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 MemMan; //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         bool Receive(std::vector<uint8> &data);
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 ::MemMan;
00051         friend class TCPServer;
00052 
00053         //
00054         Address remoteAddr;
00055         uint16 port;
00056         int sock;
00057         mutable bool connected;
00058     };
00059 
00061     class TCPServer
00062     {
00063     public:
00065         static TCPServer* Listen(uint16 port);
00066 
00068         static void FreeServer(TCPServer *server);
00069 
00071         TCPClient* GetNextConnection();
00072 
00074         inline uint16 GetListenPort() const { return port; }
00075 
00076         //TODO: Some sort of callback mechanism for notifications.
00077 
00078     private:
00079         //we are the only allocator
00080         TCPServer();
00081         inline ~TCPServer() {}
00082         inline TCPServer(const TCPServer&) {}
00083         inline void operator=(const TCPServer&) {}
00084         friend class ::MemMan;
00085 
00086         //
00087         int sock;
00088         uint16 port;
00089     };
00090 }

Generated on Wed Feb 13 20:57:04 2008 for MPMA Framework by  doxygen 1.5.4