00001
00002 #ifndef SENDS_SOCKET_API_HH
00003 #define SENDS_SOCKET_API_HH
00004
00005 #include <string>
00006
00007 namespace sends {
00008
00015 class socket_api {
00016 public:
00019 enum sock_err {
00020 serr_OK = 0,
00021 serr_failure,
00022 serr_retry,
00023 serr_internal
00024 };
00025
00026 public:
00030 socket_api(void);
00031
00035 virtual ~socket_api(void);
00036
00042 virtual socket_api* accept(void) = 0;
00043
00051 virtual sock_err bind(const std::string& addr) = 0;
00052
00057 virtual sock_err close(void) = 0;
00058
00064 virtual sock_err connect(const std::string& s) = 0;
00065
00070 sock_err error(void) const;
00071
00080 virtual long gets(char* buf, long len, char term='\n');
00081
00087 virtual sock_err handshake(void);
00088
00096 virtual sock_err listen(const std::string& port, int lq) = 0;
00097
00106 static sock_err parse_addr(const std::string& addr, unsigned int& node,
00107 unsigned short& port);
00108
00111 const char* peer_name(void) const;
00112
00119 virtual long read(char* buf, long len);
00120
00128 virtual long read_available(char* buf, long len) = 0;
00129
00134 void set_error(sock_err err);
00135
00140 sock_err set_error(void);
00141
00147 void set_verbose(int verb);
00148
00154 virtual int socket_id(void) const = 0;
00155
00161 int verbose(void) const;
00162
00169 virtual long write(const char* buf, long len) = 0;
00170
00180 virtual int wait_data(double nsec);
00181
00182 protected:
00184 sock_err mError;
00186 int mVerbose;
00188 std::string mPeer;
00189 };
00190
00191
00192 inline socket_api::sock_err
00193 socket_api::error(void) const {
00194 return mError;
00195 }
00196
00197 inline const char*
00198 socket_api::peer_name(void) const {
00199 return mPeer.c_str();
00200 }
00201
00202 inline int
00203 socket_api::verbose(void) const {
00204 return mVerbose;
00205 }
00206
00207 }
00208
00209 #endif // !defined(SENDS_SOCKET_API_HH)