aboutsummaryrefslogtreecommitdiff
path: root/src/event/SocketMonitor.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-30 10:39:17 +0100
committerMax Kellermann <max@duempel.org>2013-01-30 10:39:17 +0100
commit73f36858bb4026eff7c9e44007c87e870d324a5f (patch)
treebd42fc660f2a29e8553563dc03bccd51a7e54e5f /src/event/SocketMonitor.cxx
parentfe3f0332f71258354b70e5db685b56934f0df703 (diff)
event/SocketMonitor: add methods Read(), Write()
Diffstat (limited to 'src/event/SocketMonitor.cxx')
-rw-r--r--src/event/SocketMonitor.cxx32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/event/SocketMonitor.cxx b/src/event/SocketMonitor.cxx
index 57364c88..bf9fcdc5 100644
--- a/src/event/SocketMonitor.cxx
+++ b/src/event/SocketMonitor.cxx
@@ -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);
+}