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 #ifndef TCPCLIENTSTREAM_H
00028 #define TCPCLIENTSTREAM_H
00029
00030 #include <poll.h>
00031 #include <unistd.h>
00032 #include <stdlib.h>
00033
00034 #include "Stream.h"
00035 #include "Address.h"
00036 #include "GpCoreToolsDLLExport.h"
00037
00038 namespace GpCoreTools {
00039
00040 class DynamicBuffer;
00041
00042 class GPCORETOOLS_EXPORT TcpClientStream : public Stream
00043 {
00044 public:
00045 TcpClientStream(int fileDescriptor, const Address& peer);
00046 TcpClientStream(const Address& peer);
00047 virtual ~TcpClientStream();
00048
00049 virtual bool connect(uint16_t port);
00050
00051 virtual short eventTypes() {return POLLIN | POLLRDHUP;}
00052 virtual void event(short type);
00053 virtual void hungUp() {}
00054
00055 const Address& peer() const {return _peer;}
00056 DynamicBuffer * buffer() const {return _buffer;}
00057
00058 bool writePartial(const char * bytes, int byteCount) const {
00059 return ::send(fileDescriptor(), bytes, byteCount, MSG_MORE)==byteCount;
00060 }
00061 bool writePartialNoGateway(const char * bytes, int byteCount) const {
00062 return ::send(fileDescriptor(), bytes, byteCount, MSG_DONTROUTE | MSG_MORE)==byteCount;
00063 }
00064 bool write(const char * bytes, int byteCount) const {
00065 return ::write(fileDescriptor(), bytes, byteCount)==byteCount;
00066 }
00067 bool writeNoGateway(const char * bytes, int byteCount) const {
00068 return ::send(fileDescriptor(), bytes, byteCount, MSG_DONTROUTE)==byteCount;
00069 }
00070 protected:
00071 void setBuffer(DynamicBuffer * buffer) {_buffer=buffer;}
00072 private:
00073 Address _peer;
00074 DynamicBuffer * _buffer;
00075 };
00076
00077 }
00078
00079 #endif // TCPCLIENTSTREAM_H