void MyServerSocket::onAccept(sockaddr_in * addr, int handle){ uLong user_id = (addr->sin_addr).s_addr; ClientSocket * socket = createClient((addr->sin_addr).s_addr, inet_ntoa(addr->sin_addr), ntohs(addr->sin_port)); socket->OnAccept(handle); socket->status = socket_ready; socket->s_status = session_connect; /* 成功赋值了 为何?*/ socket->Recevice(); /* add sessions */ //clients.insert(ScoketPair(user_id, socket)); }
ClientSocket *SocketIO::Accept(ListenSocket *s) { sockaddrs conaddr; socklen_t size = sizeof(conaddr); int newsock = accept(s->GetFD(), &conaddr.sa, &size); if (newsock >= 0) { ClientSocket *ns = s->OnAccept(newsock, conaddr); ns->flags[SF_ACCEPTED] = true; ns->OnAccept(); return ns; } else throw SocketException("Unable to accept connection: " + Anope::LastError()); }
/** Accept a connection from a socket * @param s The socket * @return The new client socket */ ClientSocket *SocketIO::Accept(ListenSocket *s) { sockaddrs conaddr; socklen_t size = sizeof(conaddr); int newsock = accept(s->GetFD(), &conaddr.sa, &size); if (newsock >= 0) { ClientSocket *ns = s->OnAccept(newsock, conaddr); ns->SetStatus(SF_ACCEPTED, true); ns->OnAccept(); return ns; } else throw SocketException(printfify("Unable to accept connection: %s", strerror(errno))); }