All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Public Member Functions | Protected Member Functions
GpCoreTools::TcpClientStream Class Reference

Brief description of class still missing. More...

#include <TcpClientStream.h>

Inheritance diagram for GpCoreTools::TcpClientStream:
GpCoreTools::Stream CrystalfontzStream CubeTcpStream GpCoreTools::ScreenClient GpsStream LinkStream MasterStream NetClient SystemClient TimeMasterStream TimeSlaveStream

List of all members.

Public Member Functions

DynamicBufferbuffer () const
virtual bool connect (uint16_t port)
virtual void event (short type)
virtual short eventTypes ()
virtual void hungUp ()
const Addresspeer () const
 TcpClientStream (int fileDescriptor, const Address &peer)
 TcpClientStream (const Address &peer)
bool write (const char *bytes, int byteCount) const
bool writeNoGateway (const char *bytes, int byteCount) const
bool writePartial (const char *bytes, int byteCount) const
bool writePartialNoGateway (const char *bytes, int byteCount) const
virtual ~TcpClientStream ()

Protected Member Functions

void setBuffer (DynamicBuffer *buffer)

Detailed Description

Brief description of class still missing.

Full description of class still missing


Constructor & Destructor Documentation

GpCoreTools::TcpClientStream::TcpClientStream ( int  fileDescriptor,
const Address peer 
)

Description of constructor still missing

References peer(), GpCoreTools::Stream::setFileDescriptor(), and TRACE.

    : Stream()
{
  TRACE;
  setFileDescriptor(fileDescriptor);
  _peer=peer;
  _buffer=0;
}

Description of constructor still missing

References GpCoreTools::Stream::fileDescriptor(), peer(), GpCoreTools::Stream::setFileDescriptor(), TRACE, and write().

{
  TRACE;
  setFileDescriptor(socket(AF_INET, SOCK_STREAM, 0));
  if(fileDescriptor()<=0) {
    Log::write(0, "%s\n", strerror(errno));
  }
  _peer=peer;
  _buffer=0;
}

References TRACE.

{
  TRACE;
  delete _buffer;
}

Member Function Documentation

bool GpCoreTools::TcpClientStream::connect ( uint16_t  port) [virtual]

Reimplemented in LinkStream.

References GpCoreTools::Stream::fileDescriptor(), GpCoreTools::Address::toString(), TRACE, GpCoreTools::Address::value(), and write().

Referenced by GpCoreTools::ScreenClient::connect(), and TimeRequest::exec().

{
  TRACE;
  sockaddr_in addr;
  addr.sin_family=AF_INET;
  addr.sin_port=htons(port);
  addr.sin_addr.s_addr=_peer.value();
  Log::write(1, "connecting to %s:%hu (socket %i)\n", _peer.toString().data(), port, fileDescriptor());
  if(::connect(fileDescriptor(), (sockaddr *)&addr, sizeof(sockaddr_in))<0) {
    Log::write(1, "%s\n", strerror(errno));
    return false;
  } else {
    Log::write(1, "connected to %s:%hu (socket %i)\n", inet_ntoa(addr.sin_addr), port, fileDescriptor());
    return true;
  }
}
void GpCoreTools::TcpClientStream::event ( short  type) [virtual]

Implements GpCoreTools::Stream.

References GpCoreTools::Stream::close(), GpCoreTools::Stream::fileDescriptor(), hungUp(), GpCoreTools::DynamicBuffer::read(), GpCoreTools::Address::toString(), TRACE, and write().

{
  TRACE;
  if(type & POLLIN) {
    if(_buffer) {
      if(!_buffer->read()) {
        Log::write(1, "error reading data from %s (socket %i)\n",
                   _peer.toString().data(), fileDescriptor());
      }
    }
  }
  if(type & POLLRDHUP) {
    Log::write(1, "connection hung up with %s (socket %i)\n",
               _peer.toString().data(), fileDescriptor());
    close();
    hungUp();
  }
}
virtual short GpCoreTools::TcpClientStream::eventTypes ( ) [inline, virtual]

Implements GpCoreTools::Stream.

{return POLLIN | POLLRDHUP;}
virtual void GpCoreTools::TcpClientStream::hungUp ( ) [inline, virtual]

Reimplemented in MasterStream, LinkStream, GpCoreTools::ScreenClient, and TimeSlaveStream.

Referenced by event().

{}
const Address& GpCoreTools::TcpClientStream::peer ( ) const [inline]

Referenced by LinkStream::connect(), LinkStream::hungUp(), and TcpClientStream().

{return _peer;}
void GpCoreTools::TcpClientStream::setBuffer ( DynamicBuffer buffer) [inline, protected]
bool GpCoreTools::TcpClientStream::write ( const char *  bytes,
int  byteCount 
) const [inline]

Referenced by connect(), event(), TimeRequest::exec(), and TcpClientStream().

                                                      {
    return ::write(fileDescriptor(), bytes, byteCount)==byteCount;
  }
bool GpCoreTools::TcpClientStream::writeNoGateway ( const char *  bytes,
int  byteCount 
) const [inline]

Referenced by PeerTracker::addFromMasterRoute(), and PeerTracker::removeFromMasterRoute().

                                                               {
    return ::send(fileDescriptor(), bytes, byteCount, MSG_DONTROUTE)==byteCount;
  }
bool GpCoreTools::TcpClientStream::writePartial ( const char *  bytes,
int  byteCount 
) const [inline]

Referenced by GpCoreTools::ScreenClient::write().

                                                             {
    return ::send(fileDescriptor(), bytes, byteCount, MSG_MORE)==byteCount;
  }
bool GpCoreTools::TcpClientStream::writePartialNoGateway ( const char *  bytes,
int  byteCount 
) const [inline]

Referenced by PeerTracker::addFromMasterRoute(), and PeerTracker::removeFromMasterRoute().

                                                                      {
    return ::send(fileDescriptor(), bytes, byteCount, MSG_DONTROUTE | MSG_MORE)==byteCount;
  }

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines