Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00024 #ifndef BASETCPSUPPORT_H_
00025 #define BASETCPSUPPORT_H_
00026
00027 #include <omnetpp.h>
00028 #include <map>
00029 #include <TransportAddress.h>
00030 #include <TCPSocket.h>
00031 #include <ExtTCPSocketMap.h>
00032
00033 class BaseTcpSupport : public TCPSocket::CallbackInterface
00034 {
00035 public:
00036
00037
00038 enum EvCode {NO_EST_CONNECTION, PEER_CLOSED, PEER_TIMEDOUT, PEER_REFUSED, CONNECTION_RESET, CONNECTION_SUCC_ClOSED};
00039
00040
00041 virtual void socketDataArrived(int connId, void *yourPtr, cPacket *msg, bool urgent);
00042 virtual void socketEstablished(int connId, void *yourPtr);
00043 virtual void socketPeerClosed(int connId, void *yourPtr);
00044
00045 virtual void socketFailure(int connId, void *yourPtr, int code);
00046 virtual void socketStatusArrived(int connId, void *yourPtr, TCPStatusInfo *status) {delete status;}
00047
00048 protected:
00049
00053 void handleTCPMessage(cMessage* msg);
00054
00060 void bindAndListenTcp(int port);
00061
00067 bool isAlreadyConnected(TransportAddress address);
00068
00074 void establishTcpConnection(TransportAddress address);
00075
00082 void sendTcpData(cPacket* msg, TransportAddress address);
00083
00090 virtual void handleConnectionEvent(EvCode code, TransportAddress address);
00091
00099 virtual void handleDataReceived(TransportAddress address, cPacket* msg, bool urgent);
00100
00106 virtual void handleIncomingConnection(TransportAddress address);
00107
00113 void closeTcpConnection(TransportAddress address);
00114
00120 void setTcpOut(cGate* gate) {tcpOut = gate;}
00121
00127 cGate* getTcpOut() {return tcpOut;}
00128
00129 private:
00130
00131 ExtTCPSocketMap sockets;
00132 typedef std::vector<cMessage*> msgQueue;
00133 typedef std::map<TransportAddress, msgQueue*> transQueue;
00134 transQueue queuedTx;
00135
00136 cGate* tcpOut;
00137 };
00138
00139 #endif