00001
00002
00003 #include "StreamSocket.h"
00004 #include "ISocketHandler.h"
00005
00006
00007 #ifdef SOCKETS_NAMESPACE
00008 namespace SOCKETS_NAMESPACE {
00009 #endif
00010
00011
00012 StreamSocket::StreamSocket(ISocketHandler& h) : 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 }
00024
00025
00026 StreamSocket::~StreamSocket()
00027 {
00028 }
00029
00030
00031 void StreamSocket::SetConnecting(bool x)
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 }
00046
00047
00048 bool StreamSocket::Connecting()
00049 {
00050 return m_bConnecting;
00051 }
00052
00053
00054 bool StreamSocket::Ready()
00055 {
00056 if (GetSocket() != INVALID_SOCKET && !Connecting() && !CloseAndDelete())
00057 return true;
00058 return false;
00059 }
00060
00061
00062 void StreamSocket::SetConnectTimeout(int x)
00063 {
00064 m_connect_timeout = x;
00065 }
00066
00067
00068 int StreamSocket::GetConnectTimeout()
00069 {
00070 return m_connect_timeout;
00071 }
00072
00073
00074 void StreamSocket::SetFlushBeforeClose(bool x)
00075 {
00076 m_flush_before_close = x;
00077 }
00078
00079
00080 bool StreamSocket::GetFlushBeforeClose()
00081 {
00082 return m_flush_before_close;
00083 }
00084
00085
00086 int StreamSocket::GetConnectionRetry()
00087 {
00088 return m_connection_retry;
00089 }
00090
00091
00092 void StreamSocket::SetConnectionRetry(int x)
00093 {
00094 m_connection_retry = x;
00095 }
00096
00097
00098 int StreamSocket::GetConnectionRetries()
00099 {
00100 return m_retries;
00101 }
00102
00103
00104 void StreamSocket::IncreaseConnectionRetries()
00105 {
00106 m_retries++;
00107 }
00108
00109
00110 void StreamSocket::ResetConnectionRetries()
00111 {
00112 m_retries = 0;
00113 }
00114
00115
00116 void StreamSocket::SetCallOnConnect(bool x)
00117 {
00118 Handler().AddList(GetSocket(), LIST_CALLONCONNECT, x);
00119 m_call_on_connect = x;
00120 }
00121
00122
00123 bool StreamSocket::CallOnConnect()
00124 {
00125 return m_call_on_connect;
00126 }
00127
00128
00129 void StreamSocket::SetRetryClientConnect(bool x)
00130 {
00131 Handler().AddList(GetSocket(), LIST_RETRY, x);
00132 m_b_retry_connect = x;
00133 }
00134
00135
00136 bool StreamSocket::RetryClientConnect()
00137 {
00138 return m_b_retry_connect;
00139 }
00140
00141
00142 void StreamSocket::SetLineProtocol(bool x)
00143 {
00144 m_line_protocol = x;
00145 }
00146
00147
00148 bool StreamSocket::LineProtocol()
00149 {
00150 return m_line_protocol;
00151 }
00152
00153
00154 void StreamSocket::SetShutdown(int x)
00155 {
00156 m_shutdown = x;
00157 }
00158
00159
00160 int StreamSocket::GetShutdown()
00161 {
00162 return m_shutdown;
00163 }
00164
00165
00166
00167
00168 #ifdef SOCKETS_NAMESPACE
00169 }
00170 #endif