00001 /* NewNet - A networking framework in C++ 00002 Copyright (C) 2006 Ingmar K. Steen (iksteen@gmail.com) 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 */ 00019 00020 #include "nnserversocket.h" 00021 #include "nnlog.h" 00022 #include "platform.h" 00023 #include <iostream> 00024 00025 void 00026 NewNet::ServerSocket::disconnect() 00027 { 00028 if((descriptor() == -1) || (socketState() != SocketListening)) 00029 { 00030 NNLOG("newnet.net.warn", "Trying to disconnect an uninitialized server socket."); 00031 return; 00032 } 00033 00034 close(descriptor()); 00035 setSocketState(SocketDisconnected); 00036 disconnectedEvent(this); 00037 } 00038 00039 void 00040 NewNet::ServerSocket::process() 00041 { 00042 if(readyState() & StateReceive) 00043 { 00044 int client = ::accept(descriptor(), 0, 0); 00045 if(client == -1) 00046 { 00047 #ifndef WIN32 00048 if(errno == EAGAIN) 00049 #else 00050 if(WSAGetLastError() == EAGAIN) 00051 #endif // ! WIN32 00052 setReadyState(readyState() & ~StateReceive); 00053 else 00054 NNLOG("newnet.net.warn", "Ignoring error '%i' in ServerSocket::accept().", errno); 00055 } 00056 else 00057 acceptedEvent(client); 00058 } 00059 }
1.5.1