udpport.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 __UDPPORT_H
00030 #define __UDPPORT_H
00031
00032 #include <flexiport/port.h>
00033 #include <flexiport/config.h>
00034
00035 #include <map>
00036 #include <string>
00037 #if !defined (WIN32)
00038 #include <netinet/in.h>
00039 #endif
00040
00045 namespace flexiport
00046 {
00047
00083 class FLEXIPORT_EXPORT UDPPort : public Port
00084 {
00085 public:
00086 UDPPort (std::map<std::string, std::string> options);
00087 ~UDPPort ();
00088
00092 void Open ();
00094 void Close ();
00096 ssize_t Read (void * const buffer, size_t count);
00098 ssize_t ReadFull (void * const buffer, size_t count);
00100 ssize_t ReadUntil (void * const buffer, size_t count, uint8_t terminator);
00102 ssize_t ReadStringUntil (std::string &buffer, char terminator);
00104 ssize_t Skip (size_t count);
00107 ssize_t SkipUntil (uint8_t terminator, unsigned int count);
00109 ssize_t BytesAvailable ();
00111 ssize_t BytesAvailableWait ();
00113 ssize_t Write (const void * const buffer, size_t count);
00115 void Flush ();
00117 void Drain ();
00119 std::string GetStatus () const;
00121 void SetTimeout (Timeout timeout);
00123 void SetCanRead (bool canRead);
00125 void SetCanWrite (bool canWrite);
00127 bool IsOpen () const { return _open; }
00128
00129 private:
00130 #if !defined (WIN32)
00131 #if defined (FLEXIPORT_HAVE_GETADDRINFO)
00132 struct sockaddr _destSockAddr;
00133 #else
00134 struct sockaddr_in _destSockAddr;
00135 #endif
00136 #endif // !defined (WIN32)
00137 int _sendSock;
00138 int _recvSock;
00139
00140 std::string _destIP;
00141 unsigned int _destPort;
00142 std::string _recvIP;
00143 unsigned int _recvPort;
00144 bool _open;
00145
00146 void CheckPort (bool read);
00147
00148 bool ProcessOption (const std::string &option, const std::string &value);
00149
00150 void OpenSender ();
00151 void CloseSender ();
00152 void OpenReceiver ();
00153 void CloseReceiver ();
00154 typedef enum {TIMED_OUT, DATA_AVAILABLE, CAN_WRITE} WaitStatus;
00155 WaitStatus WaitForDataOrTimeout ();
00156 bool IsDataAvailable ();
00157 WaitStatus WaitForWritableOrTimeout ();
00158 void SetSocketBlockingFlag ();
00159 };
00160
00161 }
00162
00165 #endif // __UDPPORT_H
00166