InetTCPSlave.h

00001 /* Open SoundControl kit in C++                                              */
00002 /* Copyright (C) 2002-2004 libOSC++ contributors. See AUTHORS                */
00003 /*                                                                           */
00004 /* This library is free software; you can redistribute it and/or             */
00005 /* modify it under the terms of the GNU Lesser General Public                */
00006 /* License as published by the Free Software Foundation; either              */
00007 /* version 2.1 of the License, or (at your option) any later version.        */
00008 /*                                                                           */
00009 /* This library is distributed in the hope that it will be useful,           */
00010 /* but WITHOUT ANY WARRANTY; without even the implied warranty of            */
00011 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         */
00012 /* Lesser General Public License for more details.                           */
00013 /*                                                                           */
00014 /* You should have received a copy of the GNU Lesser General Public          */
00015 /* License along with this library; if not, write to the Free Software       */
00016 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
00017 /*                                                                           */
00018 /* For questions regarding this program contact                              */
00019 /* Daniel Holth <dholth@fastmail.fm> or visit                                */
00020 /* http://wiretap.stetson.edu/                                               */
00021 
00022 /*
00023  * This class was written by Martin Rumori (martin@rumori.de)
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 // this is defined in sys/socket.h, but we mustn't include that and winsock2
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,             // nothing to do
00186       GETTING_SIZE,     // reading the packet size
00187       GETTING_PACKET,   // reading the packet itself
00188       DROPPING_PACKET   // dropping a packet being too long
00189                         // (to regain 'sync' with data stream)
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

Generated on Thu Mar 2 23:51:35 2006 for libOSC++ by  doxygen 1.4.6