SimpleSocket
0.1
Some wrappers that make using sockets easier in C++
|
#include <sclasses.hh>
Public Member Functions | |
ReadBuffer (int fd, int bufsize=2048) | |
Instantiate on a non-blocking filedescriptor, with a given buffer size in bytes. | |
void | setTimeout (double timeout) |
Set timeout in seconds. | |
bool | getChar (char *c) |
Gets you a character in c, or false in case of EOF. | |
Simple buffered reader for use on a non-blocking socket. Has only one method to access data, getChar() which either gets you a character or it doesn't. If the internal buffer is empty, SimpleBuffer will attempt to get up to bufsize bytes more in one go. Optionally, with setTimeout(seconds) a timeout can be set.
WARNING: Only use ReadBuffer on a non-blocking socket! Otherwise it will block indefinitely to read 'bufsize' bytes, even if you only wanted one!