diff --git a/lib_acl/include/stdlib/acl_define_win32.h b/lib_acl/include/stdlib/acl_define_win32.h
index 9e39c7edc..d952c5cf6 100644
--- a/lib_acl/include/stdlib/acl_define_win32.h
+++ b/lib_acl/include/stdlib/acl_define_win32.h
@@ -12,6 +12,7 @@
* vc++11.0 VS 2012 1700
* vc++14.0 VS 2015 1900
* vc++15.0 VS 2017 1911
+ * vc++16.0 VS 2019 1929
*/
#if defined (_WIN32) || defined(_WIN64)
diff --git a/lib_fiber/c/libfiber_vc2012.vcxproj b/lib_fiber/c/libfiber_vc2012.vcxproj
index ffc992c3d..59665db80 100644
--- a/lib_fiber/c/libfiber_vc2012.vcxproj
+++ b/lib_fiber/c/libfiber_vc2012.vcxproj
@@ -410,6 +410,7 @@
+
@@ -428,4 +429,4 @@
-
+
\ No newline at end of file
diff --git a/lib_fiber/c/libfiber_vc2012.vcxproj.filters b/lib_fiber/c/libfiber_vc2012.vcxproj.filters
index 9e1a9cabe..d096e7c79 100644
--- a/lib_fiber/c/libfiber_vc2012.vcxproj.filters
+++ b/lib_fiber/c/libfiber_vc2012.vcxproj.filters
@@ -189,6 +189,9 @@
源文件\event
+
+ 源文件\hook
+
@@ -312,4 +315,4 @@
源文件\event
-
+
\ No newline at end of file
diff --git a/lib_fiber/c/libfiber_vc2019.vcxproj b/lib_fiber/c/libfiber_vc2019.vcxproj
index a578e2dbb..e640a14a5 100644
--- a/lib_fiber/c/libfiber_vc2019.vcxproj
+++ b/lib_fiber/c/libfiber_vc2019.vcxproj
@@ -292,6 +292,7 @@
+
diff --git a/lib_fiber/c/libfiber_vc2019.vcxproj.filters b/lib_fiber/c/libfiber_vc2019.vcxproj.filters
index 9cd54c05e..95736eff5 100644
--- a/lib_fiber/c/libfiber_vc2019.vcxproj.filters
+++ b/lib_fiber/c/libfiber_vc2019.vcxproj.filters
@@ -156,6 +156,9 @@
源文件\event
+
+ 头文件
+
diff --git a/lib_fiber/c/src/hook/epoll.c b/lib_fiber/c/src/hook/epoll.c
index fa9d46775..1016a091c 100644
--- a/lib_fiber/c/src/hook/epoll.c
+++ b/lib_fiber/c/src/hook/epoll.c
@@ -55,7 +55,7 @@ static void thread_free(void *ctx fiber_unused)
}
}
- if (ee->epfd >= 0 && __sys_close(ee->epfd) < 0) {
+ if (ee->epfd >= 0 && (*sys_close)(ee->epfd) < 0) {
fiber_save_errno(acl_fiber_last_error());
}
@@ -175,7 +175,7 @@ int epoll_event_close(int epfd)
mem_free(ee);
array_delete(__epfds, pos, NULL);
- return __sys_close(epfd);
+ return (*sys_close)(epfd);
}
/****************************************************************************/
@@ -186,12 +186,12 @@ int epoll_create(int size fiber_unused)
EVENT *ev;
int epfd;
- if (__sys_epoll_create == NULL) {
+ if (sys_epoll_create == NULL) {
hook_once();
}
if (!var_hook_sys_api) {
- return __sys_epoll_create ? __sys_epoll_create(size) : -1;
+ return sys_epoll_create ? (*sys_epoll_create)(size) : -1;
}
ev = fiber_io_event();
@@ -318,13 +318,12 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)
EPOLL_EVENT *ee;
EVENT *ev;
- if (__sys_epoll_ctl == NULL) {
+ if (sys_epoll_ctl == NULL) {
hook_once();
}
if (!var_hook_sys_api) {
- return __sys_epoll_ctl ?
- __sys_epoll_ctl(epfd, op, fd, event) : -1;
+ return sys_epoll_ctl ? (*sys_epoll_ctl)(epfd, op, fd, event) : -1;
}
ee = epoll_event_find(epfd);
@@ -379,13 +378,12 @@ int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout)
long long begin, now;
int old_timeout;
- if (__sys_epoll_wait == NULL) {
+ if (sys_epoll_wait == NULL) {
hook_once();
}
if (!var_hook_sys_api) {
- return __sys_epoll_wait ?
- __sys_epoll_wait(epfd, events, maxevents, timeout) : -1;
+ return sys_epoll_wait ? (*sys_epoll_wait)(epfd, events, maxevents, timeout) : -1;
}
ev = fiber_io_event();
diff --git a/lib_fiber/c/src/hook/getaddrinfo.c b/lib_fiber/c/src/hook/getaddrinfo.c
index 3d40aeee2..c5b3d2fb1 100644
--- a/lib_fiber/c/src/hook/getaddrinfo.c
+++ b/lib_fiber/c/src/hook/getaddrinfo.c
@@ -114,7 +114,7 @@ int acl_fiber_getaddrinfo(const char *node, const char *service,
{
struct addrinfo hints_tmp;
- if (__sys_getaddrinfo == NULL) {
+ if (sys_getaddrinfo == NULL) {
hook_once();
}
@@ -126,7 +126,7 @@ int acl_fiber_getaddrinfo(const char *node, const char *service,
# endif
#endif
if (!var_hook_sys_api) {
- return __sys_getaddrinfo ? __sys_getaddrinfo
+ return sys_getaddrinfo ? (*sys_getaddrinfo)
(node, service, hints, res) : EAI_NODATA;
}
@@ -166,13 +166,13 @@ int acl_fiber_getaddrinfo(const char *node, const char *service,
void acl_fiber_freeaddrinfo(struct addrinfo *res)
{
- if (__sys_freeaddrinfo == NULL) {
+ if (sys_freeaddrinfo == NULL) {
hook_once();
}
if (!var_hook_sys_api) {
- if (__sys_freeaddrinfo) {
- __sys_freeaddrinfo(res);
+ if (sys_freeaddrinfo) {
+ (*sys_freeaddrinfo)(res);
}
return;
}
diff --git a/lib_fiber/c/src/hook/gethostbyname.c b/lib_fiber/c/src/hook/gethostbyname.c
index 45d70bebd..4a4c5dd6a 100644
--- a/lib_fiber/c/src/hook/gethostbyname.c
+++ b/lib_fiber/c/src/hook/gethostbyname.c
@@ -130,16 +130,16 @@ int acl_fiber_gethostbyname_r(const char *name, struct hostent *ent,
struct addrinfo *res;
#ifdef __APPLE__
- if (__sys_gethostbyname == NULL) {
+ if (sys_gethostbyname == NULL) {
#else
- if (__sys_gethostbyname_r == NULL) {
+ if (sys_gethostbyname_r == NULL) {
#endif
hook_once();
}
if (!var_hook_sys_api) {
#ifdef __APPLE__
- *result = __sys_gethostbyname(name);
+ *result = (*sys_gethostbyname)(name);
if (result == NULL) {
if (h_errnop) {
*h_errnop = h_errno;
@@ -148,7 +148,7 @@ int acl_fiber_gethostbyname_r(const char *name, struct hostent *ent,
}
return 0;
#else
- return __sys_gethostbyname_r ? __sys_gethostbyname_r
+ return sys_gethostbyname_r ? (*sys_gethostbyname_r)
(name, ent, buf, buflen, result, h_errnop) : -1;
#endif
}
diff --git a/lib_fiber/c/src/hook/hook.c b/lib_fiber/c/src/hook/hook.c
index 0113b8510..de21c1345 100644
--- a/lib_fiber/c/src/hook/hook.c
+++ b/lib_fiber/c/src/hook/hook.c
@@ -3,153 +3,233 @@
#include "hook.h"
socket_fn __sys_socket = NULL;
-listen_fn __sys_listen = NULL;
-accept_fn __sys_accept = NULL;
-connect_fn __sys_connect = NULL;
+socket_fn *sys_socket = NULL;
+
close_fn __sys_close = NULL;
+close_fn *sys_close = NULL;
+
+listen_fn __sys_listen = NULL;
+listen_fn *sys_listen = NULL;
+
+accept_fn __sys_accept = NULL;
+accept_fn *sys_accept = NULL;
+
+connect_fn __sys_connect = NULL;
+connect_fn *sys_connect = NULL;
recv_fn __sys_recv = NULL;
+recv_fn *sys_recv = NULL;
+
recvfrom_fn __sys_recvfrom = NULL;
+recvfrom_fn *sys_recvfrom = NULL;
send_fn __sys_send = NULL;
+send_fn *sys_send = NULL;
+
sendto_fn __sys_sendto = NULL;
+sendto_fn *sys_sendto = NULL;
+
poll_fn __sys_poll = NULL;
+poll_fn *sys_poll = NULL;
+
select_fn __sys_select = NULL;
+select_fn *sys_select = NULL;
#ifdef SYS_UNIX
sleep_fn __sys_sleep = NULL;
+sleep_fn *sys_sleep = NULL;
+
setsockopt_fn __sys_setsockopt = NULL;
+setsockopt_fn *sys_setsockopt = NULL;
read_fn __sys_read = NULL;
+read_fn *sys_read = NULL;
+
readv_fn __sys_readv = NULL;
+readv_fn *sys_readv = NULL;
+
recvmsg_fn __sys_recvmsg = NULL;
+recvmsg_fn *sys_recvmsg = NULL;
write_fn __sys_write = NULL;
+write_fn *sys_write = NULL;
+
writev_fn __sys_writev = NULL;
+writev_fn *sys_writev = NULL;
+
sendmsg_fn __sys_sendmsg = NULL;
+sendmsg_fn *sys_sendmsg = NULL;
# ifdef __USE_LARGEFILE64
sendfile64_fn __sys_sendfile64 = NULL;
+sendfile64_fn *sys_sendfile64 = NULL;
# endif
# ifdef HAS_EPOLL
epoll_create_fn __sys_epoll_create = NULL;
+epoll_create_fn *sys_epoll_create = NULL;
+
epoll_wait_fn __sys_epoll_wait = NULL;
+epoll_wait_fn *sys_epoll_wait = NULL;
+
epoll_ctl_fn __sys_epoll_ctl = NULL;
+epoll_ctl_fn *sys_epoll_ctl = NULL;
# endif
getaddrinfo_fn __sys_getaddrinfo = NULL;
+getaddrinfo_fn *sys_getaddrinfo = NULL;
+
freeaddrinfo_fn __sys_freeaddrinfo = NULL;
+freeaddrinfo_fn *sys_freeaddrinfo = NULL;
+
gethostbyname_fn __sys_gethostbyname = NULL;
+gethostbyname_fn *sys_gethostbyname = NULL;
# ifndef __APPLE__
gethostbyname_r_fn __sys_gethostbyname_r = NULL;
+gethostbyname_r_fn *sys_gethostbyname_r = NULL;
# endif
#endif // SYS_UNIX
+void WINAPI set_socket_fn(socket_fn *fn)
+{
+ sys_socket = fn;
+}
+
+void WINAPI set_close_fn(close_fn *fn)
+{
+ sys_close = fn;
+}
+
+void WINAPI set_listen_fn(listen_fn *fn)
+{
+ sys_listen = fn;
+}
+
+void WINAPI set_accept_fn(accept_fn *fn)
+{
+ sys_accept = fn;
+}
+
+void WINAPI set_connect_fn(connect_fn *fn)
+{
+ sys_connect = fn;
+}
+
+void WINAPI set_recv_fn(recv_fn *fn)
+{
+ sys_recv = fn;
+}
+
+void WINAPI set_recvfrom_fn(recvfrom_fn *fn)
+{
+ sys_recvfrom = fn;
+}
+
+void WINAPI set_send_fn(send_fn *fn)
+{
+ sys_send = fn;
+}
+
+void WINAPI set_sendto_fn(sendto_fn *fn)
+{
+ sys_sendto = fn;
+}
+
+void WINAPI set_poll_fn(poll_fn *fn)
+{
+ sys_poll = fn;
+}
+
+void WINAPI set_select_fn(select_fn *fn)
+{
+ sys_select = fn;
+}
+
static void hook_api(void)
{
#ifdef SYS_UNIX
- __sys_socket = (socket_fn) dlsym(RTLD_NEXT, "socket");
- assert(__sys_socket);
- __sys_close = (close_fn) dlsym(RTLD_NEXT, "close");
- assert(__sys_close);
+#define LOAD_FN(name, type, fn, fp) do { \
+ (fn) = (type) dlsym(RTLD_NEXT, name); \
+ assert((fn)); \
+ (fp) = &(fn); \
+} while (0)
- __sys_listen = (listen_fn) dlsym(RTLD_NEXT, "listen");
- assert(__sys_listen);
-
- __sys_accept = (accept_fn) dlsym(RTLD_NEXT, "accept");
- assert(__sys_accept);
-
- __sys_connect = (connect_fn) dlsym(RTLD_NEXT, "connect");
- assert(__sys_connect);
-
- __sys_setsockopt = (setsockopt_fn) dlsym(RTLD_NEXT, "setsockopt");
- assert(__sys_setsockopt);
-
- __sys_sleep = (sleep_fn) dlsym(RTLD_NEXT, "sleep");
- assert(__sys_sleep);
-
- __sys_read = (read_fn) dlsym(RTLD_NEXT, "read");
- assert(__sys_read);
-
- __sys_readv = (readv_fn) dlsym(RTLD_NEXT, "readv");
- assert(__sys_readv);
-
- __sys_recv = (recv_fn) dlsym(RTLD_NEXT, "recv");
- assert(__sys_recv);
-
- __sys_recvfrom = (recvfrom_fn) dlsym(RTLD_NEXT, "recvfrom");
- assert(__sys_recvfrom);
-
- __sys_recvmsg = (recvmsg_fn) dlsym(RTLD_NEXT, "recvmsg");
- assert(__sys_recvmsg);
-
- __sys_write = (write_fn) dlsym(RTLD_NEXT, "write");
- assert(__sys_write);
-
- __sys_writev = (writev_fn) dlsym(RTLD_NEXT, "writev");
- assert(__sys_writev);
-
- __sys_send = (send_fn) dlsym(RTLD_NEXT, "send");
- assert(__sys_send);
-
- __sys_sendto = (sendto_fn) dlsym(RTLD_NEXT, "sendto");
- assert(__sys_sendto);
-
- __sys_sendmsg = (sendmsg_fn) dlsym(RTLD_NEXT, "sendmsg");
- assert(__sys_sendmsg);
+ LOAD_FN("socket", socket_fn, __sys_socket, sys_socket);
+ LOAD_FN("close", close_fn, __sys_close, sys_close);
+ LOAD_FN("listen", listen_fn, __sys_listen, sys_listen);
+ LOAD_FN("accept", accept_fn, __sys_accept, sys_accept);
+ LOAD_FN("connect", connect_fn, __sys_connect, sys_connect);
+ LOAD_FN("setsockopt", setsockopt_fn, __sys_setsockopt, sys_setsockopt);
+ LOAD_FN("sleep", sleep_fn, __sys_sleep, sys_sleep);
+ LOAD_FN("read", read_fn, __sys_read, sys_read);
+ LOAD_FN("readv", readv_fn, __sys_readv, sys_readv);
+ LOAD_FN("recv", recv_fn, __sys_recv, sys_recv);
+ LOAD_FN("recvfrom", recvfrom_fn, __sys_recvfrom, sys_recvfrom);
+ LOAD_FN("recvmsg", recvmsg_fn, __sys_recvmsg, sys_recvmsg);
+ LOAD_FN("write", write_fn, __sys_write, sys_write);
+ LOAD_FN("writev", writev_fn, __sys_writev, sys_writev);
+ LOAD_FN("send" send_fn __sys_send, sys_send);
+ LOAD_FN("sendto", sendto_fn, __sys_sendto, sys_sendto);
+ LOAD_FN("sendmsg", sendmsg_fn, __sys_sendmsg, sys_sendmsg);
# ifdef __USE_LARGEFILE64
- __sys_sendfile64 = (sendfile64_fn) dlsym(RTLD_NEXT, "sendfile64");
- assert(__sys_sendfile64);
+ LOAD_FN("sendfile64", sendfile64_fn, __sys_sendfile64, sys_sendfile64);
# endif
- __sys_poll = (poll_fn) dlsym(RTLD_NEXT, "poll");
- assert(__sys_poll);
- __sys_select = (select_fn) dlsym(RTLD_NEXT, "select");
- assert(__sys_select);
+ LOAD_FN("poll", poll_fn, __sys_poll, sys_poll);
+ LOAD_FN("select", select_fn, __sys_select, sys_select);
# ifdef HAS_EPOLL
- __sys_epoll_create = (epoll_create_fn) dlsym(RTLD_NEXT, "epoll_create");
- assert(__sys_epoll_create);
+ LOAD_FN("epoll_create", epoll_create_fn, __sys_epoll_create, sys_epoll_create);
- __sys_epoll_wait = (epoll_wait_fn) dlsym(RTLD_NEXT, "epoll_wait");
- assert(__sys_epoll_wait);
+ LOAD_FN("epoll_wait", epoll_wait_fn, __sys_epoll_wait, sys_epoll_wait);
- __sys_epoll_ctl = (epoll_ctl_fn) dlsym(RTLD_NEXT, "epoll_ctl");
- assert(__sys_epoll_ctl);
+ LOAD_FN("epoll_ctl", epoll_ctl_fn, __sys_epoll_ctl, sys_epoll_ctl);
# endif // HAS_EPOLL
- __sys_getaddrinfo = (getaddrinfo_fn) dlsym(RTLD_NEXT, "getaddrinfo");
- assert(__sys_getaddrinfo);
-
- __sys_freeaddrinfo = (freeaddrinfo_fn) dlsym(RTLD_NEXT, "freeaddrinfo");
- assert(__sys_freeaddrinfo);
-
- __sys_gethostbyname = (gethostbyname_fn) dlsym(RTLD_NEXT,
- "gethostbyname");
- assert(__sys_gethostbyname);
+ LOAD_FN("getaddrinfo", getaddrinfo_fn, __sys_getaddrinfo, sys_getaddrinfo);
+ LOAD_FN("freeaddrinfo", freeaddrinfo_fn, __sys_freeaddrinfo, sys_freeaddrinfo);
+ LOAD_FN("gethostbyname", gethostbyname_fn, __sys_gethostbyname, sys_gethostbyname);
# ifndef __APPLE__
- __sys_gethostbyname_r = (gethostbyname_r_fn) dlsym(RTLD_NEXT,
- "gethostbyname_r");
- assert(__sys_gethostbyname_r);
+ LOAD_FN("gethostbname_r", gethostbyname_r_fn, __sys_gethostbyname_r, sys_gethostbyname_r);
# endif
#elif defined(SYS_WIN)
__sys_socket = socket;
+ sys_socket = &__sys_socket;
+
__sys_listen = listen;
+ sys_listen = &__sys_listen;
+
__sys_accept = accept;
+ sys_accept = &__sys_accept;
+
__sys_connect = connect;
+ sys_connect = &__sys_connect;
+
__sys_close = closesocket;
+ sys_close = &__sys_close;
+
__sys_recv = (recv_fn) recv;
+ sys_recv = &__sys_recv;
+
__sys_recvfrom = (recvfrom_fn) recvfrom;
+ sys_recvfrom = &__sys_recvfrom;
+
__sys_send = (send_fn) send;
+ sys_send = &__sys_send;
+
__sys_sendto = (sendto_fn) sendto;
+ sys_sendto = &__sys_sendto;
+
__sys_poll = WSAPoll;
+ sys_poll = &__sys_poll;
+
__sys_select = select;
+ sys_select = &__sys_select;
#endif
}
@@ -161,4 +241,3 @@ void hook_once(void)
abort();
}
}
-
diff --git a/lib_fiber/c/src/hook/hook.h b/lib_fiber/c/src/hook/hook.h
index 606f19396..07c556a99 100644
--- a/lib_fiber/c/src/hook/hook.h
+++ b/lib_fiber/c/src/hook/hook.h
@@ -3,6 +3,10 @@
#include "fiber/fiber_define.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
//extern struct dns_resolv_conf *var_dns_conf;
//extern struct dns_hosts *var_dns_hosts;
//extern struct dns_hints *var_dns_hints;
@@ -16,7 +20,7 @@ typedef int (WINAPI *listen_fn)(socket_t, int);
typedef socket_t (WINAPI *accept_fn)(socket_t, struct sockaddr *, socklen_t *);
typedef int (WINAPI *connect_fn)(socket_t, const struct sockaddr *, socklen_t);
-#if defined(SYS_WIN)
+#if defined(_WIN32) || defined(_WIN64)
typedef int (WINAPI *recv_fn)(socket_t, char *, int, int);
typedef int (WINAPI *recvfrom_fn)(socket_t, char *, int, int,
@@ -28,7 +32,7 @@ typedef int (WINAPI *poll_fn)(struct pollfd *, nfds_t, int);
typedef int (WINAPI *select_fn)(int, fd_set *, fd_set *,
fd_set *, const struct timeval *);
-#elif defined(SYS_UNIX)
+#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
typedef int (*setsockopt_fn)(socket_t, int, int, const void *, socklen_t);
typedef unsigned (*sleep_fn)(unsigned int seconds);
typedef ssize_t (*read_fn)(socket_t, void *, size_t);
@@ -69,54 +73,71 @@ typedef int (*gethostbyname_r_fn)(const char *, struct hostent *, char *,
#endif
-extern socket_fn __sys_socket;
-extern close_fn __sys_close;
-extern listen_fn __sys_listen;
-extern accept_fn __sys_accept;
-extern connect_fn __sys_connect;
+void WINAPI set_socket_fn(socket_fn *fn);
+void WINAPI set_close_fn(close_fn *fn);
+void WINAPI set_listen_fn(listen_fn *fn);
+void WINAPI set_accept_fn(accept_fn *fn);
+void WINAPI set_connect_fn(connect_fn *fn);
+void WINAPI set_recv_fn(recv_fn *fn);
+void WINAPI set_recvfrom_fn(recvfrom_fn *fn);
+void WINAPI set_send_fn(send_fn *fn);
+void WINAPI set_sendto_fn(sendto_fn *fn);
+void WINAPI set_poll_fn(poll_fn *fn);
+void WINAPI set_select_fn(select_fn *fn);
-extern recv_fn __sys_recv;
+extern socket_fn *sys_socket;
+extern close_fn *sys_close;
+extern listen_fn *sys_listen;
+extern accept_fn *sys_accept;
+extern connect_fn *sys_connect;
-extern recvfrom_fn __sys_recvfrom;
+extern recv_fn *sys_recv;
-extern send_fn __sys_send;
-extern sendto_fn __sys_sendto;
-extern poll_fn __sys_poll;
-extern select_fn __sys_select;
+extern recvfrom_fn *sys_recvfrom;
-#if defined(SYS_UNIX)
+extern send_fn *sys_send;
+extern sendto_fn *sys_sendto;
+extern poll_fn *sys_poll;
+extern select_fn *sys_select;
-extern sleep_fn __sys_sleep;
-extern setsockopt_fn __sys_setsockopt;
+#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) // SYS_UNIX
-extern read_fn __sys_read;
-extern readv_fn __sys_readv;
-extern recvmsg_fn __sys_recvmsg;
+extern sleep_fn *sys_sleep;
+extern setsockopt_fn *sys_setsockopt;
-extern write_fn __sys_write;
-extern writev_fn __sys_writev;
-extern sendmsg_fn __sys_sendmsg;
+extern read_fn *sys_read;
+extern readv_fn *sys_readv;
+extern recvmsg_fn *sys_recvmsg;
+
+extern write_fn *sys_write;
+extern writev_fn *sys_writev;
+extern sendmsg_fn *sys_sendmsg;
# ifdef __USE_LARGEFILE64
-extern sendfile64_fn __sys_sendfile64;
+extern sendfile64_fn *sys_sendfile64;
# endif
# ifdef HAS_EPOLL
-extern epoll_create_fn __sys_epoll_create;
-extern epoll_wait_fn __sys_epoll_wait;
-extern epoll_ctl_fn __sys_epoll_ctl;
+extern epoll_create_fn *sys_epoll_create;
+extern epoll_wait_fn *sys_epoll_wait;
+extern epoll_ctl_fn *sys_epoll_ctl;
# endif
-extern getaddrinfo_fn __sys_getaddrinfo;
-extern freeaddrinfo_fn __sys_freeaddrinfo;
-extern gethostbyname_fn __sys_gethostbyname;
+extern getaddrinfo_fn *sys_getaddrinfo;
+extern freeaddrinfo_fn *sys_freeaddrinfo;
+extern gethostbyname_fn *sys_gethostbyname;
# ifndef __APPLE__
-extern gethostbyname_r_fn __sys_gethostbyname_r;
+extern gethostbyname_r_fn *sys_gethostbyname_r;
# endif
#endif // SYS_UNIX
void hook_once(void);
+#ifdef __cplusplus
+}
#endif
+
+#endif
+
diff --git a/lib_fiber/c/src/hook/io.c b/lib_fiber/c/src/hook/io.c
index 5cfa978b0..bd3685dc6 100644
--- a/lib_fiber/c/src/hook/io.c
+++ b/lib_fiber/c/src/hook/io.c
@@ -9,13 +9,13 @@ unsigned int sleep(unsigned int seconds)
{
if (!var_hook_sys_api) {
#ifndef USE_SYSCALL
- if (__sys_sleep == NULL) {
+ if (sys_sleep == NULL) {
hook_once();
}
#endif
//printf("use system gettimeofday\r\n");
- return __sys_sleep(seconds);
+ return (*sys_sleep)(seconds);
}
return acl_fiber_sleep(seconds);
@@ -39,12 +39,12 @@ int acl_fiber_close(socket_t fd)
return -1;
}
- if (__sys_close == NULL) {
+ if (sys_close == NULL) {
hook_once();
}
if (!var_hook_sys_api) {
- return __sys_close(fd);
+ return (*sys_close)(fd);
}
#ifdef HAS_EPOLL
@@ -63,7 +63,7 @@ int acl_fiber_close(socket_t fd)
return 0;
}
- ret = __sys_close(fd);
+ ret = (*sys_close)(fd);
if (ret == 0) {
return ret;
}
@@ -89,13 +89,13 @@ ssize_t acl_fiber_read(socket_t fd, void *buf, size_t count)
}
#ifndef USE_SYSCALL
- if (__sys_read == NULL) {
+ if (sys_read == NULL) {
hook_once();
}
#endif
if (!var_hook_sys_api) {
- return __sys_read(fd, buf, count);
+ return (*sys_read)(fd, buf, count);
}
fe = fiber_file_open(fd);
@@ -109,7 +109,7 @@ ssize_t acl_fiber_read(socket_t fd, void *buf, size_t count)
return -1;
}
- n = __sys_read(fd, buf, count);
+ n = (*sys_read)(fd, buf, count);
if (n >= 0) {
return n;
}
@@ -135,13 +135,13 @@ ssize_t acl_fiber_read(socket_t fd, void *buf, size_t count)
}
#ifndef USE_SYSCALL
- if (__sys_read == NULL) {
+ if (sys_read == NULL) {
hook_once();
}
#endif
if (!var_hook_sys_api) {
- return __sys_read(fd, buf, count);
+ return (*sys_read)(fd, buf, count);
}
fe = fiber_file_open(fd);
@@ -161,7 +161,7 @@ ssize_t acl_fiber_read(socket_t fd, void *buf, size_t count)
return -1;
}
- ret = __sys_read(fd, buf, count);
+ ret = (*sys_read)(fd, buf, count);
if (ret >= 0) {
return ret;
}
@@ -186,13 +186,13 @@ ssize_t acl_fiber_readv(socket_t fd, const struct iovec *iov, int iovcnt)
}
#ifndef USE_SYSCALL
- if (__sys_readv == NULL) {
+ if (sys_readv == NULL) {
hook_once();
}
#endif
if (!var_hook_sys_api) {
- return __sys_readv(fd, iov, iovcnt);
+ return (*sys_readv)(fd, iov, iovcnt);
}
fe = fiber_file_open(fd);
@@ -211,7 +211,7 @@ ssize_t acl_fiber_readv(socket_t fd, const struct iovec *iov, int iovcnt)
return -1;
}
- ret = __sys_readv(fd, iov, iovcnt);
+ ret = (*sys_readv)(fd, iov, iovcnt);
if (ret >= 0) {
return ret;
}
@@ -266,13 +266,13 @@ ssize_t acl_fiber_recv(socket_t sockfd, void *buf, size_t len, int flags)
}
#ifndef USE_SYSCALL
- if (__sys_recv == NULL) {
+ if (sys_recv == NULL) {
hook_once();
}
#endif
if (!var_hook_sys_api) {
- return __sys_recv(sockfd, buf, len, flags);
+ return (*sys_recv)(sockfd, buf, len, flags);
}
fe = fiber_file_open(sockfd);
@@ -296,7 +296,7 @@ ssize_t acl_fiber_recv(socket_t sockfd, void *buf, size_t len, int flags)
return -1;
}
- ret = (int) __sys_recv(sockfd, buf, len, flags);
+ ret = (int) (*sys_recv)(sockfd, buf, len, flags);
if (ret >= 0) {
return ret;
}
@@ -326,13 +326,13 @@ ssize_t acl_fiber_recvfrom(socket_t sockfd, void *buf, size_t len,
}
#ifndef USE_SYSCALL
- if (__sys_recvfrom == NULL) {
+ if (sys_recvfrom == NULL) {
hook_once();
}
#endif
if (!var_hook_sys_api) {
- return __sys_recvfrom(sockfd, buf, len, flags,
+ return (*sys_recvfrom)(sockfd, buf, len, flags,
src_addr, addrlen);
}
@@ -357,8 +357,7 @@ ssize_t acl_fiber_recvfrom(socket_t sockfd, void *buf, size_t len,
return -1;
}
- ret = __sys_recvfrom(sockfd, buf, len, flags,
- src_addr, addrlen);
+ ret = (*sys_recvfrom)(sockfd, buf, len, flags, src_addr, addrlen);
if (ret >= 0) {
return (int) ret;
}
@@ -383,13 +382,13 @@ ssize_t acl_fiber_recvmsg(socket_t sockfd, struct msghdr *msg, int flags)
}
#ifdef USE_SYSCALL
- if (__sys_recvmsg == NULL) {
+ if (sys_recvmsg == NULL) {
hook_once();
}
#endif
if (!var_hook_sys_api) {
- return __sys_recvmsg(sockfd, msg, flags);
+ return (*sys_recvmsg)(sockfd, msg, flags);
}
fe = fiber_file_open(sockfd);
@@ -409,7 +408,7 @@ ssize_t acl_fiber_recvmsg(socket_t sockfd, struct msghdr *msg, int flags)
return -1;
}
- ret = __sys_recvmsg(sockfd, msg, flags);
+ ret = (*sys_recvmsg)(sockfd, msg, flags);
if (ret >= 0) {
return ret;
}
@@ -429,12 +428,12 @@ ssize_t acl_fiber_recvmsg(socket_t sockfd, struct msghdr *msg, int flags)
#ifdef SYS_UNIX
ssize_t acl_fiber_write(socket_t fd, const void *buf, size_t count)
{
- if (__sys_write == NULL) {
+ if (sys_write == NULL) {
hook_once();
}
while (1) {
- ssize_t n = __sys_write(fd, buf, count);
+ ssize_t n = (*sys_write)(fd, buf, count);
FILE_EVENT *fe;
int err;
@@ -465,12 +464,12 @@ ssize_t acl_fiber_write(socket_t fd, const void *buf, size_t count)
ssize_t acl_fiber_writev(socket_t fd, const struct iovec *iov, int iovcnt)
{
- if (__sys_writev == NULL) {
+ if (sys_writev == NULL) {
hook_once();
}
while (1) {
- int n = (int) __sys_writev(fd, iov, iovcnt);
+ int n = (int) (*sys_writev)(fd, iov, iovcnt);
FILE_EVENT *fe;
int err;
@@ -509,13 +508,13 @@ ssize_t acl_fiber_send(socket_t sockfd, const void *buf,
#endif
{
#ifndef USE_SYSCALL
- if (__sys_send == NULL) {
+ if (sys_send == NULL) {
hook_once();
}
#endif
while (1) {
- int n = (int) __sys_send(sockfd, buf, len, flags);
+ int n = (int) (*sys_send)(sockfd, buf, len, flags);
FILE_EVENT *fe;
int err;
@@ -552,12 +551,12 @@ ssize_t acl_fiber_sendto(socket_t sockfd, const void *buf, size_t len,
int flags, const struct sockaddr *dest_addr, socklen_t addrlen)
#endif
{
- if (__sys_sendto == NULL) {
+ if (sys_sendto == NULL) {
hook_once();
}
while (1) {
- int n = (int) __sys_sendto(sockfd, buf, len, flags,
+ int n = (int) (*sys_sendto)(sockfd, buf, len, flags,
dest_addr, addrlen);
FILE_EVENT *fe;
int err;
@@ -590,12 +589,12 @@ ssize_t acl_fiber_sendto(socket_t sockfd, const void *buf, size_t len,
#ifdef SYS_UNIX
ssize_t acl_fiber_sendmsg(socket_t sockfd, const struct msghdr *msg, int flags)
{
- if (__sys_sendmsg == NULL) {
+ if (sys_sendmsg == NULL) {
hook_once();
}
while (1) {
- ssize_t n = __sys_sendmsg(sockfd, msg, flags);
+ ssize_t n = (*sys_sendmsg)(sockfd, msg, flags);
FILE_EVENT *fe;
int err;
@@ -688,12 +687,12 @@ ssize_t sendmsg(socket_t sockfd, const struct msghdr *msg, int flags)
#if defined(__USE_LARGEFILE64) && !defined(DISABLE_HOOK_IO)
ssize_t sendfile64(socket_t out_fd, int in_fd, off64_t *offset, size_t count)
{
- if (__sys_sendfile64 == NULL) {
+ if (sys_sendfile64 == NULL) {
hook_once();
}
while (1) {
- ssize_t n = __sys_sendfile64(out_fd, in_fd, offset, count);
+ ssize_t n = (*sys_sendfile64)(out_fd, in_fd, offset, count);
FILE_EVENT *fe;
int err;
diff --git a/lib_fiber/c/src/hook/poll.c b/lib_fiber/c/src/hook/poll.c
index a9abbf8e2..8be5bb5bc 100644
--- a/lib_fiber/c/src/hook/poll.c
+++ b/lib_fiber/c/src/hook/poll.c
@@ -127,12 +127,12 @@ int WINAPI acl_fiber_poll(struct pollfd *fds, nfds_t nfds, int timeout)
EVENT *ev;
int old_timeout;
- if (__sys_poll == NULL) {
+ if (sys_poll == NULL) {
hook_once();
}
if (!var_hook_sys_api) {
- return __sys_poll ? __sys_poll(fds, nfds, timeout) : -1;
+ return sys_poll ? (*sys_poll)(fds, nfds, timeout) : -1;
}
ev = fiber_io_event();
diff --git a/lib_fiber/c/src/hook/select.c b/lib_fiber/c/src/hook/select.c
index e8ceb74e6..22cf19772 100644
--- a/lib_fiber/c/src/hook/select.c
+++ b/lib_fiber/c/src/hook/select.c
@@ -125,12 +125,12 @@ int acl_fiber_select(int nfds, fd_set *readfds, fd_set *writefds,
struct pollfd *fds;
int i, timo, n, nready = 0;
- if (__sys_select == NULL) {
+ if (sys_select == NULL) {
hook_once();
}
if (!var_hook_sys_api)
- return __sys_select ? __sys_select
+ return sys_select ? (*sys_select)
(nfds, readfds, writefds, exceptfds, timeout) : -1;
fds = pfds_create(&nfds, readfds, writefds, exceptfds);
diff --git a/lib_fiber/c/src/hook/socket.c b/lib_fiber/c/src/hook/socket.c
index acf69c329..7119836f0 100644
--- a/lib_fiber/c/src/hook/socket.c
+++ b/lib_fiber/c/src/hook/socket.c
@@ -11,15 +11,15 @@ socket_t WINAPI acl_fiber_socket(int domain, int type, int protocol)
{
socket_t sockfd;
- if (__sys_socket == NULL) {
+ if (sys_socket == NULL) {
hook_once();
}
- if (__sys_socket == NULL) {
+ if (sys_socket == NULL) {
return -1;
}
- sockfd = __sys_socket(domain, type, protocol);
+ sockfd = (*sys_socket)(domain, type, protocol);
if (!var_hook_sys_api) {
return sockfd;
@@ -36,16 +36,16 @@ socket_t WINAPI acl_fiber_socket(int domain, int type, int protocol)
int WINAPI acl_fiber_listen(socket_t sockfd, int backlog)
{
- if (__sys_listen == NULL) {
+ if (sys_listen == NULL) {
hook_once();
}
if (!var_hook_sys_api) {
- return __sys_listen ? __sys_listen(sockfd, backlog) : -1;
+ return sys_listen ? (*sys_listen)(sockfd, backlog) : -1;
}
non_blocking(sockfd, NON_BLOCKING);
- if (__sys_listen(sockfd, backlog) == 0) {
+ if ((*sys_listen)(sockfd, backlog) == 0) {
return 0;
}
@@ -67,20 +67,20 @@ socket_t WINAPI acl_fiber_accept(socket_t sockfd, struct sockaddr *addr,
return -1;
}
- if (__sys_accept == NULL) {
+ if (sys_accept == NULL) {
hook_once();
}
if (!var_hook_sys_api) {
- return __sys_accept ?
- __sys_accept(sockfd, addr, addrlen) : INVALID_SOCKET;
+ return sys_accept ?
+ (*sys_accept)(sockfd, addr, addrlen) : INVALID_SOCKET;
}
#ifdef FAST_ACCEPT
non_blocking(sockfd, NON_BLOCKING);
- clifd = __sys_accept(sockfd, addr, addrlen);
+ clifd = (*sys_accept)(sockfd, addr, addrlen);
if (clifd != INVALID_SOCKET) {
non_blocking(clifd, NON_BLOCKING);
tcp_nodelay(clifd, 1);
@@ -124,7 +124,7 @@ socket_t WINAPI acl_fiber_accept(socket_t sockfd, struct sockaddr *addr,
return clifd;
}
#endif
- clifd = __sys_accept(sockfd, addr, addrlen);
+ clifd = (*sys_accept)(sockfd, addr, addrlen);
if (clifd != INVALID_SOCKET) {
non_blocking(clifd, NON_BLOCKING);
@@ -166,7 +166,7 @@ socket_t WINAPI acl_fiber_accept(socket_t sockfd, struct sockaddr *addr,
return clifd;
}
#endif
- clifd = __sys_accept(sockfd, addr, addrlen);
+ clifd = (*sys_accept)(sockfd, addr, addrlen);
if (clifd != INVALID_SOCKET) {
non_blocking(clifd, NON_BLOCKING);
@@ -192,17 +192,17 @@ int WINAPI acl_fiber_connect(socket_t sockfd, const struct sockaddr *addr,
FILE_EVENT *fe;
time_t begin, end;
- if (__sys_connect == NULL) {
+ if (sys_connect == NULL) {
hook_once();
}
if (!var_hook_sys_api) {
- return __sys_connect ? __sys_connect(sockfd, addr, addrlen) : -1;
+ return sys_connect ? (*sys_connect)(sockfd, addr, addrlen) : -1;
}
non_blocking(sockfd, NON_BLOCKING);
- ret = __sys_connect(sockfd, addr, addrlen);
+ ret = (*sys_connect)(sockfd, addr, addrlen);
if (ret >= 0) {
tcp_nodelay(sockfd, 1);
return ret;
@@ -359,18 +359,18 @@ int setsockopt(int sockfd, int level, int optname,
size_t val;
TIMEOUT_CTX *ctx;
- if (__sys_setsockopt == NULL) {
+ if (sys_setsockopt == NULL) {
hook_once();
}
if (!var_hook_sys_api || (optname != SO_RCVTIMEO
&& optname != SO_SNDTIMEO)) {
- return __sys_setsockopt ? __sys_setsockopt(sockfd, level,
+ return sys_setsockopt ? (*sys_setsockopt)(sockfd, level,
optname, optval, optlen) : -1;
}
- if (__sys_setsockopt == NULL) {
- msg_error("__sys_setsockopt null");
+ if (sys_setsockopt == NULL) {
+ msg_error("sys_setsockopt null");
return -1;
}
diff --git a/lib_fiber/cpp/src/fiber_server.cpp b/lib_fiber/cpp/src/fiber_server.cpp
index 13ac2543e..8e071be26 100644
--- a/lib_fiber/cpp/src/fiber_server.cpp
+++ b/lib_fiber/cpp/src/fiber_server.cpp
@@ -214,14 +214,7 @@ static void *thread_main(void *ctx)
int i;
#if defined(_WIN32) || defined(_WIN64)
-#if 0
- if (winapi_hook()) {
- acl_msg_info("hook Win API ok");
- } else {
- acl_msg_error("hook Win API error: %s", acl_last_serror());
- }
-#endif
-
+ #if 0
SOCKET s = socket(PF_INET, SOCK_STREAM, 0);
if (s == INVALID_SOCKET) {
printf("invalid socket: %s\r\n", acl::last_serror());
@@ -229,6 +222,7 @@ static void *thread_main(void *ctx)
} else {
printf("create socket ok\r\n");
}
+ #endif
#endif
if (__thread_init) {
@@ -819,14 +813,6 @@ static void servers_start(FIBER_SERVER **servers, int nthreads)
acl_pthread_attr_init(&attr);
acl_pthread_attr_setdetachstate(&attr, ACL_PTHREAD_CREATE_DETACHED);
-#if defined(_WIN32) || defined(_WIN64)
- if (winapi_hook()) {
- acl_msg_info("hook Win API ok");
- } else {
- acl_msg_error("hook Win API error: %s", acl_last_serror());
- }
-#endif
-
for (i = 0; i < nthreads; i++) {
acl_pthread_create(&servers[i]->tid, &attr,
thread_main, servers[i]);
@@ -1013,22 +999,36 @@ void acl_fiber_server_main(int argc, char *argv[],
__service_ctx = ctx;
__first_name = name;
-//#if !defined(_WIN32) && !defined(_WIN64)
va_start(ap, name);
+
+#if defined(_WIN32) || defined(_WIN64)
+# if _MSC_VER >= 1911
+ va_copy(__ap_dest, ap);
+# else
+ __ap_dest = ap;
+# endif
+#else
va_copy(__ap_dest, ap);
master_log_open(argv[0]);
+#endif
va_end(ap);
-//#endif
__conf_file[0] = 0;
#ifndef __APPLE__
-
-#if !defined(_WIN32) && !defined(_WIN64)
+# if !defined(_WIN32) && !defined(_WIN64)
opterr = 0;
-#endif
+# endif
optind = 0;
optarg = 0;
+#endif // __APPLE__
+
+#if defined(_WIN32) || defined(_WIN64)
+ if (winapi_hook()) {
+ acl_msg_info("hook Win API ok");
+ } else {
+ acl_msg_error("hook Win API error: %s", acl_last_serror());
+ }
#endif
while ((c = getopt(argc, argv, "Hc:n:s:t:uf:L:")) > 0) {
diff --git a/lib_fiber/cpp/src/winapi_hook.cpp b/lib_fiber/cpp/src/winapi_hook.cpp
index 0149edaea..840de8db2 100644
--- a/lib_fiber/cpp/src/winapi_hook.cpp
+++ b/lib_fiber/cpp/src/winapi_hook.cpp
@@ -1,27 +1,31 @@
#include "stdafx.hpp"
#include "winapi_hook.hpp"
-#if (defined(_WIN32) || defined(_WIN64)) && _MSC_VER >= 1911
+#if (defined(_WIN32) || defined(_WIN64)) && _MSC_VER >= 1929
#include "detours/detours.h"
-SOCKET_FN __socket = socket;
-LISTEN_FN __listen = listen;
-CLOSE_FN __close = closesocket;
-ACCEPT_FN __accept = accept;
-CONNECT_FN __connect = connect;
-RECV_FN __recv = recv;
-RECVFROM_FN __recvfrom = recvfrom;
-SEND_FN __send = send;
-SENDTO_FN __sendto = sendto;
-SELECT_FN __select = select;
-POLL_FN __poll = WSAPoll;
+typedef unsigned long nfds_t;
+#include "../../c/src/hook/hook.h"
-#define HOOK_API(from, to) do { \
- LONG ret = DetourAttach(from, to); \
+socket_fn __socket = socket;
+listen_fn __listen = listen;
+close_fn __close = closesocket;
+accept_fn __accept = accept;
+connect_fn __connect = connect;
+recv_fn __recv = recv;
+recvfrom_fn __recvfrom = recvfrom;
+send_fn __send = send;
+sendto_fn __sendto = sendto;
+select_fn __select = select;
+poll_fn __poll = WSAPoll;
+
+#define HOOK_API(from, to, action) do { \
+ LONG ret = DetourAttach(&from, to); \
if (ret != 0) { \
logger("DetourAttach %s failed %s", #from, acl::last_serror()); \
return false; \
} \
+ action(&from); \
} while (0)
bool winapi_hook(void) {
@@ -36,17 +40,18 @@ bool winapi_hook(void) {
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
- HOOK_API(&(PVOID&) __socket, &acl_fiber_socket);
- HOOK_API(&(PVOID&) __listen, acl_fiber_listen);
- HOOK_API(&(PVOID&) __close, acl_fiber_close);
- HOOK_API(&(PVOID&) __accept, acl_fiber_accept);
- HOOK_API(&(PVOID&) __connect, acl_fiber_connect);
- HOOK_API(&(PVOID&) __recv, acl_fiber_recv);
- HOOK_API(&(PVOID&) __recvfrom, acl_fiber_recvfrom);
- HOOK_API(&(PVOID&) __send, acl_fiber_send);
- HOOK_API(&(PVOID&) __sendto, acl_fiber_sendto);
- HOOK_API(&(PVOID&) __select, acl_fiber_select);
- HOOK_API(&(PVOID&) __poll, acl_fiber_poll);
+ HOOK_API(__socket, &acl_fiber_socket, set_socket_fn);
+ HOOK_API(__close, acl_fiber_close, set_close_fn);
+ HOOK_API(__listen, acl_fiber_listen, set_listen_fn);
+ HOOK_API(__accept, acl_fiber_accept, set_accept_fn);
+ HOOK_API(__connect, acl_fiber_connect, set_connect_fn);
+ HOOK_API(__recv, acl_fiber_recv, set_recv_fn);
+ HOOK_API(__recvfrom, acl_fiber_recvfrom, set_recvfrom_fn);
+ HOOK_API(__send, acl_fiber_send, set_send_fn);
+ HOOK_API(__sendto, acl_fiber_sendto, set_sendto_fn);
+ HOOK_API(__poll, acl_fiber_poll, set_poll_fn);
+ HOOK_API(__select, acl_fiber_select, set_select_fn);
+
DetourTransactionCommit();
return true;
}
diff --git a/lib_fiber/cpp/src/winapi_hook.hpp b/lib_fiber/cpp/src/winapi_hook.hpp
index 19bdfd269..91814df15 100644
--- a/lib_fiber/cpp/src/winapi_hook.hpp
+++ b/lib_fiber/cpp/src/winapi_hook.hpp
@@ -1,40 +1,4 @@
#pragma once
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if !defined(_WIN32) && !defined(_WIN64)
-# define WINAPI
-#endif
-
-typedef socket_t (WINAPI* SOCKET_FN)(int, int, int);
-typedef int (WINAPI* LISTEN_FN)(socket_t, int);
-typedef int (WINAPI* CLOSE_FN)(socket_t);
-typedef socket_t (WINAPI* ACCEPT_FN)(socket_t, struct sockaddr*, socklen_t*);
-typedef int (WINAPI* CONNECT_FN)(socket_t, const struct sockaddr*, socklen_t);
-typedef int (WINAPI* RECV_FN)(socket_t, char*, int, int);
-typedef int (WINAPI* RECVFROM_FN)(socket_t, char*, int, int, struct sockaddr*, socklen_t*);
-typedef int (WINAPI* SEND_FN)(socket_t, const char*, int, int);
-typedef int (WINAPI* SENDTO_FN)(socket_t, const char*, int, int, const struct sockaddr*, socklen_t);
-typedef int (WINAPI* SELECT_FN)(int, fd_set*, fd_set*, fd_set*, const struct timeval*);
-typedef int (WINAPI* POLL_FN)(struct pollfd*, unsigned long, int);
-
-extern SOCKET_FN __socket;
-extern LISTEN_FN __listen;
-extern CLOSE_FN __close;
-extern ACCEPT_FN __accept;
-extern CONNECT_FN __connect;
-extern RECV_FN __recv;
-extern RECVFROM_FN __recvfrom;
-extern SEND_FN __send;
-extern SENDTO_FN __sendto;
-extern SELECT_FN __select;
-extern POLL_FN __poll;
-
bool winapi_hook(void);
-#ifdef __cplusplus
-}
-#endif
-
diff --git a/lib_fiber/samples-c++1x/server/server.vcxproj b/lib_fiber/samples-c++1x/server/server.vcxproj
new file mode 100644
index 000000000..c22bc00dc
--- /dev/null
+++ b/lib_fiber/samples-c++1x/server/server.vcxproj
@@ -0,0 +1,193 @@
+
+
+
+
+ DebugDll
+ Win32
+
+
+ Debug
+ Win32
+
+
+ ReleaseDll
+ Win32
+
+
+ Release
+ Win32
+
+
+
+ {EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}
+ Win32Proj
+ server
+ server
+
+
+
+ Application
+ true
+ v142
+ MultiByte
+
+
+ Application
+ true
+ v142
+ MultiByte
+
+
+ Application
+ true
+ v142
+ MultiByte
+
+
+ Application
+ false
+ v142
+ true
+ MultiByte
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ .\
+
+
+ true
+ .\
+
+
+ true
+ .\
+
+
+ false
+ .\
+
+
+
+ NotUsing
+ Level3
+ Disabled
+ WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
+ true
+ ..\;..\..\c\include;..\..\cpp\include;..\..\..\lib_acl\include;..\..\..\lib_acl_cpp\include
+ MultiThreadedDebugDLL
+
+
+ Console
+ true
+ ..\..\c;..\..\..\lib_acl;
+ libfiber.lib;libfiber_cpp.lib;lib_acl_vc2019d.lib;lib_protocol_vc2019d.lib;lib_acl_cpp_vc2019d.lib;ws2_32.lib;%(AdditionalDependencies)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Level3
+ Disabled
+ WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;ACL_DLL;FIBER_DLL;%(PreprocessorDefinitions)
+ true
+ ..\..\cpp\include; ..\..\..\lib_acl\include;..\; ..\..\..\lib_acl_cpp\include;..\
+ MultiThreadedDebugDLL
+
+
+ Console
+ true
+ ..\..\..\lib_acl;..\..\..\lib_acl_cpp;..\..\..\lib_protocol\;..\..\..\lib_fiber\c;..\..\..\lib_fiber\cpp;
+ libfiber.lib;libfiber_cpp.lib;lib_acl_d.lib;lib_protocol_d.lib;lib_acl_cpp_d.lib;ws2_32.lib;%(AdditionalDependencies)
+
+
+
+
+
+
+ copy ..\..\..\lib_acl\lib_acl_d.dll .\ /Y
+copy ..\..\c\libfiber.dll .\ /Y
+
+
+
+
+ NotUsing
+ Level3
+ Disabled
+ WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;ACL_DLL;FIBER_DLL;%(PreprocessorDefinitions)
+ true
+ ..\..\c\include; ..\..\..\lib_acl\include;..\
+ MultiThreadedDLL
+
+
+ Console
+ true
+ ..\..\c;..\..\..\lib_acl;
+ lib_acl.lib;libfiber.lib;ws2_32.lib;%(AdditionalDependencies)
+
+
+
+
+
+
+ copy ..\..\..\lib_acl\lib_acl.dll .\ /Y
+copy ..\..\c\libfiber.dll .\ /Y
+
+
+
+
+ Level3
+ NotUsing
+ MaxSpeed
+ true
+ true
+ WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
+ true
+ ..\..\c\include; ..\..\..\lib_acl\include;..\
+ MultiThreadedDLL
+
+
+ Console
+ true
+ true
+ true
+ ..\..\c;..\..\..\lib_acl;
+ libfiber.lib;lib_acl_vc2019.lib;ws2_32.lib;%(AdditionalDependencies)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/lib_fiber/samples-c++1x/server/server.vcxproj.filters b/lib_fiber/samples-c++1x/server/server.vcxproj.filters
new file mode 100644
index 000000000..c2fbc52fb
--- /dev/null
+++ b/lib_fiber/samples-c++1x/server/server.vcxproj.filters
@@ -0,0 +1,33 @@
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hpp;hxx;hm;inl;inc;xsd
+
+
+ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
+ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
+
+
+
+
+ 源文件
+
+
+ 源文件
+
+
+
+
+ 头文件
+
+
+ 头文件
+
+
+
\ No newline at end of file
diff --git a/lib_fiber/samples/master_fiber/http_servlet.h b/lib_fiber/samples/master_fiber/http_servlet.h
index fd5d88973..b2f568ad8 100644
--- a/lib_fiber/samples/master_fiber/http_servlet.h
+++ b/lib_fiber/samples/master_fiber/http_servlet.h
@@ -4,7 +4,7 @@ class http_servlet : public acl::HttpServlet
{
public:
http_servlet(acl::socket_stream* stream, acl::session* session)
- : HttpServlet(stream, session)
+ : HttpServlet(stream, session), i_(0)
{
}
@@ -21,13 +21,16 @@ public:
// override
bool doPost(acl::HttpServletRequest&, acl::HttpServletResponse& res)
{
- const char* buf = "hello world!";
- size_t len = strlen(buf);
+ acl::string buf;
+ buf.format("hello world-%d", i_++);
- res.setContentLength(len);
+ res.setContentLength(buf.size());
res.setKeepAlive(true);
// http Ӧ
- return res.write(buf, len) && res.write(NULL, 0);
+ return res.write(buf) && res.write(NULL, 0);
}
+
+private:
+ int i_;
};