NET_ERROR_CODE TcpNetwork::NewSession() { SOCKADDR_IN client_addr; int client_len = static_cast<int>(sizeof(client_addr)); auto client_sockfd = accept(m_ServerSockfd, (SOCKADDR*)&client_addr, &client_len); if (client_sockfd < 0) { m_pRefLogger->Write(LOG_TYPE::L_ERROR, "%s | Wrong socket %d cannot accept", __FUNCTION__, client_sockfd); return NET_ERROR_CODE::ACCEPT_API_ERROR; } auto newSessionIndex = AllocClientSessionIndex(); //index pool 이용해서 여유가 있는지 체크. if (newSessionIndex < 0) { m_pRefLogger->Write(LOG_TYPE::L_WARN, "%s | client_sockfd(%d) >= MAX_SESSION", __FUNCTION__, client_sockfd); //pool에서 얻어 올 수 없었으므로 바로 짜름. CloseSession(ServerConfig::SOCKET_CLOSE_CASE::SESSION_POOL_EMPTY, client_sockfd, -1); return NET_ERROR_CODE::ACCEPT_MAX_SESSION_COUNT; } char clientIP[ServerConfig::MAX_IP_LEN] = { 0, }; inet_ntop(AF_INET, &(client_addr.sin_addr), clientIP, ServerConfig::MAX_IP_LEN - 1); SetSockOption(client_sockfd); FD_SET(client_sockfd, &m_Readfds); ConnectedSession(newSessionIndex, (int)client_sockfd, clientIP);//여기까지... 아직 미완성 return NET_ERROR_CODE::NONE; }
TCPServerLib::NET_ERROR_CODE TCPNetwork::NewSession() { SOCKADDR_IN clientAddr; int addrLen = sizeof(SOCKADDR_IN); SOCKET clientSockFd; clientSockFd = accept(m_serverSocket, (SOCKADDR*)&clientAddr, &addrLen); if (clientSockFd < 0) { return NET_ERROR_CODE::ACCEPT_API_ERROR; } int newSessionIdx = GetClientSessionIndex(); if (newSessionIdx < 0) { CloseSession(SOCKET_CLOSE_CASE::SESSION_POOL_EMPTY, clientSockFd, -1); return NET_ERROR_CODE::ACCEPT_MAX_SESSION_COUNT; } SetSockOption(clientSockFd); FD_SET(clientSockFd, &m_readSet); ConnectedSession(newSessionIdx, clientSockFd); return NET_ERROR_CODE::NONE; }