while(1) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?connect_fd = accept(listen_fd, (struct sockaddr *)&clt_addr, (socklen_t *)&len); ?? ??? ??? ??? ??? ?
?? ??? ??? ??? ??? ?if ( connect_fd >0) ?? ??? ??? ??? ??? ?{
?? ??? ??? ??? ??? ??? ?printf("\n +++ server connect fd =%d +++\n", connect_fd); ?? ??? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ??? ?/* set socket noblock mode */ ?? ??? ??? ??? ??? ??? ?KLC_Socket_SetNoBlock(connect_fd); ?? ??? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ??? ?setsockopt(connect_fd, SOL_SOCKET, SO_REUSEADDR, (char *)&flag, sizeof(flag)); ?? ??? ??? ??? ??? ??? ?setsockopt(connect_fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(flag));
?? ??? ??? ??? ??? ??? ?/* statistics */ ?? ??? ??? ??? ??? ??? ?socket_connectcounter();
?? ??? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ??? ?if (NULL != Socket_CallBack_Fun) ?? ??? ??? ??? ??? ??? ??? ?Socket_CallBack_Fun(SOCKCMD_OPENED, connect_fd , NULL);
?? ??? ??? ??? ??? ??? ?ev.data.fd = connect_fd; ?? ??? ??? ??? ??? ??? ?ev.events = EPOLLIN|EPOLLET; ?? ??? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ??? ?epoll_ctl(epfd, EPOLL_CTL_ADD, connect_fd, &ev);
?? ??? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ?if ( connect_fd == -1 && errno==EAGAIN) ?? ??? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}?? ??? ??? ? ?
在SOCKET时无阻塞,并且使用ET模式的情况下,CONNECT 代码要直到读取到错误为止,否则会有丢失CONNECT SOCKET的情况。
|