Add read/write timeout support

Hi Pedro,

Due to our needs at $work, this pull request adds timeout support to read/write operations. However, I am not entirely comfortable with my code or the tests, so any comments/review you have would be great.

Cheers,
Ovid