00001 /* 00002 mySocket, IncomingSocket 00003 Copyright (C) 2006 Kornel Csernai <csko@csko.hu> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 #include <IncomingSocket.h> 00020 #include <SocketHandler.h> 00021 #include <StringLib.h> 00022 00023 using namespace StringLib; 00024 00025 // Constructor 00026 IncomingSocket::IncomingSocket(socket_t _sock, struct sockaddr_in _saddr, 00027 ListenServer* _parent) : RealSocket(_sock){ 00028 saddr = _saddr; 00029 parent = _parent; 00030 00031 } 00032 00033 // Destructor 00034 IncomingSocket::~IncomingSocket(){ 00035 00036 // OnClose(); 00037 00038 } 00039 00040 // Get parent socket ID 00041 ListenServer* IncomingSocket::GetParent(){ 00042 00043 return parent; 00044 00045 } 00046 00047 // Called on socket close 00048 void IncomingSocket::OnClose(){ 00049 00050 __OnClose(); 00051 00052 } 00053 00054 00055 void IncomingSocket::Tellroom(string str){ 00056 00057 SocketHandler* handler = SocketHandler::getInstance(); 00058 if(!handler) throw SocketException(SOCKETHANDLING_FAILED); 00059 00060 Socket* sock; 00061 IncomingSocket* incoming; 00062 00063 for(int i=0; i < handler -> l_read -> size(); i++){ 00064 00065 sock = handler -> l_read -> get(i); 00066 incoming = dynamic_cast<IncomingSocket *>(sock); 00067 if(incoming -> GetParent() == GetParent()){ // Write on every valid child socket 00068 00069 incoming -> Write(str); 00070 00071 } 00072 } 00073 00074 } 00075