void DESC_MANAGER::DestroyDesc(LPDESC d, bool bEraseFromSet) { if (bEraseFromSet) m_set_pkDesc.erase(d); if (d->GetHandshake()) m_map_handshake.erase(d->GetHandshake()); if (d->GetHandle() != 0) m_map_handle.erase(d->GetHandle()); else m_set_pkClientDesc.erase((LPCLIENT_DESC) d); // Explicit call to the virtual function Destroy() d->Destroy(); M2_DELETE(d); --m_iSocketsConnected; }
LPDESC DESC_MANAGER::AcceptDesc(LPFDWATCH fdw, socket_t s) { socket_t desc; LPDESC newd; static struct sockaddr_in peer; static char host[MAX_HOST_LENGTH + 1]; if ((desc = socket_accept(s, &peer)) == -1) return NULL; strlcpy(host, inet_ntoa(peer.sin_addr), sizeof(host)); if (g_bAuthServer) { if (IsBanIP(peer.sin_addr)) { sys_log(0, "connection from %s was banned.", host); socket_close(desc); return NULL; } } if (!IsValidIP(admin_ip, host)) // admin_ip 에 등록된 IP 는 최대 사용자 수에 구애받지 않는다. { if (m_iSocketsConnected >= MAX_ALLOW_USER) { sys_err("max connection reached. MAX_ALLOW_USER = %d", MAX_ALLOW_USER); socket_close(desc); return NULL; } } newd = M2_NEW DESC; crc_t handshake = CreateHandshake(); if (!newd->Setup(fdw, desc, peer, ++m_iHandleCount, handshake)) { socket_close(desc); M2_DELETE(newd); return NULL; } m_map_handshake.insert(DESC_HANDSHAKE_MAP::value_type(handshake, newd)); m_map_handle.insert(DESC_HANDLE_MAP::value_type(newd->GetHandle(), newd)); m_set_pkDesc.insert(newd); ++m_iSocketsConnected; return (newd); }