NetServerTCP2Destination.h

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #if !defined(__INCLUDE_NetServerTCP2Destinationh_INCLUDE__)
00022 #define __INCLUDE_NetServerTCP2Destinationh_INCLUDE__
00023 
00024 #include <net/NetInterface.h>
00025 #include <list>
00026 #include <map>
00027 
00028 class NetServerTCP2;
00029 class NetServerTCP2Destination : public NetMessageHandlerI
00030 {
00031 public:
00032         NetServerTCP2Destination(NetMessageHandler *incomingMessageHandler,
00033                 TCPsocket socket, unsigned int destinationId);
00034         virtual ~NetServerTCP2Destination();
00035 
00036         void printStats(unsigned int destinationId);
00037         void stop() { stopped_ = true; }
00038         bool finished() { return finished_; }
00039 
00040         unsigned int getIpAddress();
00041         static unsigned int getIpAddressFromSocket(TCPsocket socket);
00042 
00043         void addMessage(NetMessage *message) 
00044         {
00045                 outgoingMessageHandler_.addMessage(message);
00046         }
00047 
00048         // NetMessageHandlerI
00049         virtual void processMessage(NetMessage &message);
00050 
00051 protected:
00052         enum HeaderType
00053         {
00054                 TypeNone = 0,
00055                 TypeMessage = 1,
00056                 TypeLast = 4
00057         };
00058 
00059         bool packetLogging_;
00060         unsigned int destinationId_;
00061         SDL_Thread *sendRecvThread_;
00062         TCPsocket socket_;
00063         SDLNet_SocketSet socketSet_;
00064         NetBuffer currentMessagePart_;
00065         NetMessage *currentMessage_;
00066         int currentMessageLen_;
00067         char currentMessageType_;
00068         int currentMessageSentLen_;
00069         unsigned int messagesSent_, messagesRecieved_;
00070         unsigned int bytesIn_, bytesOut_;
00071         bool stopped_, finished_;
00072         NetMessageHandler outgoingMessageHandler_;
00073         NetMessageHandler *incomingMessageHandler_;
00074         std::list<NetMessage *> outgoingMessages_;
00075 
00076         enum SocketResult
00077         {
00078                 SocketActivity,
00079                 SocketEmpty,
00080                 SocketClosed
00081         };
00082         SocketResult checkIncoming();
00083         SocketResult checkOutgoing();
00084 
00085         static int sendRecvThreadFunc(void *c);
00086         void actualSendRecvFunc();
00087         bool sendHeader(char headerType, int len);
00088 };
00089 
00090 #endif // __INCLUDE_NetServerTCP2Destinationh_INCLUDE__

Generated on Mon Feb 16 15:14:51 2009 for Scorched3D by  doxygen 1.5.3