Logo
~Sockets~
~Examples~
~Contact~


StreamSocket Class Reference
[Basic sockets]

SOCK_STREAM Socket base class. More...

#include <StreamSocket.h>

Inheritance diagram for StreamSocket:

Inheritance graph
[legend]
Collaboration diagram for StreamSocket:

Collaboration graph
[legend]
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).
void SetCallOnConnect (bool x=true)
 Instruct socket to call OnConnect callback next sockethandler cycle.
bool CallOnConnect ()
 Check call on connect flag.
void SetRetryClientConnect (bool x=true)
 Set flag to initiate a connection attempt after a connection timeout.
bool RetryClientConnect ()
 Check if a connection attempt should be made.
virtual void SetLineProtocol (bool=true)
 Enable the OnLine callback.
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 &)

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_call_on_connect
 OnConnect will be called next ISocketHandler cycle if true.
bool m_b_retry_connect
 Try another connection attempt next ISocketHandler cycle.
bool m_line_protocol
 Line protocol mode flag.
int m_shutdown
 Shutdown status.

Detailed Description

SOCK_STREAM Socket base class.

Definition at line 14 of file StreamSocket.h.


Constructor & Destructor Documentation

StreamSocket::StreamSocket ( ISocketHandler  ) 

Definition at line 12 of file StreamSocket.cpp.

00012                                             : Socket(h)
00013 ,m_bConnecting(false)
00014 ,m_connect_timeout(5)
00015 ,m_flush_before_close(true)
00016 ,m_connection_retry(0)
00017 ,m_retries(0)
00018 ,m_call_on_connect(false)
00019 ,m_b_retry_connect(false)
00020 ,m_line_protocol(false)
00021 ,m_shutdown(0)
00022 {
00023 }

StreamSocket::~StreamSocket (  ) 

Definition at line 26 of file StreamSocket.cpp.

00027 {
00028 }

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

Definition at line 104 of file StreamSocket.h.

00104 {} // copy constructor


Member Function Documentation

void StreamSocket::SetConnecting ( bool  = true  ) 

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

Definition at line 31 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().

00032 {
00033         if (x != m_bConnecting)
00034         {
00035                 m_bConnecting = x;
00036                 if (x)
00037                 {
00038                         SetTimeout( GetConnectTimeout() );
00039                 }
00040                 else
00041                 {
00042                         SetTimeout( 0 );
00043                 }
00044         }
00045 }

bool StreamSocket::Connecting (  ) 

Check connecting flag.

Returns:
true if the socket is still trying to connect

Definition at line 48 of file StreamSocket.cpp.

References m_bConnecting.

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

00049 {
00050         return m_bConnecting;
00051 }

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 54 of file StreamSocket.cpp.

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

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

00055 {
00056         if (GetSocket() != INVALID_SOCKET && !Connecting() && !CloseAndDelete())
00057                 return true;
00058         return false;
00059 }

void StreamSocket::SetConnectTimeout ( int  x  ) 

Set timeout to use for connection attempt.

Parameters:
x Timeout in seconds

Definition at line 62 of file StreamSocket.cpp.

References m_connect_timeout.

00063 {
00064         m_connect_timeout = x;
00065 }

int StreamSocket::GetConnectTimeout (  ) 

Return number of seconds to wait for a connection.

Returns:
Connection timeout (seconds)

Definition at line 68 of file StreamSocket.cpp.

References m_connect_timeout.

Referenced by SetConnecting().

00069 {
00070         return m_connect_timeout;
00071 }

void StreamSocket::SetFlushBeforeClose ( bool  = true  ) 

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

Definition at line 74 of file StreamSocket.cpp.

References m_flush_before_close.

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

00075 {
00076         m_flush_before_close = x;
00077 }

bool StreamSocket::GetFlushBeforeClose (  ) 

Check flush before status.

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

Definition at line 80 of file StreamSocket.cpp.

References m_flush_before_close.

00081 {
00082         return m_flush_before_close;
00083 }

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 92 of file StreamSocket.cpp.

References m_connection_retry.

00093 {
00094         m_connection_retry = x;
00095 }

int StreamSocket::GetConnectionRetry (  ) 

Get number of maximum connection retries (tcp only).

Definition at line 86 of file StreamSocket.cpp.

References m_connection_retry.

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

00087 {
00088         return m_connection_retry;
00089 }

void StreamSocket::IncreaseConnectionRetries (  ) 

Increase number of actual connection retries (tcp only).

Definition at line 104 of file StreamSocket.cpp.

References m_retries.

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

00105 {
00106         m_retries++;
00107 }

