diff options
author | Angelo Mantellini <manangel@cisco.com> | 2019-01-31 18:20:48 +0100 |
---|---|---|
committer | Angelo Mantellini <manangel@cisco.com> | 2019-02-01 15:23:03 +0100 |
commit | f5a0b8a5e24cede05e15ab696f0e15257a503525 (patch) | |
tree | 8cab87196baf7ea5468cebc4002da45175d91ae8 /hicn-light/src/core/dispatcher.c | |
parent | bf29f9a52ffa3a1f32f700e4fd36ea53885d83aa (diff) |
[HICN24] Windows compatibility for hicn-light
Change-Id: I8e19e52c9b4ec0fcbd7344c28765f5da1937569c
Signed-off-by: Angelo Mantellini <manangel@cisco.com>
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; } |