00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef __SOCKET_H_
00014 #define __SOCKET_H_
00015
00016 #include <inttypes.h>
00017 #include <string>
00018
00019 #define ASCII_MAX_LENGTH 255
00020
00021
00022 using namespace std;
00023
00027 class Socket
00028 {
00029 public:
00030 Socket();
00031
00035 virtual ~Socket() = 0;
00036
00042 int writeLine( string msg );
00043
00050 int writeLine( const char *msg );
00051
00058 bool startBinaryTransfer( int64_t length, int packetSize );
00059
00066 int readBinary( uint8_t *buffer, int maxlen );
00067
00074 int writeBinary( const uint8_t *buffer, int length );
00075
00081 virtual int readLine( string &msg ) = 0;
00082
00086 virtual void interrupt() = 0;
00087
00091 virtual void close();
00092
00093 protected:
00100 virtual int readBlock( void *buffer, int maxlen ) = 0;
00101
00108 virtual int writeBlock( const void *buffer, int length ) = 0;
00109
00110 private:
00116 int getTransferLength( int length );
00117
00127 int codec( uint8_t *&buffer, int &length, int transfer, bool enc );
00128
00129 int64_t binaryOffset, binaryLength;
00130 int binaryPacket, binaryIndex;
00131 uint8_t *binaryBuffer;
00132 };
00133
00134 #endif