Differences From Artifact [e59925afa4]:
- File
src/OFTCPSocket.m
— part of check-in
[c6a4b0a95f]
at
2014-08-18 10:53:56
on branch trunk
— OFTCPSocket: Clear read buffer for new connection
This prevents reading old data when closing and reconnecting the socket. (user: js, size: 11203) [annotate] [blame] [check-ins using]
To Artifact [c059520ca3]:
- File src/OFTCPSocket.m — part of check-in [06d2de4571] at 2014-12-13 16:52:58 on branch trunk — Use CLOEXEC for files and sockets (user: js, size: 12290) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
286 287 288 289 290 291 292 293 | port = _SOCKS5Port; } results = of_resolve_host(host, port, SOCK_STREAM); for (iter = results; *iter != NULL; iter++) { of_resolver_result_t *result = *iter; | > > > | > > > > > > | 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | port = _SOCKS5Port; } results = of_resolve_host(host, port, SOCK_STREAM); for (iter = results; *iter != NULL; iter++) { of_resolver_result_t *result = *iter; #if SOCK_CLOEXEC == 0 int flags; #endif if ((_socket = socket(result->family, result->type | SOCK_CLOEXEC, result->protocol)) == INVALID_SOCKET) continue; #if SOCK_CLOEXEC == 0 if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #endif if (connect(_socket, result->address, result->addressLength) == -1) { close(_socket); _socket = INVALID_SOCKET; continue; } |
︙ | ︙ | |||
381 382 383 384 385 386 387 | #ifdef __wii__ if (port == 0) port = freePort--; #endif results = of_resolve_host(host, port, SOCK_STREAM); @try { | > > > > | > > > > > > | 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | #ifdef __wii__ if (port == 0) port = freePort--; #endif results = of_resolve_host(host, port, SOCK_STREAM); @try { #if SOCK_CLOEXEC == 0 int flags; #endif if ((_socket = socket(results[0]->family, results[0]->type | SOCK_CLOEXEC, results[0]->protocol)) == INVALID_SOCKET) @throw [OFBindFailedException exceptionWithHost: host port: port socket: self]; #if SOCK_CLOEXEC == 0 if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #endif if (setsockopt(_socket, SOL_SOCKET, SO_REUSEADDR, (const char*)&one, (socklen_t)sizeof(one))) @throw [OFSetOptionFailedException exceptionWithStream: self]; if (bind(_socket, results[0]->address, |
︙ | ︙ | |||
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 | _listening = true; } - (instancetype)accept { OFTCPSocket *client = [[[[self class] alloc] init] autorelease]; client->_address = [client allocMemoryWithSize: sizeof(struct sockaddr_storage)]; client->_addressLength = (socklen_t)sizeof(struct sockaddr_storage); if ((client->_socket = accept(_socket, client->_address, &client->_addressLength)) == INVALID_SOCKET) @throw [OFAcceptFailedException exceptionWithSocket: self]; assert(client->_addressLength <= sizeof(struct sockaddr_storage)); if (client->_addressLength != sizeof(struct sockaddr_storage)) { @try { client->_address = [client resizeMemory: client->_address | > > > > > > > > > > > > > > > > | 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 | _listening = true; } - (instancetype)accept { OFTCPSocket *client = [[[[self class] alloc] init] autorelease]; #if (!defined(HAVE_PACCEPT) && !defined(HAVE_ACCEPT4)) || !defined(SOCK_CLOEXEC) int flags; #endif client->_address = [client allocMemoryWithSize: sizeof(struct sockaddr_storage)]; client->_addressLength = (socklen_t)sizeof(struct sockaddr_storage); #if defined(HAVE_PACCEPT) && defined(SOCK_CLOEXEC) if ((client->_socket = paccept(_socket, client->_address, &client->_addressLength, NULL, SOCK_CLOEXEC)) == INVALID_SOCKET) @throw [OFAcceptFailedException exceptionWithSocket: self]; #elif defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) if ((client->_socket = accept4(_socket, client->_address, &client->_addressLength, SOCK_CLOEXEC)) == INVALID_SOCKET) @throw [OFAcceptFailedException exceptionWithSocket: self]; #else if ((client->_socket = accept(_socket, client->_address, &client->_addressLength)) == INVALID_SOCKET) @throw [OFAcceptFailedException exceptionWithSocket: self]; if ((flags = fcntl(client->_socket, F_GETFD, 0)) != -1) fcntl(client->_socket, F_SETFD, flags | FD_CLOEXEC); #endif assert(client->_addressLength <= sizeof(struct sockaddr_storage)); if (client->_addressLength != sizeof(struct sockaddr_storage)) { @try { client->_address = [client resizeMemory: client->_address |
︙ | ︙ |