Changeset 14 in cheroxy for trunk/src/CRXSocket.cpp
- Timestamp:
- 10/24/12 11:12:11 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/CRXSocket.cpp
r6 r14 18 18 { 19 19 /*----------------------------------------------------------------*/ 20 memset ((void *)&mAddress, 0x0, sizeof (st SockAddrIn));20 memset ((void *)&mAddress, 0x0, sizeof (struct sockaddr_in)); 21 21 22 22 if (!CRXSocket::IsInitialized ()) … … 160 160 161 161 int 162 CRXSocket::Connect (std::string aUrl, 163 ushort aPort) 162 CRXSocket::Connect (const std::string aUrl, 163 const unsigned short aPort, 164 const int aTimeout) 164 165 { 165 166 int aResult = -1; 166 167 struct hostent * aHostEnt; 168 169 #ifndef _WIN32 170 struct timeval aTimeVal; 171 aTimeVal.tv_sec = aTimeout; 172 aTimeVal.tv_usec= 0; 173 #else 174 int aTimeMilliSec = aTimeout * 1000; 175 #endif 167 176 168 177 /*----------------------------------------------------------------*/ … … 188 197 } 189 198 190 aResult = connect (mSocket, (stSockAddr*) &mAddress, sizeof (mAddress)); 199 if (aTimeout > TCPSOCKET_NO_TIMEOUT) 200 { 201 #ifdef _WIN32 202 aResult = setsockopt (mSocket, 203 SOL_SOCKET, 204 SO_RCVTIMEO, 205 (char *) &aTimeMilliSec, 206 sizeof (aTimeMilliSec)); 207 #else 208 aResult = setsockopt (mSocket, 209 SOL_SOCKET, 210 SO_RCVTIMEO, 211 &aTimeVal, 212 (socklen_t) sizeof (aTimeVal)); 213 #endif 214 if (aResult < 0) 215 { 216 return ERROR_TCPSOCKET_FAILED_TO_SETSOCKOPT; 217 } 218 } 219 220 aResult = connect (mSocket, (struct sockaddr*) &mAddress, sizeof (mAddress)); 191 221 if (aResult < 0) 192 222 { … … 199 229 200 230 int 201 CRXSocket::CreateServer ( ushortaPort,202 intaBacklog,203 st SockAddrIn* aAddress)231 CRXSocket::CreateServer (const unsigned short aPort, 232 const int aBacklog, 233 struct sockaddr_in * aAddress) 204 234 { 205 235 int aResult = -1; … … 216 246 mAddress.sin_port = htons (aPort); 217 247 218 aResult = bind (mSocket, (st SockAddr *)&mAddress, sizeof (stSockAddr));248 aResult = bind (mSocket, (struct sockaddr *)&mAddress, sizeof (struct sockaddr)); 219 249 if (aResult < 0) 220 250 { … … 230 260 if (aAddress != NULL) 231 261 { 232 memset ((void *)aAddress, 0x0, sizeof (st SockAddrIn));233 memcpy ((void *)aAddress, (void *)&mAddress, sizeof (st SockAddrIn));234 } 235 236 /*----------------------------------------------------------------*/ 237 return aResult; 238 } 239 240 int 241 CRXSocket::Accept (st SockAddrIn* aRemoteAddress,242 int * aAddressLength)243 { 244 int aResult = -1;245 246 st SockAddrIn aAddress;247 socklen_t aLength = sizeof (aAddress);262 memset ((void *)aAddress, 0x0, sizeof (struct sockaddr_in)); 263 memcpy ((void *)aAddress, (void *)&mAddress, sizeof (struct sockaddr_in)); 264 } 265 266 /*----------------------------------------------------------------*/ 267 return aResult; 268 } 269 270 int 271 CRXSocket::Accept (struct sockaddr_in * aRemoteAddress, 272 int * aAddressLength) 273 { 274 int aResult = -1; 275 276 struct sockaddr_in aAddress; 277 socklen_t aLength = sizeof (aAddress); 248 278 249 279 /*----------------------------------------------------------------*/ 250 280 if (!IsReady ()) return ERROR_TCPSOCKET_NOT_READY; 251 281 252 aResult = accept (mSocket, (st SockAddr *) &aAddress, &aLength);282 aResult = accept (mSocket, (struct sockaddr *) &aAddress, &aLength); 253 283 if (aResult < 0) 254 284 { … … 258 288 if (aRemoteAddress != NULL) 259 289 { 260 memset ((void *)aRemoteAddress, 0x0, sizeof (st SockAddrIn));261 memcpy ((void *)aRemoteAddress, (void *)&aAddress, sizeof (st SockAddrIn));290 memset ((void *)aRemoteAddress, 0x0, sizeof (struct sockaddr_in)); 291 memcpy ((void *)aRemoteAddress, (void *)&aAddress, sizeof (struct sockaddr_in)); 262 292 } 263 293
Note:
See TracChangeset
for help on using the changeset viewer.