Candidate_v1.7.0
        stable
      
      
      
| Rev | Line |   | 
|---|
| [0b990d] | 1 | #ifdef __GNUG__
 | 
|---|
 | 2 | #pragma interface
 | 
|---|
 | 3 | #endif
 | 
|---|
 | 4 | 
 | 
|---|
 | 5 | #ifndef _socket_h
 | 
|---|
 | 6 | #define _socket_h
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | #include <unistd.h>
 | 
|---|
 | 9 | #include <sys/types.h>
 | 
|---|
 | 10 | 
 | 
|---|
 | 11 | #include <string>
 | 
|---|
 | 12 | 
 | 
|---|
 | 13 | class TCPSocket {
 | 
|---|
 | 14 |   protected:
 | 
|---|
 | 15 |     TCPSocket();
 | 
|---|
 | 16 |     virtual ~TCPSocket();
 | 
|---|
 | 17 | 
 | 
|---|
 | 18 |     int socket_;
 | 
|---|
 | 19 |     int port_;
 | 
|---|
 | 20 |     bool initialized_;
 | 
|---|
 | 21 |     bool bound_;
 | 
|---|
 | 22 | 
 | 
|---|
 | 23 |   public:
 | 
|---|
 | 24 |     void create();
 | 
|---|
 | 25 |     void bind(u_int16_t port_begin, u_int16_t port_fence);
 | 
|---|
 | 26 |     int port() { return port_; }
 | 
|---|
 | 27 |     u_int32_t addr();
 | 
|---|
 | 28 | 
 | 
|---|
 | 29 |     bool initialized() { return initialized_; }
 | 
|---|
 | 30 |     bool bound() { return bound_; }
 | 
|---|
 | 31 | 
 | 
|---|
 | 32 |     virtual void close();
 | 
|---|
 | 33 | };
 | 
|---|
 | 34 | 
 | 
|---|
 | 35 | class TCPIOSocket: public TCPSocket {
 | 
|---|
 | 36 |   public:
 | 
|---|
 | 37 |     int read(void *d, int n);
 | 
|---|
 | 38 |     int write(const void *d, int n);
 | 
|---|
 | 39 |     int read_int(int *d, int n) {return read((void*)d,n*sizeof(int));}
 | 
|---|
 | 40 |     int write_int(const int *d, int n) {return write((void*)d,n*sizeof(int));}
 | 
|---|
 | 41 |     int read_string(std::string &);
 | 
|---|
 | 42 |     int write_string(const std::string &);
 | 
|---|
 | 43 |     int read_int(int &);
 | 
|---|
 | 44 |     int write_int(int);
 | 
|---|
 | 45 |     int read_uint32(u_int32_t &);
 | 
|---|
 | 46 |     int write_uint32(u_int32_t);
 | 
|---|
 | 47 | };
 | 
|---|
 | 48 | 
 | 
|---|
 | 49 | class TCPServerSocket: public TCPSocket {
 | 
|---|
 | 50 |     friend class TCPServerConnection;
 | 
|---|
 | 51 |   public:
 | 
|---|
 | 52 |     void listen(int queue_length = 8);
 | 
|---|
 | 53 | };
 | 
|---|
 | 54 | 
 | 
|---|
 | 55 | class TCPServerConnection: public TCPIOSocket {
 | 
|---|
 | 56 |   public:
 | 
|---|
 | 57 |     void accept(const TCPServerSocket &);
 | 
|---|
 | 58 | };
 | 
|---|
 | 59 | 
 | 
|---|
 | 60 | class TCPClientConnection: public TCPIOSocket {
 | 
|---|
 | 61 |     bool connected_;
 | 
|---|
 | 62 |   public:
 | 
|---|
 | 63 |     TCPClientConnection();
 | 
|---|
 | 64 |     void close();
 | 
|---|
 | 65 |     bool connected() { return connected_; }
 | 
|---|
 | 66 |     void connect(const char *remote_hostname, u_int16_t remote_port);
 | 
|---|
 | 67 |     void connect(u_int32_t remote_host, u_int16_t remote_port);
 | 
|---|
 | 68 | };
 | 
|---|
 | 69 | 
 | 
|---|
 | 70 | #endif
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.