登录 用户中心() [退出] 后台管理 注册
   
您的位置: 首页 >> 程序员学前班[不再更新,只读] >> 主题: [mysql/unix/linux]怪异的 accept 方式     [回主站]     [分站链接]
标题
[mysql/unix/linux]怪异的 accept 方式
clq
浏览(0) + 2009-06-25 10:53:08 发表 编辑

关键字:

[mysql/unix/linux]怪异的 accept 方式

http://fanqiang.chinaunix.net/a4/b7/20010913/0900001283.html

--------------------------------------------------

[ 永远的UNIX::UNIX技术资料的宝库 ]
首页 > 编程技术 > 网络编程 > 正文
Socket编程中select()的妙用
本文出自: 作者: (2001-09-13 09:00:00)
发信站: 华南网木棉站 (Tue Aug 4 15:43:41 1998), 转信

【 原文由 cpu 所发表 】

用过 WinSock API 网友们知道:WinSock 编程中有一很方便的地方便是其
息驱动机制,不管是底层 API 的 WSAAsyncSelect() 还是 MFC 的异步Socket类:
CAsyncSocket,都提供了诸如 FD_ACCEPT、FD_READ、FD_CLOSE 之类的消息
供编程人员捕捉并处理。FD_ACCEPT 通知进程有客户方Socket请求连接,
FD_READ通知进程本地Socket有东东可读,FD_CLOSE通知进程对方Socket已
关闭。那么,BSD Socket 是不是真的相形见拙呢?

非也! 'cause cpu love unix so.

BSD UNIX中有一系统调用芳名select()完全可以提供类似的消息驱动机制。
cpu郑重宣布:WinSock的WSAAsyncSeclet()不过是此select()的fork版!

bill也是fork出来的嘛,xixi.

select()的机制中提供一fd_set的数据结构,实际上是一long类型的数组,
每一个数组元素都能与一打开的文件句柄(不管是Socket句柄,还是其他
文件或命名管道或设备句柄)建立联系,建立联系的工作由程序员完成,
当调用select()时,由内核根据IO状态修改fd_set的内容,由此来通知执
行了select()的进程哪一Socket或文件可读,下面具体解释:

#include
#include
#include

int select(nfds, readfds, writefds, exceptfds, timeout)
int nfds;
fd_set *readfds, *writefds, *exceptfds;
struct timeval *timeout;

ndfs:select监视的文件句柄数,视进程中打开的文件数而定,一般设为呢要监视各文件
中的最大文件号加一。
readfds:select监视的可读文件句柄集合。
writefds: select监视的可写文件句柄集合。
exceptfds:select监视的异常文件句柄集合。
timeout:本次select()的超时结束时间。(见/usr/sys/select.h,
可精确至百万分之一秒!)

当readfds或writefds中映象的文件可读或可写或超时,本次select()
就结束返回。程序员利用一组系统提供的宏在select()结束时便可判
断哪一文件可读或可写。对Socket编程特别有用的就是readfds。
几只相关的宏解释如下:

FD_ZERO(fd_set *fdset):清空fdset与所有文件句柄的联系。
FD_SET(int fd, fd_set *fdset):建立文件句柄fd与fdset的联系。
FD_CLR(int fd, fd_set *fdset):清除文件句柄fd与fdset的联系。
FD_ISSET(int fd, fdset *fdset):检查fdset联系的文件句柄fd是否
可读写,>0表示可读写。
(关于fd_set及相关宏的定义见/usr/include/sys/types.h)

这样,你的socket只需在有东东读的时候才读入,大致如下:

...
int sockfd;
fd_set fdR;
struct timeval timeout = ..;
...
for(;;) {
FD_ZERO(&fdR);
FD_SET(sockfd, &fdR);
switch (select(sockfd + 1, &fdR, NULL, &timeout)) {
case -1:
error handled by u;
case 0:
timeout hanled by u;
default:
if (FD_ISSET(sockfd)) {
now u read or recv something;
/* if sockfd is father and
server socket, u can now
accept() */
}
}
}

所以一个FD_ISSET(sockfd)就相当通知了sockfd可读。
至于struct timeval在此的功能,请man select。不同的timeval设置
使使select()表现出超时结束、无超时阻塞和轮询三种特性。由于
timeval可精确至百万分之一秒,所以Windows的SetTimer()根本不算
什么。你可以用select()做一个超级时钟。

