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 #ifndef LIBOSC_INETTCPSLAVE_H
00027 #define LIBOSC_INETTCPSLAVE_H
00028
00029 #include "InetTransport.h"
00030 #include "InetTCPMaster.h"
00031
00032 #include <errno.h>
00033
00034 #ifdef __CYGWIN__
00035 #include <w32api/winsock2.h>
00036 #include <w32api/ws2tcpip.h>
00037 #include <poll.h>
00038
00039 #define SHUT_RDWR 2
00040 #else // __CYGWIN__
00041 #include <sys/types.h>
00042 #include <sys/socket.h>
00043 #include <sys/poll.h>
00044 #include <netinet/in.h>
00045 #include <arpa/inet.h>
00046 #endif // __CYGWIN__
00047
00048
00058 class InetTCPSlave : public InetTransport
00059 {
00060
00061 friend class InetTCPMaster;
00062
00063 public:
00070 InetTCPSlave (InetTCPMaster *tcpMaster,
00071 InetOSCAddrType addrType,
00072 int socket,
00073 struct sockaddr *remoteAddr);
00074
00076 virtual ~InetTCPSlave ();
00077
00082 bool handle ();
00083
00090 bool transmit(const std::string& data);
00091
00096 const int getHandle () const;
00097
00107 bool disconnect ();
00108
00113 const struct sockaddr *const getRemoteAddr () const;
00114
00119 const std::string getRemoteHost () const;
00120
00125 const int getRemotePort () const;
00126
00131 const bool isConnected () const;
00132
00138 const bool isWriteBlocking () const;
00139
00148 void setWriteBlocking (bool writeblock = true);
00149
00154 const std::string getStatusString (void);
00155
00160 virtual std::string getName();
00161
00162
00163 protected:
00164
00177 bool justDisconnect ();
00178
00179
00180 private:
00181
00183 typedef enum
00184 {
00185 IDLE,
00186 GETTING_SIZE,
00187 GETTING_PACKET,
00188 DROPPING_PACKET
00189
00190 } InetTCPSlaveState;
00191
00193 bool _connected;
00194
00196 bool _writeblock;
00197
00199 InetTCPSlaveState _rstate;
00200
00202 std::string _rbuf;
00203
00205 uint32_t _rsize;
00206
00208 uint32_t _gotbytes;
00209
00211 InetTCPMaster *const _tcpMaster;
00212
00214 const struct sockaddr *_remoteAddr;
00215
00216 };
00217
00218 #endif // #ifndef LIBOSC_INETTCPSLAVE_H