Changeset 2115 for box/trunk/lib/server/SocketStream.cpp
- Timestamp:
- 28/03/2008 22:18:44 (4 years ago)
- File:
-
- 1 edited
-
box/trunk/lib/server/SocketStream.cpp (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/lib/server/SocketStream.cpp
r1894 r2115 151 151 152 152 // Create the socket 153 mSocketHandle = ::socket(sockDomain, SOCK_STREAM, 0 /* let OS choose protocol */); 153 mSocketHandle = ::socket(sockDomain, SOCK_STREAM, 154 0 /* let OS choose protocol */); 154 155 if(mSocketHandle == INVALID_SOCKET_VALUE) 155 156 { 157 BOX_LOG_SYS_ERROR("Failed to create a network socket"); 156 158 THROW_EXCEPTION(ServerException, SocketOpenError) 157 159 } … … 164 166 DWORD err = WSAGetLastError(); 165 167 ::closesocket(mSocketHandle); 166 #else 168 BOX_LOG_WIN_ERROR_NUMBER("Failed to connect to socket " 169 "(type " << Type << ", name " << Name << 170 ", port " << Port << ")", err); 171 #else // !WIN32 167 172 int err = errno; 168 173 ::close(mSocketHandle); 169 #endif 170 171 #ifdef WIN32 172 BOX_ERROR("Failed to connect to socket (type " << Type << 173 ", name " << Name << ", port " << Port << "): " << 174 GetErrorMessage(err) 175 ); 176 #else 177 BOX_ERROR("Failed to connect to socket (type " << Type << 178 ", name " << Name << ", port " << Port << "): " << 179 strerror(err) << " (" << err << ")" 180 ); 181 #endif 174 BOX_LOG_SYS_ERROR("Failed to connect to socket (type " << 175 Type << ", name " << Name << ", port " << Port << 176 ")"); 177 #endif // WIN32 182 178 183 179 mSocketHandle = INVALID_SOCKET_VALUE; … … 221 217 { 222 218 // Bad! 223 THROW_EXCEPTION(ServerException, SocketPollError) 219 BOX_LOG_SYS_ERROR("Failed to poll socket"); 220 THROW_EXCEPTION(ServerException, 221 SocketPollError) 224 222 } 225 223 break; … … 251 249 { 252 250 // Other error 253 THROW_EXCEPTION(ConnectionException, Conn_SocketReadError) 251 BOX_LOG_SYS_ERROR("Failed to read from socket"); 252 THROW_EXCEPTION(ConnectionException, 253 Conn_SocketReadError); 254 254 } 255 255 } 256 256 257 // Closed for reading? 257 258 if(r == 0) … … 298 299 // Error. 299 300 mWriteClosed = true; // assume can't write again 300 THROW_EXCEPTION(ConnectionException, Conn_SocketWriteError) 301 BOX_LOG_SYS_ERROR("Failed to write to socket"); 302 THROW_EXCEPTION(ConnectionException, 303 Conn_SocketWriteError); 301 304 } 302 305 … … 311 314 if(bytesLeft > 0) 312 315 { 313 TRACE3("Waiting to send data on socket %d, (%d to send of %d)\n", mSocketHandle, bytesLeft, NBytes); 316 BOX_TRACE("Waiting to send data on socket " << 317 mSocketHandle << " (" << bytesLeft << 318 " of " << NBytes << " bytes left)"); 314 319 315 320 // Wait for data to send. … … 324 329 if(errno != EINTR) 325 330 { 326 THROW_EXCEPTION(ServerException, SocketPollError) 331 BOX_LOG_SYS_ERROR("Failed to poll " 332 "socket"); 333 THROW_EXCEPTION(ServerException, 334 SocketPollError) 327 335 } 328 336 } … … 351 359 #endif 352 360 { 361 BOX_LOG_SYS_ERROR("Failed to close socket"); 353 362 THROW_EXCEPTION(ServerException, SocketCloseError) 354 363 } … … 381 390 if(::shutdown(mSocketHandle, how) == -1) 382 391 { 392 BOX_LOG_SYS_ERROR("Failed to shutdown socket"); 383 393 THROW_EXCEPTION(ConnectionException, Conn_SocketShutdownError) 384 394 } … … 459 469 socklen_t credLen = sizeof(cred); 460 470 461 if(::getsockopt(mSocketHandle, SOL_SOCKET, SO_PEERCRED, &cred, &credLen) == 0) 471 if(::getsockopt(mSocketHandle, SOL_SOCKET, SO_PEERCRED, &cred, 472 &credLen) == 0) 462 473 { 463 474 rUidOut = cred.uid; … … 465 476 return true; 466 477 } 478 479 BOX_LOG_SYS_ERROR("Failed to get peer credentials on socket"); 467 480 #endif 468 481
Note: See TracChangeset
for help on using the changeset viewer.
