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);
my_fromhost(&req);
if (!my_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",
my_eva l_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, SHUT_RDWR);//关闭连接
(void) closesocket(new_sock);
continue;
}
}
}
#endif /* HAVE_LIBWRAP */
{
size_socket dummyLen;
struct sockaddr_storage dummy;
dummyLen = sizeof(dummy);
if ( getsockname(new_sock,(struct sockaddr *)&dummy,
(SOCKET_SIZE_TYPE *)&dummyLen) < 0 )
{
sql_perror("Error on new connection socket");
(void) shutdown(new_sock, SHUT_RDWR);
(void) closesocket(new_sock);
continue;
}
}
/*
** Don't allow too many connections
*/
if (!(thd= new THD))//为该连接分配处理的结构,在以后用于给线程使用
{
(void) shutdown(new_sock, SHUT_RDWR);
(void) closesocket(new_sock);
continue;
}
if (!(vio_tmp=vio_new(new_sock,
sock == unix_sock VIO_TYPE_SOCKET :
VIO_TYPE_TCPIP,
sock == unix_sock VIO_LOCALHOST: 0)) ||
my_net_init(&thd->net,vio_tmp))//初始化网络
{
/*
Only delete the temporary vio if we didn't already attach it to the
NET object. The destructor in THD will delete any initialized net
structure.
*/
if (vio_tmp && thd->net.vio != vio_tmp)
vio_delete(vio_tmp);
else
{
(void) shutdown(new_sock, SHUT_RDWR);
(void) closesocket(new_sock);
}
delete thd;
continue;
}
if (sock == unix_sock)
thd->security_ctx->host=(char*) my_localhost;
create_new_thread(thd);//准备为连接分配线程
}
DBUG_VOID_RETURN;
}