From: Christian P. <cp...@us...> - 2005-02-10 19:10:49
|
Update of /cvsroot/pclasses/pclasses2/src/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1512/src/Net Added Files: ServerSocketManager.cpp Log Message: Added ServerSocketManager --- NEW FILE: ServerSocketManager.cpp --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pclasses/Net/ServerSocketManager.h" namespace P { namespace Net { typedef std::list< StreamSocketServer* > ServerList; typedef std::map< StreamSocketServer*, SocketListener* > ListenersMap; ServerSocketManager::ServerSocketManager() { } ServerSocketManager::~ServerSocketManager() { // delete all listeners ... ListenersMap::const_iterator li = _listeners.begin(); while(li != _listeners.end()) { delete li->second; ++li; } // delete the server sockets ... ServerList::const_iterator si = _servers.begin(); while(si != _servers.end()) { delete *si; ++si; } } void ServerSocketManager::addServer(const NetworkAddress& addr, port_t port) { // create the server socket and listen for incomming connections ... StreamSocketServer* srv = new StreamSocketServer(addr, port); srv->listen(); // create the socket listener and connect the write-signal for // accepting incomming connections ... SocketListener* listener = new SocketListener(*srv); listener->sigWrite.bind(make_method(this, &ServerSocketManager::slotConnected)); _servers.push_back(srv); _listeners.insert(std::make_pair(srv, listener)); } void ServerSocketManager::removeServer(const NetworkAddress& addr, port_t port) { //@fixme .. we need Socket::socketAddr() to implement this method } void ServerSocketManager::onConnect(StreamSocketServer& srv) { // left empty... } void ServerSocketManager::slotConnected(SocketListener& l) { StreamSocketServer& srv = (StreamSocketServer&)l.socket(); onConnect(srv); sigConnect.fire(srv); } } // !namespace Net } // !namespace P |