00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef CERTI_SOCKET_TCP_HH
00021 #define CERTI_SOCKET_TCP_HH
00022
00023 #include "Socket.hh"
00024 #include "certi.hh"
00025
00026 #ifndef _WIN32
00027 #include <sys/socket.h>
00028 #include <netinet/in.h>
00029 #endif
00030
00031
00032
00033
00034
00035
00036 namespace certi {
00037
00048 class CERTI_EXPORT SocketTCP : public Socket
00049 {
00050 public :
00051 SocketTCP();
00052 virtual ~SocketTCP();
00053 virtual void close();
00054
00055 virtual void createConnection(const char *server_name, unsigned int port)
00056 throw (NetworkError);
00057 void createTCPClient(in_port_t port, in_addr_t addr) throw (NetworkError);
00058 void createTCPServer(in_port_t port = 0, in_addr_t addr = INADDR_ANY) throw (NetworkError);
00059
00060 int accept(SocketTCP *serveur) throw (NetworkError);
00061 virtual void send(const unsigned char *, size_t) throw (NetworkError, NetworkSignal);
00062 virtual void receive(void *Buffer, unsigned long Size) throw (NetworkError, NetworkSignal);
00063
00064 virtual bool isDataReady() const ;
00065
00066 virtual unsigned long returnAdress() const ;
00067
00068 SocketTCP &operator=(SocketTCP &theSocket);
00069
00070 #ifdef _WIN32
00071 SOCKET returnSocket();
00072 static bool winsockStartup();
00073 static void winsockShutdown();
00074 static bool winsockInitialized() { return (winsockInits > 0);}
00075 #else
00076 virtual int returnSocket() ;
00077 #endif
00078
00079 protected:
00080 int timeoutTCP(int, int);
00081
00082 ByteCount_t SentBytesCount;
00083 ByteCount_t RcvdBytesCount;
00084
00085 private:
00086 int open();
00087 int connect(in_port_t port, in_addr_t addr);
00088 int listen(unsigned long howMuch=5);
00089 int bind(in_port_t port=0, in_addr_t addr=INADDR_ANY);
00090 void setPort(in_port_t port);
00091 in_port_t getPort() const ;
00092 in_addr_t getAddr() const ;
00093
00094 #ifdef _WIN32
00095 SOCKET _socket_tcp;
00096 static int winsockInits;
00097 #else
00098 long _socket_tcp;
00099 #endif
00100 bool _est_init_tcp;
00101 struct sockaddr_in _sockIn;
00102
00103 #ifdef SOCKTCP_BUFFER_LENGTH
00104
00105
00106
00107 char ReadBuffer[SOCKTCP_BUFFER_LENGTH] ;
00108 unsigned long RBLength ;
00109 #endif
00110 };
00111
00112 }
00113
00114 #endif // CERTI_SOCKET_TCP_HH