From 106283c9f4efdfe3e61eb0352c642596a9b262d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=A0=91=E6=96=B0?= Date: Sun, 23 Oct 2022 18:08:20 +0800 Subject: [PATCH] build ok for windows --- lib_fiber/c/src/event.h | 7 ++++++- lib_fiber/c/src/event/event_iocp.c | 2 +- lib_fiber/c/src/file_event.c | 14 +++++++------- lib_fiber/c/src/hook/poll.c | 8 ++++---- lib_fiber/samples/client2/client2_vc2019.vcxproj | 9 +++++---- lib_fiber/samples/client2/main.c | 5 +++++ lib_fiber/samples/patch.c | 2 +- lib_fiber/samples/patch.h | 2 +- lib_fiber/samples/server2/server2_vc2019.vcxproj | 8 ++++---- 9 files changed, 34 insertions(+), 23 deletions(-) diff --git a/lib_fiber/c/src/event.h b/lib_fiber/c/src/event.h index 1764a2034..a44191d4f 100644 --- a/lib_fiber/c/src/event.h +++ b/lib_fiber/c/src/event.h @@ -189,7 +189,12 @@ struct FILE_EVENT { IOCP_EVENT *poller_write; socket_t iocp_sock; int sock_type; - struct sockaddr_in addr; + union { + struct { + struct sockaddr_in addr; + socklen_t len; + } peer; + } var; #endif int refer; }; diff --git a/lib_fiber/c/src/event/event_iocp.c b/lib_fiber/c/src/event/event_iocp.c index 5bc472966..951a2fa24 100644 --- a/lib_fiber/c/src/event/event_iocp.c +++ b/lib_fiber/c/src/event/event_iocp.c @@ -344,7 +344,7 @@ int event_iocp_connect(EVENT *ev, FILE_EVENT *fe) memset(&event->overlapped, 0, sizeof(event->overlapped)); ret = lpfnConnectEx(fe->fd, - (const struct sockaddr *) &fe->addr, + (const struct sockaddr *) &fe->var.peer.addr, sizeof(struct sockaddr), NULL, 0, diff --git a/lib_fiber/c/src/file_event.c b/lib_fiber/c/src/file_event.c index 5f7bfa3d4..965188f05 100644 --- a/lib_fiber/c/src/file_event.c +++ b/lib_fiber/c/src/file_event.c @@ -35,17 +35,17 @@ void file_event_init(FILE_EVENT *fe, socket_t fd) #endif #ifdef HAS_IOCP - fe->buff = NULL; - fe->size = 0; - fe->len = 0; - fe->h_iocp = NULL; - fe->reader = NULL; - fe->writer = NULL; + fe->rbuf = NULL; + fe->rsize = 0; + fe->rlen = 0; + fe->h_iocp = NULL; + fe->reader = NULL; + fe->writer = NULL; fe->poller_read = NULL; fe->poller_write = NULL; fe->iocp_sock = INVALID_SOCKET; fe->sock_type = getsocktype(fd); - memset(&fe->peer_addr, 0, sizeof(fe->peer_addr)); + memset(&fe->var, 0, sizeof(fe->var)); #endif fe->refer = 1; diff --git a/lib_fiber/c/src/hook/poll.c b/lib_fiber/c/src/hook/poll.c index 91c2486d2..0a3945e5c 100644 --- a/lib_fiber/c/src/hook/poll.c +++ b/lib_fiber/c/src/hook/poll.c @@ -221,11 +221,11 @@ static POLLFD *pollfd_alloc(POLL_EVENT *pe, struct pollfd *fds, nfds_t nfds) pfds[i].fe = fiber_file_open_write(fds[i].fd); } #ifdef HAS_IOCP - pfds[i].fe->buff = NULL; - pfds[i].fe->size = 0; + pfds[i].fe->rbuf = NULL; + pfds[i].fe->rsize = 0; #endif - pfds[i].pe = pe; - pfds[i].pfd = &fds[i]; + pfds[i].pe = pe; + pfds[i].pfd = &fds[i]; pfds[i].pfd->revents = 0; SET_POLLING(pfds[i].fe); } diff --git a/lib_fiber/samples/client2/client2_vc2019.vcxproj b/lib_fiber/samples/client2/client2_vc2019.vcxproj index c98b02eaa..b12fec385 100644 --- a/lib_fiber/samples/client2/client2_vc2019.vcxproj +++ b/lib_fiber/samples/client2/client2_vc2019.vcxproj @@ -88,7 +88,7 @@ NotUsing Level3 Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) false ..\..\c\include; ..\..\..\lib_acl\include;..\ MultiThreadedDebugDLL @@ -115,7 +115,7 @@ Level3 Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;ACL_DLL;FIBER_DLL;%(PreprocessorDefinitions) + WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;ACL_DLL;FIBER_DLL;%(PreprocessorDefinitions) false ..\..\c\include; ..\..\..\lib_acl\include;..\ MultiThreadedDebugDLL @@ -141,7 +141,7 @@ copy ..\..\c\libfiber.dll .\ /Y NotUsing Level3 Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;ACL_DLL;FIBER_DLL;%(PreprocessorDefinitions) + WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;ACL_DLL;FIBER_DLL;%(PreprocessorDefinitions) false ..\..\c\include; ..\..\..\lib_acl\include;..\ MultiThreadedDLL @@ -168,7 +168,7 @@ copy ..\..\c\libfiber.dll .\ /Y MaxSpeed true true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) false ..\..\c\include; ..\..\..\lib_acl\include;..\ MultiThreadedDLL @@ -183,6 +183,7 @@ copy ..\..\c\libfiber.dll .\ /Y + diff --git a/lib_fiber/samples/client2/main.c b/lib_fiber/samples/client2/main.c index 59a86eae3..1d3c9bc95 100644 --- a/lib_fiber/samples/client2/main.c +++ b/lib_fiber/samples/client2/main.c @@ -51,7 +51,12 @@ static int check_write(SOCKET fd, int timeout) pfd.fd = fd; pfd.events = POLLOUT; +#if defined(_WIN32) || defined(_WIN64) + n = WSAPoll(&pfd, 1, timeout); +#else n = poll(&pfd, 1, timeout); +#endif + if (n < 0) { printf("poll error: %s\r\n", acl_last_serror()); return -1; diff --git a/lib_fiber/samples/patch.c b/lib_fiber/samples/patch.c index bb2bc9ab2..7541be2e0 100644 --- a/lib_fiber/samples/patch.c +++ b/lib_fiber/samples/patch.c @@ -131,7 +131,7 @@ int set_non_blocking(SOCKET fd, int on) int flags = 0; if (ioctlsocket(fd, FIONBIO, &n) < 0) { - msg_error("ioctlsocket(fd,FIONBIO) failed"); + printf("ioctlsocket(fd,FIONBIO) failed\r\n"); return -1; } return flags; diff --git a/lib_fiber/samples/patch.h b/lib_fiber/samples/patch.h index 470309055..4912bf2ba 100644 --- a/lib_fiber/samples/patch.h +++ b/lib_fiber/samples/patch.h @@ -11,7 +11,7 @@ extern "C" { # define snprintf _snprintf extern int optind; extern char *optarg; -int getopt(int argc, char * const argv[], char *opts); +int getopt(int argc, char *argv[], const char *opts); #else # define SOCKET int # define INVALID_SOCKET -1 diff --git a/lib_fiber/samples/server2/server2_vc2019.vcxproj b/lib_fiber/samples/server2/server2_vc2019.vcxproj index 075dc391c..a1d02548c 100644 --- a/lib_fiber/samples/server2/server2_vc2019.vcxproj +++ b/lib_fiber/samples/server2/server2_vc2019.vcxproj @@ -132,8 +132,8 @@ - copy ..\..\..\lib_acl\lib_acl_d.dll .\ /Y -copy ..\..\c\libfiber.dll .\ /Y + + @@ -158,8 +158,8 @@ copy ..\..\c\libfiber.dll .\ /Y - copy ..\..\..\lib_acl\lib_acl.dll .\ /Y -copy ..\..\c\libfiber.dll .\ /Y + +