FD_ACCEPT的实现?依然如上,因为客户方socket请求连接时,会发送
连接请求报文,此时select()当然会结束,FD_ISSET(sockfd)当然大
于零,因为有报文可读嘛!至于这方面的应用,主要在于服务方的父
Socket,你若不喜欢主动accept(),可改为如上机制来accept()。

至于FD_CLOSE的实现及处理,颇费了一堆cpu处理时间,未完待续。

--
讨论关于利用select()检测对方Socket关闭的问题:

仍然是本地Socket有东东可读,因为对方Socket关闭时,会发一个关闭连接
通知报文,会马上被select()检测到的。关于TCP的连接(三次握手)和关
闭(二次握手)机制,敬请参考有关TCP/IP的书籍。

不知是什么原因,UNIX好象没有提供通知进程关于Socket或Pipe对方关闭的
信号,也可能是cpu所知有限。总之,当对方关闭,一执行recv()或read(),
马上回返回-1,此时全局变量errno的值是115,相应的sys_errlist[errno]
为"Connect refused"(请参考/usr/include/sys/errno.h)。所以,在上
篇的for(;;)...select()程序块中,当有东西可读时,一定要检查recv()或
read()的返回值,返回-1时要作出关断本地Socket的处理,否则select()会
一直认为有东西读,其结果曾几令cpu伤心欲断针脚。不信你可以试试:不检
查recv()返回结果,且将收到的东东(实际没收到)写至标准输出...
在有名管道的编程中也有类似问题出现。具体处理详见拙作:发布一个有用
的Socket客户方原码。

至于主动写Socket时对方突然关闭的处理则可以简单地捕捉信号SIGPIPE并作
出相应关断本地Socket等等的处理。SIGPIPE的解释是:写入无读者方的管道。
在此不作赘述,请详man signal。

以上是cpu在作tcp/ip数据传输实验积累的经验,若有错漏,请狂炮击之。

唉,昨天在hacker区被一帮孙子轰得差点儿没短路。ren cpu(奔腾的心) z80

补充关于select在异步(非阻塞)connect中的应用,刚开始搞socket编程的时候
我一直都用阻塞式的connect,非阻塞connect的问题是由于当时搞proxy scan
而提出的呵呵
通过在网上与网友们的交流及查找相关FAQ,总算知道了怎么解决这一问题.同样
用select可以很好地解决这一问题.大致过程是这样的:

1.将打开的socket设为非阻塞的,可以用fcntl(socket, F_SETFL, O_NDELAY)完
成(有的系统用FNEDLAY也可).

2.发connect调用,这时返回-1,但是errno被设为EINPROGRESS,意即connect仍旧
在进行还没有完成.

3.将打开的socket设进被监视的可写(注意不是可读)文件集合用select进行监视,
如果可写,用
getsockopt(socket, SOL_SOCKET, SO_ERROR, &error, sizeof(int));
来得到error的值,如果为零,则connect成功.

在许多unix版本的proxyscan程序你都可以看到类似的过程,另外在solaris精华
区->编程技巧中有一个通用的带超时参数的connect模块.

