event/SocketMonitor: add methods Read(), Write()

This commit is contained in:
Max Kellermann
2013-01-30 10:39:17 +01:00
parent fe3f0332f7
commit 73f36858bb
4 changed files with 43 additions and 27 deletions

View File

@@ -25,6 +25,13 @@
#include <assert.h>
#ifdef WIN32
#include <winsock2.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
#endif
/*
* GSource methods
*
@@ -127,3 +134,28 @@ SocketMonitor::Close()
{
close_socket(Steal());
}
SocketMonitor::ssize_t
SocketMonitor::Read(void *data, size_t length)
{
int flags = 0;
#ifdef MSG_DONTWAIT
flags |= MSG_DONTWAIT;
#endif
return recv(Get(), (char *)data, length, flags);
}
SocketMonitor::ssize_t
SocketMonitor::Write(const void *data, size_t length)
{
int flags = 0;
#ifdef MSG_NOSIGNAL
flags |= MSG_NOSIGNAL;
#endif
#ifdef MSG_DONTWAIT
flags |= MSG_DONTWAIT;
#endif
return send(Get(), (const char *)data, length, flags);
}