Logo
~Sockets~
~Examples~
~Contact~


StreamSocket Class Reference
[Basic sockets]

SOCK_STREAM Socket base class. More...

#include <StreamSocket.h>

Inheritance diagram for StreamSocket:
Collaboration diagram for StreamSocket:

List of all members.


Public Member Functions

 StreamSocket (ISocketHandler &)
 ~StreamSocket ()
void SetConnecting (bool=true)
 Socket should Check Connect on next write event from select().
bool Connecting ()
 Check connecting flag.
bool Ready ()
 Returns true when socket file descriptor is valid, socket connection is established, and socket is not about to be closed.
void SetConnectTimeout (int x)
 Set timeout to use for connection attempt.
int GetConnectTimeout ()
 Return number of seconds to wait for a connection.
void SetFlushBeforeClose (bool=true)
 Set flush before close to make a tcp socket completely empty its output buffer before closing the connection.
bool GetFlushBeforeClose ()
 Check flush before status.
void SetConnectionRetry (int n)
 Define number of connection retries (tcp only).
int GetConnectionRetry ()
 Get number of maximum connection retries (tcp only).
void IncreaseConnectionRetries ()
 Increase number of actual connection retries (tcp only).
int GetConnectionRetries ()
 Get number of actual connection retries (tcp only).
void ResetConnectionRetries ()
 Reset actual connection retries (tcp only).
virtual void SetLineProtocol (bool=true)
 Called after OnRead if socket is in line protocol mode.
bool LineProtocol ()
 Check line protocol mode.
void SetShutdown (int)
 Set shutdown status.
int GetShutdown ()
 Get shutdown status.
virtual int Protocol ()=0
 Returns IPPROTO_TCP or IPPROTO_SCTP.

Protected Member Functions

 StreamSocket (const StreamSocket &src)

Private Member Functions

StreamSocketoperator= (const StreamSocket &)

Private Attributes

bool m_bConnecting
 Flag indicating connection in progress.
int m_connect_timeout
 Connection timeout (seconds).
bool m_flush_before_close
 Send all data before closing (default true).
int m_connection_retry
 Maximum connection retries (tcp).
int m_retries
 Actual number of connection retries (tcp).
bool m_line_protocol
 Line protocol mode flag.
int m_shutdown
 Shutdown status.

Detailed Description

SOCK_STREAM Socket base class.

Definition at line 46 of file StreamSocket.h.


Constructor & Destructor Documentation

StreamSocket::StreamSocket ( ISocketHandler h  ) 

Definition at line 42 of file StreamSocket.cpp.

00042                                             : Socket(h)
00043 ,m_bConnecting(false)
00044 ,m_connect_timeout(5)
00045 ,m_flush_before_close(true)
00046 ,m_connection_retry(0)
00047 ,m_retries(0)
00048 ,m_line_protocol(false)
00049 ,m_shutdown(0)
00050 {
00051 }

StreamSocket::~StreamSocket (  ) 

Definition at line 54 of file StreamSocket.cpp.

00055 {
00056 }

StreamSocket::StreamSocket ( const StreamSocket src  )  [inline, protected]

Definition at line 118 of file StreamSocket.h.

00118 : Socket(src) {} // copy constructor


Member Function Documentation

void StreamSocket::SetConnecting ( bool  x = true  ) 

Socket should Check Connect on next write event from select().

Definition at line 59 of file StreamSocket.cpp.

References GetConnectTimeout(), m_bConnecting, and Socket::SetTimeout().

Referenced by SctpSocket::AddConnection(), TcpSocket::OnConnectTimeout(), SctpSocket::OnConnectTimeout(), TcpSocket::OnSocks4ConnectFailed(), TcpSocket::OnSocks4Read(), TcpSocket::OnWrite(), SctpSocket::OnWrite(), TcpSocket::Open(), and SctpSocket::Open().

00060 {
00061         if (x != m_bConnecting)
00062         {
00063                 m_bConnecting = x;
00064                 if (x)
00065                 {
00066                         SetTimeout( GetConnectTimeout() );
00067                 }
00068                 else
00069                 {
00070                         SetTimeout( 0 );
00071                 }
00072         }
00073 }

bool StreamSocket::Connecting (  ) 

Check connecting flag.

Returns:
true if the socket is still trying to connect

Definition at line 76 of file StreamSocket.cpp.

References m_bConnecting.

Referenced by HttpGetSocket::DoConnect(), TcpSocket::OnWrite(), SctpSocket::OnWrite(), Ready(), and TcpSocket::SendBuf().

00077 {
00078         return m_bConnecting;
00079 }

bool StreamSocket::Ready (  )  [virtual]

Returns true when socket file descriptor is valid, socket connection is established, and socket is not about to be closed.

Reimplemented from Socket.

Definition at line 82 of file StreamSocket.cpp.

References Socket::CloseAndDelete(), Connecting(), Socket::GetSocket(), and INVALID_SOCKET.

Referenced by TcpSocket::OnRead(), and TcpSocket::SendBuf().

00083 {
00084         if (GetSocket() != INVALID_SOCKET && !Connecting() && !CloseAndDelete())
00085                 return true;
00086         return false;
00087 }

void StreamSocket::SetConnectTimeout ( int  x  ) 

Set timeout to use for connection attempt.

Parameters:
x Timeout in seconds

Definition at line 90 of file StreamSocket.cpp.

References m_connect_timeout.

00091 {
00092         m_connect_timeout = x;
00093 }

int StreamSocket::GetConnectTimeout (  ) 

Return number of seconds to wait for a connection.