(http://www.fanqiang.com) 进入【UNIX论坛】
相关文章
Java源码:Socket编程 (2002-01-02 08:10:00)
Java做一个最简单的Socket通话程序 (2001-12-30 08:30:00)
类似socket传输的flush() (2001-12-03 07:10:00)
Socket编程中select()的妙用 (2001-09-13 09:00:00)
用gcc 编译,为何有不同的结果 (关于socket函数)? (2001-08-29 10:00:00)
BSD Socket 简易入门手册 (2001-08-21 09:00:00)
用Perl语言进行Socket编程 (2001-08-20 15:00:00)
linux kernel 2.4.5 ipv4 socket层的一点解释 (2001-07-30 10:00:00)
Unix环境下的Socket编程 (2001-06-26 15:00:01)
Linux程式设计- 4.socket (2001-05-24 17:24:26)

===更多相关===


★ 樊强制作 欢迎分享 ★

clq
2009-6-25 10:54:15 发表 编辑

mysql 与之极其相似.

--------------------------------------------------

#ifndef EMBEDDED_LIBRARY
//clq//extern "C" pthread_handler_decl(handle_connections_sockets,
//clq// arg __attribute__((unused)))
int pthread_handler_decl_old()
{
my_socket sock,new_sock;
uint error_count=0;
uint max_used_connection= (uint) (max(ip_sock,unix_sock)+1);
fd_set readFDs,clientFDs;
THD *thd;
struct sockaddr_in cAddr;
int ip_flags=0,socket_flags=0,flags;
st_vio *vio_tmp;
DBUG_ENTER("handle_connections_sockets");

LINT_INIT(new_sock);

(void) my_pthread_getprio(pthread_self()); // For debugging

FD_ZERO(&clientFDs);
if (ip_sock != INVALID_SOCKET)
{
FD_SET(ip_sock,&clientFDs);
#ifdef HAVE_FCNTL
ip_flags = fcntl(ip_sock, F_GETFL, 0);
#endif
}
#ifdef HAVE_SYS_UN_H
FD_SET(unix_sock,&clientFDs);
#ifdef HAVE_FCNTL
socket_flags=fcntl(unix_sock, F_GETFL, 0);
#endif
#endif

DBUG_PRINT("general",("Waiting for connections."));
MAYBE_BROKEN_SYSCALL;
while (!abort_loop)
{
readFDs=clientFDs;
#ifdef HPUX10
if (select(max_used_connection,(int*) &readFDs,0,0,0) < 0)
continue;
#else
if (select((int) max_used_connection,&readFDs,0,0,0) < 0)
{
if (socket_errno != SOCKET_EINTR)
{
if (!select_errors++ && !abort_loop) /* purecov: inspected */
sql_print_error("mysqld: Got error %d from select",socket_errno); /* purecov: inspected */
}
MAYBE_BROKEN_SYSCALL
continue;
}
#endif /* HPUX10 */
if (abort_loop)
{
MAYBE_BROKEN_SYSCALL;
break;
}

/* Is this a new connection request ? */
#ifdef HAVE_SYS_UN_H
if (FD_ISSET(unix_sock,&readFDs))
{
sock = unix_sock;
flags= socket_flags;
}
else
#endif
{
sock = ip_sock;
flags= ip_flags;
}

#if !defined(NO_FCNTL_NONBLOCK)
if (!(test_flags & TEST_BLOCKING))
{
#if defined(O_NONBLOCK)
fcntl(sock, F_SETFL, flags | O_NONBLOCK);
#elif defined(O_NDELAY)
fcntl(sock, F_SETFL, flags | O_NDELAY);
#endif
}
#endif /* NO_FCNTL_NONBLOCK */
for (uint retry=0; retry < MAX_ACCEPT_RETRY; retry++)
{
size_socket length=sizeof(struct sockaddr_in);
new_sock = accept(sock, my_reinterpret_cast(struct sockaddr *) (&cAddr),
&length);
#ifdef __NETWARE__
// TODO: temporary fix, waiting for TCP/IP fix - DEFECT000303149
if ((new_sock == INVALID_SOCKET) && (socket_errno == EINVAL))
{
kill_server(SIGTERM);
}
#endif
if (new_sock != INVALID_SOCKET ||
(socket_errno != SOCKET_EINTR && socket_errno != SOCKET_EAGAIN))
break;
MAYBE_BROKEN_SYSCALL;
#if !defined(NO_FCNTL_NONBLOCK)
if (!(test_flags & TEST_BLOCKING))
{
if (retry == MAX_ACCEPT_RETRY - 1)
fcntl(sock, F_SETFL, flags); // Try without O_NONBLOCK
}
#endif
}
#if !defined(NO_FCNTL_NONBLOCK)
if (!(test_flags & TEST_BLOCKING))
fcntl(sock, F_SETFL, flags);
#endif
if (new_sock == INVALID_SOCKET)
{
if ((error_count++ & 255) == 0) // This can happen often
sql_perror("Error in accept");
MAYBE_BROKEN_SYSCALL;
if (socket_errno == SOCKET_ENFILE || socket_errno == SOCKET_EMFILE)
sleep(1); // Give other threads some time
continue;
}

#ifdef HAVE_LIBWRAP
{
if (sock == ip_sock)
{
struct request_info req;
signal(SIGCHLD, SIG_DFL);
request_init(&req, RQ_DAEMON, libwrapName, RQ_FILE, new_sock, NULL);
fromhost(&req);
if (!hosts_access(&req))
{
/*
This may be stupid but refuse() includes an exit(0)
which we surely don't want...
clean_exit() - same stupid thing ...
*/
syslog(deny_severity, "refused connect from %s",
eval_client(&req));

/*
C++ sucks (the gibberish in front just translates the supplied
sink function pointer in the req structure from a void (*sink)();
to a void(*sink)(int) if you omit the cast, the C++ compiler
will cry...
*/
if (req.sink)
((void (*)(int))req.sink)(req.fd);

(void) shutdown(new_sock,2);
(void) closesocket(new_sock);
continue;
}
}
}
#endif /* HAVE_LIBWRAP */

{
size_socket dummyLen;
struct sockaddr dummy;
dummyLen = sizeof(struct sockaddr);
if (getsockname(new_sock,&dummy, &dummyLen) < 0)
{
sql_perror("Error on new connection socket");
(void) shutdown(new_sock,2);
(void) closesocket(new_sock);
continue;
}
}

/*
** Don't allow too many connections
*/

if (!(thd= new THD))
{
(void) shutdown(new_sock,2);
VOID(closesocket(new_sock));
continue;
}
if (!(vio_tmp=vio_new(new_sock,
sock == unix_sock ? VIO_TYPE_SOCKET :
VIO_TYPE_TCPIP,
sock == unix_sock)) ||
my_net_init(&thd->net,vio_tmp))
{
if (vio_tmp)
vio_delete(vio_tmp);
else
{
(void) shutdown(new_sock,2);
(void) closesocket(new_sock);
}
delete thd;
continue;
}
if (sock == unix_sock)
thd->host=(char*) my_localhost;
#ifdef __WIN__
/* Set default wait_timeout */
ulong wait_timeout= global_system_variables.net_wait_timeout * 1000;
(void) setsockopt(new_sock, SOL_SOCKET, SO_RCVTIMEO, (char*)&wait_timeout,
sizeof(wait_timeout));
#endif
create_new_thread(thd);
}

#ifdef OS2
// kill server must be invoked from thread 1!
kill_server(MYSQL_KILL_SIGNAL);
#endif
decrement_handler_count();
DBUG_RETURN(0);
}


#ifdef __NT__
extern "C" pthread_handler_decl(handle_connections_namedpipes,arg)
{
HANDLE hConnectedPipe;
BOOL fConnected;
THD *thd;
my_thread_init();
DBUG_ENTER("handle_connections_namedpipes");
(void) my_pthread_getprio(pthread_self()); // For debugging

DBUG_PRINT("general",("Waiting for named pipe connections."));
while (!abort_loop)
{
/* wait for named pipe connection */
fConnected = ConnectNamedPipe( hPipe, NULL );
if (abort_loop)
break;
if (!fConnected)
fConnected = GetLastError() == ERROR_PIPE_CONNECTED;
if (!fConnected)
{
CloseHandle( hPipe );
if ((hPipe = CreateNamedPipe(pipe_name,
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_BYTE |
PIPE_READMODE_BYTE |
PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES,
(int) global_system_variables.net_buffer_length,
(int) global_system_variables.net_buffer_length,
NMPWAIT_USE_DEFAULT_WAIT,
&saPipeSecurity )) ==
INVALID_HANDLE_VALUE )
{
sql_perror("Can't create new named pipe!");
break; // Abort
}
}
hConnectedPipe = hPipe;
/* create new pipe for new connection */
if ((hPipe = CreateNamedPipe(pipe_name,
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_BYTE |
PIPE_READMODE_BYTE |
PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES,
(int) global_system_variables.net_buffer_length,
(int) global_system_variables.net_buffer_length,
NMPWAIT_USE_DEFAULT_WAIT,
&saPipeSecurity)) ==
INVALID_HANDLE_VALUE)
{
sql_perror("Can't create new named pipe!");
hPipe=hConnectedPipe;
continue; // We have to try again
}

if (!(thd = new THD))
{
DisconnectNamedPipe( hConnectedPipe );
CloseHandle( hConnectedPipe );
continue;
}
if (!(thd->net.vio = vio_new_win32pipe(hConnectedPipe)) ||
my_net_init(&thd->net, thd->net.vio))
{
close_connection(thd, ER_OUT_OF_RESOURCES, 1);
delete thd;
continue;
}
/* host name is unknown */
thd->host = my_strdup(my_localhost,MYF(0)); /* Host is unknown */
create_new_thread(thd);
}

decrement_handler_count();
DBUG_RETURN(0);
}
#endif /* __NT__ */


/*
Thread of shared memory's service

SYNOPSIS
pthread_handler_decl()
handle_connections_shared_memory Thread handle
arg Arguments of thread
*/

#ifdef HAVE_SMEM
pthread_handler_decl(handle_connections_shared_memory,arg)
{
/* file-mapping object, use for create shared memory */
HANDLE handle_connect_file_map= 0;
char *handle_connect_map= 0; // pointer on shared memory
HANDLE event_connect_answer= 0;
ulong smem_buffer_length= shared_memory_buffer_length + 4;
ulong connect_number= 1;
char tmp[63];
char *suffix_pos;
char connect_number_char[22], *p;
const char *errmsg= 0;
SECURITY_ATTRIBUTES *sa_event= 0, *sa_mapping= 0;
my_thread_init();
DBUG_ENTER("handle_connections_shared_memorys");
DBUG_PRINT("general",("Waiting for allocated shared memory."));

if (my_security_attr_create(&sa_event, &errmsg,
GENERIC_ALL, SYNCHRONIZE | EVENT_MODIFY_STATE))
goto error;

if (my_security_attr_create(&sa_mapping, &errmsg,
GENERIC_ALL, FILE_MAP_READ | FILE_MAP_WRITE))
goto error;

/*
The name of event and file-mapping events create agree next rule:
shared_memory_base_name+unique_part
Where:
shared_memory_base_name is unique value for each server
unique_part is unique value for each object (events and file-mapping)
*/
suffix_pos= strxmov(tmp,shared_memory_base_name,"_",NullS);
strmov(suffix_pos, "CONNECT_REQUEST");
if ((smem_event_connect_request= CreateEvent(sa_event,
FALSE, FALSE, tmp)) == 0)
{
errmsg= "Could not create request event";
goto error;
}
strmov(suffix_pos, "CONNECT_ANSWER");
if ((event_connect_answer= CreateEvent(sa_event, FALSE, FALSE, tmp)) == 0)
{
errmsg="Could not create answer event";
goto error;
}
strmov(suffix_pos, "CONNECT_DATA");
if ((handle_connect_file_map=
CreateFileMapping(INVALID_HANDLE_VALUE, sa_mapping,
PAGE_READWRITE, 0, sizeof(connect_number), tmp)) == 0)
{
errmsg= "Could not create file mapping";
goto error;
}
if ((handle_connect_map= (char *)MapViewOfFile(handle_connect_file_map,
FILE_MAP_WRITE,0,0,
sizeof(DWORD))) == 0)
{
errmsg= "Could not create shared memory service";
goto error;
}

while (!abort_loop)
{
/* Wait a request from client */
WaitForSingleObject(smem_event_connect_request,INFINITE);

/*
it can be after shutdown command
*/
if (abort_loop)
goto error;

HANDLE handle_client_file_map= 0;
char *handle_client_map= 0;
HANDLE event_client_wrote= 0;
HANDLE event_client_read= 0; // for transfer data server <-> client
HANDLE event_server_wrote= 0;
HANDLE event_server_read= 0;
HANDLE event_conn_closed= 0;
THD *thd= 0;

p= int10_to_str(connect_number, connect_number_char, 10);
/*
The name of event and file-mapping events create agree next rule:
shared_memory_base_name+unique_part+number_of_connection
Where:
shared_memory_base_name is uniquel value for each server
unique_part is unique value for each object (events and file-mapping)
number_of_connection is connection-number between server and client
*/
suffix_pos= strxmov(tmp,shared_memory_base_name,"_",connect_number_char,
"_",NullS);
strmov(suffix_pos, "DATA");
if ((handle_client_file_map=
CreateFileMapping(INVALID_HANDLE_VALUE, sa_mapping,
PAGE_READWRITE, 0, smem_buffer_length, tmp)) == 0)
{
errmsg= "Could not create file mapping";
goto errorconn;
}
if ((handle_client_map= (char*)MapViewOfFile(handle_client_file_map,
FILE_MAP_WRITE,0,0,
smem_buffer_length)) == 0)
{
errmsg= "Could not create memory map";
goto errorconn;
}
strmov(suffix_pos, "CLIENT_WROTE");
if ((event_client_wrote= CreateEvent(sa_event, FALSE, FALSE, tmp)) == 0)
{
errmsg= "Could not create client write event";
goto errorconn;
}
strmov(suffix_pos, "CLIENT_READ");
if ((event_client_read= CreateEvent(sa_event, FALSE, FALSE, tmp)) == 0)
{
errmsg= "Could not create client read event";
goto errorconn;
}
strmov(suffix_pos, "SERVER_READ");
if ((event_server_read= CreateEvent(sa_event, FALSE, FALSE, tmp)) == 0)
{
errmsg= "Could not create server read event";
goto errorconn;
}
strmov(suffix_pos, "SERVER_WROTE");
if ((event_server_wrote= CreateEvent(sa_event,
FALSE, FALSE, tmp)) == 0)
{
errmsg= "Could not create server write event";
goto errorconn;
}
strmov(suffix_pos, "CONNECTION_CLOSED");
if ((event_conn_closed= CreateEvent(sa_event,
TRUE, FALSE, tmp)) == 0)
{
errmsg= "Could not create closed connection event";
goto errorconn;
}
if (abort_loop)
goto errorconn;
if (!(thd= new THD))
goto errorconn;
/* Send number of connection to client */
int4store(handle_connect_map, connect_number);
if (!SetEvent(event_connect_answer))
{
errmsg= "Could not send answer event";
goto errorconn;
}
/* Set event that client should receive data */
if (!SetEvent(event_client_read))
{
errmsg= "Could not set client to read mode";
goto errorconn;
}
if (!(thd->net.vio= vio_new_win32shared_memory(&thd->net,
handle_client_file_map,
handle_client_map,
event_client_wrote,
event_client_read,
event_server_wrote,
event_server_read,
event_conn_closed)) ||
my_net_init(&thd->net, thd->net.vio))
{
close_connection(thd, ER_OUT_OF_RESOURCES, 1);
errmsg= 0;
goto errorconn;
}
thd->host= my_strdup(my_localhost,MYF(0)); /* Host is unknown */
create_new_thread(thd);
connect_number++;
continue;

errorconn:
/* Could not form connection; Free used handlers/memort and retry */
if (errmsg)
{
char buff[180];
strxmov(buff, "Can't create shared memory connection: ", errmsg, ".",
NullS);
sql_perror(buff);
}
if (handle_client_file_map)
CloseHandle(handle_client_file_map);
if (handle_client_map)
UnmapViewOfFile(handle_client_map);
if (event_server_wrote)
CloseHandle(event_server_wrote);
if (event_server_read)
CloseHandle(event_server_read);
if (event_client_wrote)
CloseHandle(event_client_wrote);
if (event_client_read)
CloseHandle(event_client_read);
if (event_conn_closed)
CloseHandle(event_conn_closed);
delete thd;
}

/* End shared memory handling */
error:
if (errmsg)
{
char buff[180];
strxmov(buff, "Can't create shared memory service: ", errmsg, ".", NullS);
sql_perror(buff);
}
my_security_attr_free(sa_event);
my_security_attr_free(sa_mapping);
if (handle_connect_map) UnmapViewOfFile(handle_connect_map);
if (handle_connect_file_map) CloseHandle(handle_connect_file_map);
if (event_connect_answer) CloseHandle(event_connect_answer);
if (smem_event_connect_request) CloseHandle(smem_event_connect_request);

decrement_handler_count();
DBUG_RETURN(0);
}
#endif /* HAVE_SMEM */
#endif /* EMBEDDED_LIBRARY */

clq
2009-6-25 10:55:28 发表 编辑


// 设置监听端口号
if (::bind(socket_handle, (struct sockaddr*)&addr, sizeof(SOCKADDR_IN)) == SOCKET_ERROR)
{
::closesocket(socket_handle);
socket_handle = INVALID_SOCKET;
return false;
}

//关于SOMAXCONN是有一些讨论的,也许为128或者256比较好
if (::listen(socket_handle, SOMAXCONN) == SOCKET_ERROR)
{
::closesocket(socket_handle);
socket_handle = INVALID_SOCKET;
return false;
}


总数:2 页次:1/1 首页 尾页  
总数:2 页次:1/1 首页 尾页  


所在合集/目录



发表评论:
文本/html模式切换 插入图片 文本/html模式切换


附件:



NEWBT官方QQ群1: 276678893
可求档连环画,漫画;询问文本处理大师等软件使用技巧;求档softhub软件下载及使用技巧.
但不可"开车",严禁国家敏感话题,不可求档涉及版权的文档软件.
验证问题说明申请入群原因即可.

Copyright © 2005-2020 clq, All Rights Reserved
版权所有
桂ICP备15002303号-1