|
1 | 1 | /* sagittarius-socket.c -*- mode:c; coding:utf-8; -*-
|
2 | 2 | *
|
3 |
| - * Copyright (c) 2010-2016 Takashi Kato <ktakashi@ymail.com> |
| 3 | + * Copyright (c) 2010-2025 Takashi Kato <ktakashi@ymail.com> |
4 | 4 | *
|
5 | 5 | * Redistribution and use in source and binary forms, with or without
|
6 | 6 | * modification, are permitted provided that the following conditions
|
@@ -500,13 +500,15 @@ SgObject Sg_CreateSocket(int family, int socktype, int protocol)
|
500 | 500 | return make_socket_inner(fd);
|
501 | 501 | }
|
502 | 502 |
|
503 |
| -static void disable_nagle(SOCKET fd) |
| 503 | +static void flush_tcp(SOCKET fd) |
504 | 504 | {
|
505 | 505 | #ifdef TCP_NODELAY
|
506 |
| - const int value = 1; |
507 |
| - /* we ignore the return value here, since this is merely performance |
508 |
| - optimisation */ |
509 |
| - setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const char *)&value, sizeof(int)); |
| 506 | + int value = 1; |
| 507 | + /* we ignore the return value here, since this is merely performance |
| 508 | + optimisation */ |
| 509 | + setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const char *)&value, sizeof(int)); |
| 510 | + value = 0; |
| 511 | + setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const char *)&value, sizeof(int)); |
510 | 512 | #endif
|
511 | 513 | }
|
512 | 514 |
|
@@ -541,8 +543,6 @@ SgObject Sg_SocketConnect(SgSocket *socket, SgAddrinfo* addrinfo,
|
541 | 543 | goto err;
|
542 | 544 | }
|
543 | 545 | }
|
544 |
| - |
545 |
| - disable_nagle(socket->socket); |
546 | 546 | socket->type = SG_SOCKET_CLIENT;
|
547 | 547 | socket->address = SG_SOCKADDR(ai_addr(addrinfo));
|
548 | 548 | socket->node = addrinfo->node;
|
@@ -708,29 +708,27 @@ SgObject Sg_SocketGetopt(SgSocket *socket, int level, int name, int rsize)
|
708 | 708 | #endif
|
709 | 709 |
|
710 | 710 | #define handleError(who, socket, r) \
|
711 |
| - do { \ |
712 |
| - if ((r) < 0) { \ |
713 |
| - int e = last_error; \ |
714 |
| - socket->lastError = e; \ |
715 |
| - switch (e) { \ |
716 |
| - case EINTR: \ |
717 |
| - continue; \ |
718 |
| - case EPIPE: \ |
719 |
| - if (flags & MSG_NOSIGNAL) { \ |
720 |
| - return 0; \ |
721 |
| - } \ |
722 |
| - break; \ |
723 |
| - case NON_BLOCKING_CASE: \ |
724 |
| - case ETIMEDOUT:/* Windows, maybe we should raise an error here*/ \ |
725 |
| - /* most probably non-blocking socket */ \ |
726 |
| - return (r); \ |
| 711 | + if ((r) < 0) { \ |
| 712 | + int e = last_error; \ |
| 713 | + socket->lastError = e; \ |
| 714 | + switch (e) { \ |
| 715 | + case EINTR: \ |
| 716 | + continue; \ |
| 717 | + case EPIPE: \ |
| 718 | + if (flags & MSG_NOSIGNAL) { \ |
| 719 | + return 0; \ |
727 | 720 | } \
|
728 |
| - raise_socket_error(SG_INTERN(who), \ |
729 |
| - Sg_GetLastErrorMessageWithErrorCode(e), \ |
730 |
| - Sg_MakeConditionSocket(socket), \ |
731 |
| - SG_LIST1(SG_MAKE_INT(e))); \ |
| 721 | + break; \ |
| 722 | + case NON_BLOCKING_CASE: \ |
| 723 | + case ETIMEDOUT:/* Windows, maybe we should raise an error here*/ \ |
| 724 | + /* most probably non-blocking socket */ \ |
| 725 | + return (r); \ |
732 | 726 | } \
|
733 |
| - } while (0) |
| 727 | + raise_socket_error(SG_INTERN(who), \ |
| 728 | + Sg_GetLastErrorMessageWithErrorCode(e), \ |
| 729 | + Sg_MakeConditionSocket(socket), \ |
| 730 | + SG_LIST1(SG_MAKE_INT(e))); \ |
| 731 | + } \ |
734 | 732 |
|
735 | 733 | long Sg_SocketReceive(SgSocket *socket, uint8_t *data, long size, int flags)
|
736 | 734 | {
|
@@ -776,6 +774,7 @@ long Sg_SocketSend(SgSocket *socket, uint8_t *data, long size, int flags)
|
776 | 774 | data += ret;
|
777 | 775 | size -= ret;
|
778 | 776 | }
|
| 777 | + flush_tcp(socket->socket); |
779 | 778 | return sizeSent;
|
780 | 779 | }
|
781 | 780 |
|
@@ -870,7 +869,6 @@ SgObject Sg_SocketAccept(SgSocket *socket)
|
870 | 869 | break;
|
871 | 870 | }
|
872 | 871 | }
|
873 |
| - disable_nagle(fd); |
874 | 872 | return make_socket(fd, SG_SOCKET_SERVER,
|
875 | 873 | make_sockaddr(addrlen, (struct sockaddr *)&addr, TRUE));
|
876 | 874 | }
|
|
0 commit comments