reSIProcate/stack  9694
Public Member Functions | Private Member Functions
resip::TcpConnection Class Reference

#include <TcpConnection.hxx>

Inheritance diagram for resip::TcpConnection:
Inheritance graph
[legend]
Collaboration diagram for resip::TcpConnection:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 TcpConnection (Transport *transport, const Tuple &who, Socket fd, Compression &compression)
int read (char *buf, const int count)
 pure virtual, but need concrete Connection for book-ends of lists
int write (const char *buf, const int count)
 pure virtual, but need concrete Connection for book-ends of lists
virtual bool hasDataToRead ()
 always true -- always add to fdset as read ready
virtual bool isGood ()
 has valid connection
virtual bool isWritable ()
Data peerName ()

Private Member Functions

 TcpConnection ()
 No default c'tor.

Detailed Description

Definition at line 11 of file TcpConnection.hxx.


Constructor & Destructor Documentation

TcpConnection::TcpConnection ( Transport transport,
const Tuple who,
Socket  fd,
Compression compression 
)

Definition at line 14 of file TcpConnection.cxx.

References DebugLog.

  : Connection(transport,who, fd, compression)
{
   DebugLog (<< "Creating TCP connection " << who << " on " << fd);
}
resip::TcpConnection::TcpConnection ( ) [private]

No default c'tor.


Member Function Documentation

bool TcpConnection::hasDataToRead ( ) [virtual]

always true -- always add to fdset as read ready

Reimplemented from resip::Connection.

Definition at line 107 of file TcpConnection.cxx.

{
   return false;
}
bool TcpConnection::isGood ( ) [virtual]

has valid connection

Reimplemented from resip::Connection.

Definition at line 113 of file TcpConnection.cxx.

{
   return true;
}
bool TcpConnection::isWritable ( ) [virtual]

Reimplemented from resip::Connection.

Definition at line 119 of file TcpConnection.cxx.

{
   return true;
}
Data resip::TcpConnection::peerName ( )
int TcpConnection::read ( char *  ,
const int   
) [virtual]

pure virtual, but need concrete Connection for book-ends of lists

Reimplemented from resip::Connection.

Definition at line 22 of file TcpConnection.cxx.

References resip::getErrno(), resip::Connection::getSocket(), resip::Connection::read(), and SOCKET_ERROR.

{
   assert(buf);
   assert(count > 0);
   
#if defined(WIN32)
   int bytesRead = ::recv(getSocket(), buf, count, 0);
#else
   int bytesRead = ::read(getSocket(), buf, count);
#endif

   if (bytesRead == SOCKET_ERROR)
   {
      int e = getErrno();
      switch (e)
      {
         case EAGAIN:
#ifdef WIN32 //EWOULDBLOCK is not returned from recv on *nix/*bsd
         case EWOULDBLOCK:  
#endif
            InfoLog (<< "No data ready to read");
            return 0;
         case EINTR:
            InfoLog (<< "The call was interrupted by a signal before any data was read.");
            return 0;            
            break;
         case EIO:
            InfoLog (<< "I/O error");
            break;
         case EBADF:
            InfoLog (<< "fd is not a valid file descriptor or is not open for reading.");
            break;
         case EINVAL:
            InfoLog (<< "fd is attached to an object which is unsuitable for reading.");
            break;
         case EFAULT:
            InfoLog (<< "buf is outside your accessible address space.");
            break;
         default:
            InfoLog (<< "Some other error");
            break;
      }

      InfoLog (<< "Failed read on " << getSocket() << " " << strerror(e));
      Transport::error(e);
      setFailureReason(TransportFailure::ConnectionException, e+2000);
      return -1;
   }
   else if (bytesRead == 0)
   {
      InfoLog (<< "Connection closed by remote " << *this);
      return -1;
   }

   return bytesRead;
}

Here is the call graph for this function:

int TcpConnection::write ( const char *  ,
const int   
) [virtual]

pure virtual, but need concrete Connection for book-ends of lists

Reimplemented from resip::Connection.

Definition at line 81 of file TcpConnection.cxx.

{
   //DebugLog (<< "Writing " << buf);   // Note:  this can end up writing garbage to the logs following the message for non-null terminated buffers

   assert(buf);
   assert(count > 0);

#if defined(WIN32)
   int bytesWritten = ::send(getSocket(), buf, count, 0);
#else
   int bytesWritten = ::write(getSocket(), buf, count);
#endif

   if (bytesWritten == INVALID_SOCKET)
   {
      int e = getErrno();
      InfoLog (<< "Failed write on " << getSocket() << " " << strerror(e));
      Transport::error(e);
      //setFailureReason(TransportFailure::ConnectionException, e+1000);
      return -1;
   }
   
   return bytesWritten;
}

The documentation for this class was generated from the following files: