diff options
author | Luca Muscariello <lumuscar+fdio@cisco.com> | 2019-02-01 20:00:21 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@fd.io> | 2019-02-01 20:00:21 +0000 |
commit | 79f9c336d9d8af63e322e3c52f09fec3d7cb3c2b (patch) | |
tree | 7674e218ee813ff7aec6868ab86a1dd6c40af28f /hicn-light/src/core/dispatcher.c | |
parent | e8fabe3f6313a3b9050fe16458e4714d9dce426e (diff) | |
parent | f5a0b8a5e24cede05e15ab696f0e15257a503525 (diff) |
Merge "[HICN24] Windows compatibility for hicn-light"
Diffstat (limited to 'hicn-light/src/core/dispatcher.c')
-rw-r--r-- | hicn-light/src/core/dispatcher.c | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/hicn-light/src/core/dispatcher.c b/hicn-light/src/core/dispatcher.c index 078087c59..b6ef5e21f 100644 --- a/hicn-light/src/core/dispatcher.c +++ b/hicn-light/src/core/dispatcher.c @@ -22,9 +22,13 @@ * timers, and network events. */ +#ifndef _WIN32 +#include <arpa/inet.h> +#include <sys/socket.h> +#include <unistd.h> +#endif #include <errno.h> #include <fcntl.h> -#include <pthread.h> #include <signal.h> #include <src/config.h> #include <stdarg.h> @@ -32,10 +36,6 @@ #include <stdlib.h> #include <string.h> #include <time.h> -#include <unistd.h> - -#include <arpa/inet.h> -#include <sys/socket.h> #include <parc/algol/parc_EventQueue.h> #include <parc/algol/parc_EventTimer.h> @@ -44,6 +44,8 @@ #include <src/core/dispatcher.h> +#include <pthread.h> + #ifndef INPORT_ANY #define INPORT_ANY 0 #endif @@ -298,6 +300,7 @@ static bool dispatcher_StreamBufferBindAndConnect(Dispatcher *dispatcher, // we need to bind, then connect. Special operation, so we make our // own fd then pass it off to the buffer event +#ifndef _WIN32 int fd = socket(localSock->sa_family, SOCK_STREAM, 0); if (fd < 0) { perror("socket"); @@ -333,6 +336,42 @@ static bool dispatcher_StreamBufferBindAndConnect(Dispatcher *dispatcher, close(fd); return false; } +#else + SOCKET fd = socket(localSock->sa_family, SOCK_STREAM, 0); + if (fd == INVALID_SOCKET) { + perror("socket"); + return -1; + } + + // Set non-blocking flag + u_long mode = 1; + int result = ioctlsocket(fd, FIONBIO, &mode); + if (result == NO_ERROR) { + perror("ioctlsocket error"); + closesocket(fd); + WSACleanup(); + return -1; + } + + int failure = bind(fd, localSock, (int)localSockLength); + if (failure) { + perror("bind"); + closesocket(fd); + WSACleanup(); + return false; + } + + parcEventQueue_SetFileDescriptor(buffer, (int)fd); + + failure = parcEventQueue_ConnectSocket(buffer, remoteSock, remoteSockLength); + if (failure && (errno != EINPROGRESS)) { + perror("connect"); + closesocket(fd); + WSACleanup(); + return false; + } +#endif + return true; } |