TCP.h

Go to the documentation of this file.
00001 
00002 //written by Luke Lenhart, 2008
00003 //See /docs/License.txt for details on how this code may be used.
00004 
00005 #pragma once
00006 
00007 #include "Common.h"
00008 #include <vector>
00009 
00010 class MPMAMemoryManager; //FD
00011 
00012 namespace NET
00013 {
00015     class TCPClient
00016     {
00017     public:
00019         static TCPClient* Connect(const Address &addr, uint16 localPort=0);
00020 
00022         static void FreeClient(TCPClient *client);
00023 
00025         bool IsConnected() const;
00026 
00028         bool Send(const void *data, uint dataLen);
00029 
00031         uint Receive(std::vector<uint8> &data, uint exactBytesToRetrieve=0);
00032 
00034         inline uint16 GetLocalPort() const { return port; }
00035 
00037         inline const Address& GetRemoteAddress() const { return remoteAddr; }
00038 
00040         void EnableSendCoalescing(bool allow);
00041 
00042         //TODO: Some sort of callback mechanism for notifications.
00043 
00044     private:
00045         //we are the only allocator
00046         TCPClient();
00047         inline ~TCPClient() {}
00048         inline TCPClient(const TCPClient&) {}
00049         inline void operator=(const TCPClient&) {}
00050         friend class ::MPMAMemoryManager;
00051         friend class TCPServer;
00052 
00053         //
00054         Address remoteAddr;
00055         uint16 port;
00056         int sock;
00057         mutable bool connected;
00058         std::vector<uint8> bufferedBytes;
00059     };
00060 
00062     class TCPServer
00063     {
00064     public:
00066         static TCPServer* Listen(uint16 port, bool openNatAutomatically=true);
00067 
00069         static void FreeServer(TCPServer *server);
00070 
00072         TCPClient* GetNextConnection();
00073 
00075         inline uint16 GetListenPort() const { return port; }
00076 
00077         //TODO: Some sort of callback mechanism for notifications.
00078 
00079     private:
00080         //we are the only allocator
00081         TCPServer();
00082         inline ~TCPServer() {}
00083         inline TCPServer(const TCPServer&) {}
00084         inline void operator=(const TCPServer&) {}
00085         friend class ::MPMAMemoryManager;
00086 
00087         //
00088         int sock;
00089         uint16 port;
00090         bool autoUPNP;
00091     };
00092 }

Generated on Sat Aug 9 15:05:05 2008 for MPMA Framework by  doxygen 1.5.6