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
00019 #ifndef __INET_TCPSOCKET_H
00020 #define __INET_TCPSOCKET_H
00021
00022 #include <omnetpp.h>
00023 #include "TCPCommand_m.h"
00024 #include "IPvXAddress.h"
00025
00026 class TCPStatusInfo;
00027
00028
00123 class INET_API TCPSocket
00124 {
00125 public:
00134 class CallbackInterface
00135 {
00136 public:
00137 virtual ~CallbackInterface() {}
00138 virtual void socketDataArrived(int connId, void *yourPtr, cPacket *msg, bool urgent) = 0;
00139 virtual void socketEstablished(int connId, void *yourPtr) {}
00140 virtual void socketPeerClosed(int connId, void *yourPtr) {}
00141 virtual void socketClosed(int connId, void *yourPtr) {}
00142 virtual void socketFailure(int connId, void *yourPtr, int code) {}
00143 virtual void socketStatusArrived(int connId, void *yourPtr, TCPStatusInfo *status) {delete status;}
00144 };
00145
00146 enum State {NOT_BOUND, BOUND, LISTENING, CONNECTING, CONNECTED, PEER_CLOSED, LOCALLY_CLOSED, CLOSED, SOCKERROR};
00147
00148 protected:
00149 int connId;
00150 int sockstate;
00151
00152 IPvXAddress localAddr;
00153 int localPrt;
00154 IPvXAddress remoteAddr;
00155 int remotePrt;
00156
00157 CallbackInterface *cb;
00158 void *yourPtr;
00159
00160 cGate *gateToTcp;
00161
00162 std::string sendQueueClass;
00163 std::string receiveQueueClass;
00164 std::string tcpAlgorithmClass;
00165
00166
00167 protected:
00168 void sendToTCP(cMessage *msg);
00169
00170
00171 void listen(bool fork);
00172
00173 public:
00178 TCPSocket();
00179
00185 TCPSocket(cMessage *msg);
00186
00190 ~TCPSocket() {}
00191
00197 int getConnectionId() const {return connId;}
00198
00204 int getState() {return sockstate;}
00205
00209 static const char *stateName(int state);
00210
00213 IPvXAddress getLocalAddress() {return localAddr;}
00214 int getLocalPort() {return localPrt;}
00215 IPvXAddress getRemoteAddress() {return remoteAddr;}
00216 int getRemotePort() {return remotePrt;}
00218
00221
00226 void setOutputGate(cGate *toTcp) {gateToTcp = toTcp;}
00227
00231 void bind(int localPort);
00232
00237 void bind(IPvXAddress localAddr, int localPort);
00238
00242 const char *getSendQueueClass() const {return sendQueueClass.c_str();}
00243
00247 const char *getReceiveQueueClass() const {return receiveQueueClass.c_str();}
00248
00252 const char *getTCPAlgorithmClass() const {return tcpAlgorithmClass.c_str();}
00253
00257 void setSendQueueClass(const char *sendQueueClass) { this->sendQueueClass = sendQueueClass; }
00258
00262 void setReceiveQueueClass(const char *receiveQueueClass) { this->receiveQueueClass = receiveQueueClass; }
00263
00267 void setTCPAlgorithmClass(const char *tcpAlgorithmClass) { this->tcpAlgorithmClass = tcpAlgorithmClass; }
00268
00281 void listen() {listen(true);}
00282
00290 void listenOnce() {listen(false);}
00291
00295 void connect(IPvXAddress remoteAddr, int remotePort);
00296
00300 void send(cMessage *msg);
00301
00308 void close();
00309
00313 void abort();
00314
00322 void requestStatus();
00323
00341 void renewSocket();
00343
00351 bool belongsToSocket(cMessage *msg);
00352
00358 static bool belongsToAnyTCPSocket(cMessage *msg);
00359
00381 void setCallbackObject(CallbackInterface *cb, void *yourPtr=NULL);
00382
00399 void processMessage(cMessage *msg);
00401 };
00402
00403 #endif
00404
00405