![]() |
StreamSocket.cppGo to the documentation of this file.00001 00006 /* 00007 Copyright (C) 2008-2011 Anders Hedstrom 00008 00009 This library is made available under the terms of the GNU GPL, with 00010 the additional exemption that compiling, linking, and/or using OpenSSL 00011 is allowed. 00012 00013 If you would like to use this library in a closed-source application, 00014 a separate license agreement is available. For information about 00015 the closed-source license agreement for the C++ sockets library, 00016 please visit http://www.alhem.net/Sockets/license.html and/or 00017 email license@alhem.net. 00018 00019 This program is free software; you can redistribute it and/or 00020 modify it under the terms of the GNU General Public License 00021 as published by the Free Software Foundation; either version 2 00022 of the License, or (at your option) any later version. 00023 00024 This program is distributed in the hope that it will be useful, 00025 but WITHOUT ANY WARRANTY; without even the implied warranty of 00026 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00027 GNU General Public License for more details. 00028 00029 You should have received a copy of the GNU General Public License 00030 along with this program; if not, write to the Free Software 00031 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00032 */ 00033 #include "StreamSocket.h" 00034 #include "ISocketHandler.h" 00035 00036 00037 #ifdef SOCKETS_NAMESPACE 00038 namespace SOCKETS_NAMESPACE { 00039 #endif 00040 00041 00042 StreamSocket::StreamSocket(ISocketHandler& h) : 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 } 00052 00053 00054 StreamSocket::~StreamSocket() 00055 { 00056 } 00057 00058 00059 void StreamSocket::SetConnecting(bool x) 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 } 00074 00075 00076 bool StreamSocket::Connecting() 00077 { 00078 return m_bConnecting; 00079 } 00080 00081 00082 bool StreamSocket::Ready() 00083 { 00084 if (GetSocket() != INVALID_SOCKET && !Connecting() && !CloseAndDelete()) 00085 return true; 00086 return false; 00087 } 00088 00089 00090 void StreamSocket::SetConnectTimeout(int x) 00091 { 00092 m_connect_timeout = x; 00093 } 00094 00095 00096 int StreamSocket::GetConnectTimeout() 00097 { 00098 return m_connect_timeout; 00099 } 00100 00101 00102 void StreamSocket::SetFlushBeforeClose(bool x) 00103 { 00104 m_flush_before_close = x; 00105 } 00106 00107 00108 bool StreamSocket::GetFlushBeforeClose() 00109 { 00110 return m_flush_before_close; 00111 } 00112 00113 00114 int StreamSocket::GetConnectionRetry() 00115 { 00116 return m_connection_retry; 00117 } 00118 00119 00120 void StreamSocket::SetConnectionRetry(int x) 00121 { 00122 m_connection_retry = x; 00123 } 00124 00125 00126 int StreamSocket::GetConnectionRetries() 00127 { 00128 return m_retries; 00129 } 00130 00131 00132 void StreamSocket::IncreaseConnectionRetries() 00133 { 00134 m_retries++; 00135 } 00136 00137 00138 void StreamSocket::ResetConnectionRetries() 00139 { 00140 m_retries = 0; 00141 } 00142 00143 00144 void StreamSocket::SetLineProtocol(bool x) 00145 { 00146 m_line_protocol = x; 00147 } 00148 00149 00150 bool StreamSocket::LineProtocol() 00151 { 00152 return m_line_protocol; 00153 } 00154 00155 00156 void StreamSocket::SetShutdown(int x) 00157 { 00158 m_shutdown = x; 00159 } 00160 00161 00162 int StreamSocket::GetShutdown() 00163 { 00164 return m_shutdown; 00165 } 00166 00167 00168 00169 00170 #ifdef SOCKETS_NAMESPACE 00171 } // namespace SOCKETS_NAMESPACE { 00172 #endif 00173 |