Returns:
Connection timeout (seconds)

Definition at line 96 of file StreamSocket.cpp.

References m_connect_timeout.

Referenced by SetConnecting().

00097 {
00098         return m_connect_timeout;
00099 }

void StreamSocket::SetFlushBeforeClose ( bool  x = true  ) 

Set flush before close to make a tcp socket completely empty its output buffer before closing the connection.

Definition at line 102 of file StreamSocket.cpp.

References m_flush_before_close.

Referenced by TcpSocket::OnRead(), and TcpSocket::TryWrite().

00103 {
00104         m_flush_before_close = x;
00105 }

bool StreamSocket::GetFlushBeforeClose (  ) 

Check flush before status.

Returns:
true if the socket should send all data before closing

Definition at line 108 of file StreamSocket.cpp.

References m_flush_before_close.

00109 {
00110         return m_flush_before_close;
00111 }

void StreamSocket::SetConnectionRetry ( int  n  ) 

Define number of connection retries (tcp only).

n = 0 - no retry n > 0 - number of retries n = -1 - unlimited retries

Definition at line 120 of file StreamSocket.cpp.

References m_connection_retry.

00121 {
00122         m_connection_retry = x;
00123 }

int StreamSocket::GetConnectionRetry (  ) 

Get number of maximum connection retries (tcp only).

Definition at line 114 of file StreamSocket.cpp.

References m_connection_retry.

Referenced by TcpSocket::OnConnectTimeout(), SctpSocket::OnConnectTimeout(), TcpSocket::OnWrite(), and SctpSocket::OnWrite().

00115 {
00116         return m_connection_retry;
00117 }

void StreamSocket::IncreaseConnectionRetries (  ) 

Increase number of actual connection retries (tcp only).

Definition at line 132 of file StreamSocket.cpp.

References m_retries.

Referenced by TcpSocket::OnConnectTimeout(), and SctpSocket::OnConnectTimeout().

00133 {
00134         m_retries++;
00135 }

int StreamSocket::GetConnectionRetries (  ) 

Get number of actual connection retries (tcp only).

Definition at line 126 of file StreamSocket.cpp.

References m_retries.

Referenced by TcpSocket::OnConnectTimeout(), SctpSocket::OnConnectTimeout(), TcpSocket::OnWrite(), and SctpSocket::OnWrite().

00127 {
00128         return m_retries;
00129 }

void StreamSocket::ResetConnectionRetries (  ) 

Reset actual connection retries (tcp only).

Definition at line 138 of file StreamSocket.cpp.

References m_retries.

00139 {
00140         m_retries = 0;
00141 }

void StreamSocket::SetLineProtocol ( bool  x = true  )  [virtual]

Called after OnRead if socket is in line protocol mode.

See also:
SetLineProtocol Enable the OnLine callback. Do not create your own OnRead callback when using this.

Reimplemented in TcpSocket.

Definition at line 144 of file StreamSocket.cpp.

References m_line_protocol.

Referenced by TcpSocket::SetLineProtocol().

00145 {
00146         m_line_protocol = x;
00147 }

bool StreamSocket::LineProtocol (  ) 

Check line protocol mode.

Returns:
true if socket is in line protocol mode

Definition at line 150 of file StreamSocket.cpp.

References m_line_protocol.

Referenced by TcpSocket::OnRead().

00151 {
00152         return m_line_protocol;
00153 }

void StreamSocket::SetShutdown ( int  x  ) 

Set shutdown status.

Definition at line 156 of file StreamSocket.cpp.

References m_shutdown.

Referenced by TcpSocket::OnRead().

00157 {
00158         m_shutdown = x;
00159 }

int StreamSocket::GetShutdown (  ) 

Get shutdown status.

Definition at line 162 of file StreamSocket.cpp.

References m_shutdown.

Referenced by TcpSocket::Close().

00163 {
00164         return m_shutdown;
00165 }

virtual int StreamSocket::Protocol (  )  [pure virtual]

Returns IPPROTO_TCP or IPPROTO_SCTP.

Implemented in SctpSocket, and TcpSocket.

StreamSocket& StreamSocket::operator= ( const StreamSocket  )  [inline, private]

Definition at line 121 of file StreamSocket.h.

00121 { return *this; } // assignment operator


Member Data Documentation

Flag indicating connection in progress.

Definition at line 123 of file StreamSocket.h.

Referenced by Connecting(), and SetConnecting().

Connection timeout (seconds).

Definition at line 124 of file StreamSocket.h.

Referenced by GetConnectTimeout(), and SetConnectTimeout().

Send all data before closing (default true).

Definition at line 125 of file StreamSocket.h.

Referenced by GetFlushBeforeClose(), and SetFlushBeforeClose().

Maximum connection retries (tcp).

Definition at line 126 of file StreamSocket.h.

Referenced by GetConnectionRetry(), and SetConnectionRetry().

int StreamSocket::m_retries [private]

Actual number of connection retries (tcp).

Definition at line 127 of file StreamSocket.h.

Referenced by GetConnectionRetries(), IncreaseConnectionRetries(), and ResetConnectionRetries().

Line protocol mode flag.

Definition at line 128 of file StreamSocket.h.

Referenced by LineProtocol(), and SetLineProtocol().

int StreamSocket::m_shutdown [private]

Shutdown status.

Definition at line 129 of file StreamSocket.h.

Referenced by GetShutdown(), and SetShutdown().


The documentation for this class was generated from the following files:
Page, code, and content Copyright (C) 2007 by Anders Hedström
Generated for C++ Sockets by  doxygen 1.4.4