aboutsummaryrefslogtreecommitdiff
path: root/src/socket.h
diff options
context:
space:
mode:
authorOskari Timperi <oskari.timperi@iki.fi>2017-03-18 09:17:16 +0200
committerOskari Timperi <oskari.timperi@iki.fi>2017-03-18 09:17:16 +0200
commit03f7cae60919a04ff0ebc87baf3b51b9bbb1776f (patch)
tree3d0306c4b5f5ddef77e9bcd0ec8cadf3013ba13d /src/socket.h
parentd97c786dbd30b4349d22b41c657f69a335f3d77a (diff)
downloadmqtt-03f7cae60919a04ff0ebc87baf3b51b9bbb1776f.tar.gz
mqtt-03f7cae60919a04ff0ebc87baf3b51b9bbb1776f.zip
Modify the code to use nonblocking sockets
Diffstat (limited to 'src/socket.h')
-rw-r--r--src/socket.h26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/socket.h b/src/socket.h
index e7b1a80..abc67af 100644
--- a/src/socket.h
+++ b/src/socket.h
@@ -6,7 +6,25 @@
#include <stdlib.h>
#include <stdint.h>
-int SocketConnect(const char *host, short port);
+#if defined(_WIN32)
+#include "win32.h"
+#define SocketErrno (WSAGetLastError())
+#define SOCKET_EINPROGRESS (WSAEWOULDBLOCK)
+#else
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/select.h>
+#include <netdb.h>
+#include <unistd.h>
+#include <arpa/inet.h>
+#include <fcntl.h>
+#include <errno.h>
+#define SocketErrno (errno)
+#define SOCKET_EINPROGRESS (EINPROGRESS)
+#endif
+
+int SocketConnect(const char *host, short port, int nonblocking);
int SocketDisconnect(int sock);
@@ -24,4 +42,10 @@ int64_t SocketRecv(int sock, void *buf, size_t len, int flags);
int64_t SocketSend(int sock, const void *buf, size_t len, int flags);
+void SocketSetNonblocking(int sock, int nb);
+
+int SocketGetError(int sock, int *error);
+
+int SocketWouldBlock(int error);
+
#endif