Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1 | #ifndef T_SOCKET_H |
| 2 | #define T_SOCKET_H |
| 3 | |
| 4 | #include <string> |
| 5 | |
| 6 | #include "transport/TTransport.h" |
| 7 | #include "transport/TServerSocket.h" |
| 8 | |
| 9 | class TSocketOptions; |
| 10 | |
| 11 | /** |
| 12 | * TCP Socket implementation of the TTransport interface. |
| 13 | * |
| 14 | * @author Mark Slee <mcslee@facebook.com> |
| 15 | */ |
| 16 | class TSocket : public TTransport { |
| 17 | friend TTransport* TServerSocket::accept(); |
| 18 | |
| 19 | public: |
| 20 | TSocket(std::string host, int port); |
| 21 | ~TSocket(); |
| 22 | |
| 23 | bool open(); |
| 24 | void close(); |
| 25 | int read (std::string &s, uint32_t size); |
| 26 | void write(const std::string& s); |
| 27 | |
| 28 | bool setLinger(bool on, int linger); |
| 29 | bool setNoDelay(bool noDelay); |
| 30 | |
| 31 | private: |
| 32 | TSocket(int socket); |
| 33 | TSocketOptions *options_; |
| 34 | std::string host_; |
| 35 | int port_; |
| 36 | int socket_; |
| 37 | }; |
| 38 | |
| 39 | #endif |