From 915210956d2448e83cd9167389b277dff28c8201 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Tue, 19 Apr 2016 18:52:44 +0900 Subject: [PATCH] fix to work 07netcat.strm on windows --- examples/07netcat.strm | 2 +- src/io.c | 3 ++- src/pollfd.c | 1 - src/socket.c | 2 ++ 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/07netcat.strm b/examples/07netcat.strm index 3e58b1e..00c65aa 100644 --- a/examples/07netcat.strm +++ b/examples/07netcat.strm @@ -1,3 +1,3 @@ s = tcp_socket("localhost", 8007) -stdin | s s | stdout +stdin | s diff --git a/src/io.c b/src/io.c index 3a70a23..3cab1a3 100644 --- a/src/io.c +++ b/src/io.c @@ -6,6 +6,7 @@ # include #else # include +# include #endif #include @@ -334,7 +335,7 @@ strm_writeio(strm_io io) #ifdef _WIN32 WSANETWORKEVENTS wev; if (WSAEnumNetworkEvents((SOCKET) io->fd, NULL, &wev) == 0) { - d->f = fdopen(_open_osfhandle(io->fd, 0), "w"); + d->f = fdopen(_open_osfhandle(io->fd, _O_RDONLY), "w"); } else d->f = fdopen(io->fd, "w"); #else diff --git a/src/pollfd.c b/src/pollfd.c index 03582b3..abfd4cb 100644 --- a/src/pollfd.c +++ b/src/pollfd.c @@ -186,7 +186,6 @@ epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout) } else { HANDLE h = (HANDLE) _get_osfhandle(ee->fds[i]); if (h != INVALID_HANDLE_VALUE && WaitForSingleObject(h, 0) == WAIT_OBJECT_0) { - memcpy(&events[e++], ee, sizeof(struct epoll_event)); events[e++] = *ee; if (ee->events & EPOLLONESHOT) ee->fds[i] = -1; diff --git a/src/socket.c b/src/socket.c index e8e6e85..ecb05c5 100644 --- a/src/socket.c +++ b/src/socket.c @@ -149,8 +149,10 @@ tcp_socket(strm_stream* task, int argc, strm_value* args, strm_value* ret) strm_string host; #ifdef _WIN32 + int sockopt = SO_SYNCHRONOUS_NONALERT; WSADATA wsa; WSAStartup(MAKEWORD(2, 0), &wsa); + setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *)&sockopt, sizeof(sockopt)); #endif if (argc != 2) {