tcpport.h
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
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef __TCPPORT_H
00030 #define __TCPPORT_H
00031
00032 #include <flexiport/port.h>
00033
00034 #include <map>
00035 #include <string>
00036
00041 namespace flexiport
00042 {
00043
00061 class FLEXIPORT_EXPORT TCPPort : public Port
00062 {
00063 public:
00064 TCPPort (std::map<std::string, std::string> options);
00065 ~TCPPort ();
00066
00072 void Open ();
00074 void Close ();
00076 ssize_t Read (void * const buffer, size_t count);
00078 ssize_t ReadFull (void * const buffer, size_t count);
00080 ssize_t BytesAvailable ();
00082 ssize_t BytesAvailableWait ();
00084 ssize_t Write (const void * const buffer, size_t count);
00086 void Flush ();
00088 void Drain ();
00090 std::string GetStatus () const;
00092 void SetTimeout (Timeout timeout);
00094 void SetCanRead (bool canRead);
00096 void SetCanWrite (bool canWrite);
00098 bool IsOpen () const { return _open; }
00099
00100 private:
00101 int _sock;
00102 int _listenSock;
00103
00104 std::string _ip;
00105 unsigned int _port;
00106 bool _isListener;
00107 bool _open;
00108
00109 void CheckPort (bool read);
00110
00111 bool ProcessOption (const std::string &option, const std::string &value);
00112
00113 void Connect ();
00114 void WaitForConnection ();
00115 typedef enum {TIMED_OUT, DATA_AVAILABLE, CAN_WRITE} WaitStatus;
00116 WaitStatus WaitForDataOrTimeout ();
00117 bool IsDataAvailable ();
00118 WaitStatus WaitForWritableOrTimeout ();
00119 void SetSocketBlockingFlag ();
00120 };
00121
00122 }
00123
00126 #endif // __TCPPORT_H
00127