mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-30 02:47:56 +08:00
optimize fiber module by hooking system API on windows
This commit is contained in:
parent
079f1eb069
commit
04aaede734
@ -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)
|
||||
|
@ -410,6 +410,7 @@
|
||||
<ClCompile Include="src\hook\epoll.c" />
|
||||
<ClCompile Include="src\hook\getaddrinfo.c" />
|
||||
<ClCompile Include="src\hook\gethostbyname.c" />
|
||||
<ClCompile Include="src\hook\hook.c" />
|
||||
<ClCompile Include="src\hook\io.c" />
|
||||
<ClCompile Include="src\hook\poll.c" />
|
||||
<ClCompile Include="src\hook\select.c" />
|
||||
@ -428,4 +429,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
@ -189,6 +189,9 @@
|
||||
<ClCompile Include="src\event\event_iocp.c">
|
||||
<Filter>源文件\event</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\hook\hook.c">
|
||||
<Filter>源文件\hook</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\stdafx.h">
|
||||
@ -312,4 +315,4 @@
|
||||
<Filter>源文件\event</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
@ -292,6 +292,7 @@
|
||||
<Text Include="ReadMe.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="hook_api.h" />
|
||||
<ClInclude Include="include\fiber\fiber_base.h" />
|
||||
<ClInclude Include="include\fiber\fiber_channel.h" />
|
||||
<ClInclude Include="include\fiber\fiber_define.h" />
|
||||
|
@ -156,6 +156,9 @@
|
||||
<ClInclude Include="src\event\event_iocp.h">
|
||||
<Filter>源文件\event</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="hook_api.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\stdafx.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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
193
lib_fiber/samples-c++1x/server/server.vcxproj
Normal file
193
lib_fiber/samples-c++1x/server/server.vcxproj
Normal file
@ -0,0 +1,193 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="DebugDll|Win32">
|
||||
<Configuration>DebugDll</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="ReleaseDll|Win32">
|
||||
<Configuration>ReleaseDll</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>server</RootNamespace>
|
||||
<ProjectName>server</ProjectName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugDll|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='DebugDll|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<OutDir>.\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugDll|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<OutDir>.\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<OutDir>.\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<OutDir>.\</OutDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>..\;..\..\c\include;..\..\cpp\include;..\..\..\lib_acl\include;..\..\..\lib_acl_cpp\include</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>..\..\c;..\..\..\lib_acl;</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>libfiber.lib;libfiber_cpp.lib;lib_acl_vc2019d.lib;lib_protocol_vc2019d.lib;lib_acl_cpp_vc2019d.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<IgnoreAllDefaultLibraries>
|
||||
</IgnoreAllDefaultLibraries>
|
||||
<IgnoreSpecificDefaultLibraries>
|
||||
</IgnoreSpecificDefaultLibraries>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>
|
||||
</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugDll|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;ACL_DLL;FIBER_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>..\..\cpp\include; ..\..\..\lib_acl\include;..\; ..\..\..\lib_acl_cpp\include;..\</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>..\..\..\lib_acl;..\..\..\lib_acl_cpp;..\..\..\lib_protocol\;..\..\..\lib_fiber\c;..\..\..\lib_fiber\cpp;</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>libfiber.lib;libfiber_cpp.lib;lib_acl_d.lib;lib_protocol_d.lib;lib_acl_cpp_d.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<IgnoreAllDefaultLibraries>
|
||||
</IgnoreAllDefaultLibraries>
|
||||
<IgnoreSpecificDefaultLibraries>
|
||||
</IgnoreSpecificDefaultLibraries>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>copy ..\..\..\lib_acl\lib_acl_d.dll .\ /Y
|
||||
copy ..\..\c\libfiber.dll .\ /Y</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;ACL_DLL;FIBER_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>..\..\c\include; ..\..\..\lib_acl\include;..\</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>..\..\c;..\..\..\lib_acl;</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>lib_acl.lib;libfiber.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<IgnoreAllDefaultLibraries>
|
||||
</IgnoreAllDefaultLibraries>
|
||||
<IgnoreSpecificDefaultLibraries>
|
||||
</IgnoreSpecificDefaultLibraries>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>copy ..\..\..\lib_acl\lib_acl.dll .\ /Y
|
||||
copy ..\..\c\libfiber.dll .\ /Y</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>..\..\c\include; ..\..\..\lib_acl\include;..\</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>..\..\c;..\..\..\lib_acl;</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>libfiber.lib;lib_acl_vc2019.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="stdafx.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="http_servlet.h" />
|
||||
<ClInclude Include="stdafx.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
33
lib_fiber/samples-c++1x/server/server.vcxproj.filters
Normal file
33
lib_fiber/samples-c++1x/server/server.vcxproj.filters
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="源文件">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="头文件">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="资源文件">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="http_servlet.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="stdafx.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -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_;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user