From 03f7cae60919a04ff0ebc87baf3b51b9bbb1776f Mon Sep 17 00:00:00 2001 From: Oskari Timperi Date: Sat, 18 Mar 2017 09:17:16 +0200 Subject: Modify the code to use nonblocking sockets --- src/socket.h | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/socket.h') 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 #include -int SocketConnect(const char *host, short port); +#if defined(_WIN32) +#include "win32.h" +#define SocketErrno (WSAGetLastError()) +#define SOCKET_EINPROGRESS (WSAEWOULDBLOCK) +#else +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 -- cgit v1.2.3