int StreamSocket::GetConnectionRetries (  ) 

Get number of actual connection retries (tcp only).

Definition at line 98 of file StreamSocket.cpp.

References m_retries.

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

00099 {
00100         return m_retries;
00101 }

void StreamSocket::ResetConnectionRetries (  ) 

Reset actual connection retries (tcp only).

Definition at line 110 of file StreamSocket.cpp.

References m_retries.

00111 {
00112         m_retries = 0;
00113 }

void StreamSocket::SetCallOnConnect ( bool  x = true  ) 

Instruct socket to call OnConnect callback next sockethandler cycle.

Definition at line 116 of file StreamSocket.cpp.

References ISocketHandler::AddList(), Socket::GetSocket(), Socket::Handler(), LIST_CALLONCONNECT, and m_call_on_connect.

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

00117 {
00118         Handler().AddList(GetSocket(), LIST_CALLONCONNECT, x);
00119         m_call_on_connect = x;
00120 }

bool StreamSocket::CallOnConnect (  ) 

Check call on connect flag.

Returns:
true if OnConnect() should be called a.s.a.p

Definition at line 123 of file StreamSocket.cpp.

References m_call_on_connect.

00124 {
00125         return m_call_on_connect;
00126 }

void StreamSocket::SetRetryClientConnect ( bool  x = true  ) 

Set flag to initiate a connection attempt after a connection timeout.

Definition at line 129 of file StreamSocket.cpp.

References ISocketHandler::AddList(), Socket::GetSocket(), Socket::Handler(), LIST_RETRY, and m_b_retry_connect.

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

00130 {
00131         Handler().AddList(GetSocket(), LIST_RETRY, x);
00132         m_b_retry_connect = x;
00133 }

bool StreamSocket::RetryClientConnect (  ) 

Check if a connection attempt should be made.

Returns:
true when another attempt should be made

Definition at line 136 of file StreamSocket.cpp.

References m_b_retry_connect.

00137 {
00138         return m_b_retry_connect;
00139 }

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

Enable the OnLine callback.

Do not create your own OnRead callback when using this.

Reimplemented in TcpSocket.

Definition at line 142 of file StreamSocket.cpp.

References m_line_protocol.

Referenced by TcpSocket::SetLineProtocol().

00143 {
00144         m_line_protocol = x;
00145 }

bool StreamSocket::LineProtocol (  ) 

Check line protocol mode.

Returns:
true if socket is in line protocol mode

Definition at line 148 of file StreamSocket.cpp.

References m_line_protocol.

Referenced by TcpSocket::OnRead().

00149 {
00150         return m_line_protocol;
00151 }

void StreamSocket::SetShutdown ( int   ) 

Set shutdown status.

Definition at line 154 of file StreamSocket.cpp.

References m_shutdown.

Referenced by TcpSocket::OnRead().

00155 {
00156         m_shutdown = x;
00157 }

int StreamSocket::GetShutdown (  ) 

Get shutdown status.

Definition at line 160 of file StreamSocket.cpp.

References m_shutdown.

Referenced by TcpSocket::Close().

00161 {
00162         return m_shutdown;
00163 }

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 107 of file StreamSocket.h.

00107 { return *this; } // assignment operator


Member Data Documentation

Flag indicating connection in progress.

Definition at line 109 of file StreamSocket.h.

Referenced by Connecting(), and SetConnecting().

Connection timeout (seconds).

Definition at line 110 of file StreamSocket.h.

Referenced by GetConnectTimeout(), and SetConnectTimeout().

Send all data before closing (default true).

Definition at line 111 of file StreamSocket.h.

Referenced by GetFlushBeforeClose(), and SetFlushBeforeClose().

Maximum connection retries (tcp).

Definition at line 112 of file StreamSocket.h.

Referenced by GetConnectionRetry(), and SetConnectionRetry().

int StreamSocket::m_retries [private]

Actual number of connection retries (tcp).

Definition at line 113 of file StreamSocket.h.

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

OnConnect will be called next ISocketHandler cycle if true.

Definition at line 114 of file StreamSocket.h.

Referenced by CallOnConnect(), and SetCallOnConnect().

Try another connection attempt next ISocketHandler cycle.

Definition at line 115 of file StreamSocket.h.

Referenced by RetryClientConnect(), and SetRetryClientConnect().

Line protocol mode flag.

Definition at line 116 of file StreamSocket.h.

Referenced by LineProtocol(), and SetLineProtocol().

int StreamSocket::m_shutdown [private]

Shutdown status.

Definition at line 117 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