The branch, master has been updated
       via  84a4e23 tests: Add test for TCP_NODELAY setsockopt()
       via  96dbeb7 tests: Add test for TCP_NODELAY getsockopt()
       via  1db6130 swrap: Add support for TCP_NODELAY in getsockopt()
       via  e9e0dac swrap: Add support for TCP_NODELAY in setsockopt()
      from  40b1926 Bump version to 1.1.4

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 84a4e23728a558984f449610b9e84933acfb0515
Author: Andreas Schneider <a...@samba.org>
Date:   Thu Oct 8 11:02:10 2015 +0200

    tests: Add test for TCP_NODELAY setsockopt()
    
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Michael Adam <ob...@samba.org>

commit 96dbeb75f78665cf81a4ef8e3842e819043f8d51
Author: Andreas Schneider <a...@samba.org>
Date:   Mon Sep 14 22:07:09 2015 +0200

    tests: Add test for TCP_NODELAY getsockopt()
    
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Michael Adam <ob...@samba.org>

commit 1db61302b6036bdfabf0e3a1507e0e5573a57368
Author: Andreas Schneider <a...@samba.org>
Date:   Mon Sep 14 22:06:52 2015 +0200

    swrap: Add support for TCP_NODELAY in getsockopt()
    
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Michael Adam <ob...@samba.org>

commit e9e0dac6d719304af8174f4b9119709afe71f508
Author: Andreas Schneider <a...@samba.org>
Date:   Thu Oct 8 10:51:02 2015 +0200

    swrap: Add support for TCP_NODELAY in setsockopt()
    
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Michael Adam <ob...@samba.org>

-----------------------------------------------------------------------

Summary of changes:
 src/socket_wrapper.c                 | 53 ++++++++++++++++++++++++++++++++++++
 tests/test_echo_tcp_socket_options.c | 49 +++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+)


Changeset truncated at 500 lines:

diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 45282ed..aad5f3e 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -248,6 +248,7 @@ struct socket_info
        int connected;
        int defer_connect;
        int pktinfo;
+       int tcp_nodelay;
 
        /* The unix path so we can unlink it on close() */
        struct sockaddr_un un_addr;
@@ -3350,6 +3351,29 @@ static int swrap_getsockopt(int s, int level, int 
optname,
                                               optval,
                                               optlen);
                }
+       } else if (level == IPPROTO_TCP) {
+               switch (optname) {
+#ifdef TCP_NODELAY
+               case TCP_NODELAY:
+                       /*
+                        * This enables sending packets directly out over TCP.
+                        * As a unix socket is doing that any way, report it as
+                        * enabled.
+                        */
+                       if (optval == NULL || optlen == NULL ||
+                           *optlen < (socklen_t)sizeof(int)) {
+                               errno = EINVAL;
+                               return -1;
+                       }
+
+                       *optlen = sizeof(int);
+                       *(int *)optval = si->tcp_nodelay;
+
+                       return 0;
+#endif /* TCP_NODELAY */
+               default:
+                       break;
+               }
        }
 
        errno = ENOPROTOOPT;
@@ -3388,6 +3412,35 @@ static int swrap_setsockopt(int s, int level, int 
optname,
                                       optname,
                                       optval,
                                       optlen);
+       } else if (level == IPPROTO_TCP) {
+               switch (optname) {
+#ifdef TCP_NODELAY
+               case TCP_NODELAY: {
+                       int i;
+
+                       /*
+                        * This enables sending packets directly out over TCP.
+                        * A unix socket is doing that any way.
+                        */
+                       if (optval == NULL || optlen == 0 ||
+                           optlen < (socklen_t)sizeof(int)) {
+                               errno = EINVAL;
+                               return -1;
+                       }
+
+                       i = *discard_const_p(int, optval);
+                       if (i != 0 && i != 1) {
+                               errno = EINVAL;
+                               return -1;
+                       }
+                       si->tcp_nodelay = i;
+
+                       return 0;
+               }
+#endif /* TCP_NODELAY */
+               default:
+                       break;
+               }
        }
 
        switch (si->family) {
diff --git a/tests/test_echo_tcp_socket_options.c 
b/tests/test_echo_tcp_socket_options.c
index f068fb8..dfa46fe 100644
--- a/tests/test_echo_tcp_socket_options.c
+++ b/tests/test_echo_tcp_socket_options.c
@@ -10,6 +10,7 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
+#include <netinet/tcp.h>
 #include <arpa/inet.h>
 #include <netdb.h>
 #include <stdlib.h>
@@ -293,6 +294,51 @@ static void test_bind_ipv6_only(void **state)
 }
 #endif
 
+static void test_sockopt_tcp(void **state)
+{
+       struct torture_address addr = {
+               .sa_socklen = sizeof(struct sockaddr_in),
+       };
+       int opt = -1;
+       socklen_t optlen = sizeof(int);
+       int rc;
+
+       int s;
+
+       (void) state; /* unused */
+
+       s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+       assert_int_not_equal(s, -1);
+
+       addr.sa.in.sin_family = AF_INET;
+       addr.sa.in.sin_port = htons(torture_server_port());
+
+       rc = inet_pton(addr.sa.in.sin_family,
+                      torture_server_address(AF_INET),
+                      &addr.sa.in.sin_addr);
+       assert_int_equal(rc, 1);
+
+       rc = connect(s, &addr.sa.s, addr.sa_socklen);
+       assert_int_equal(rc, 0);
+
+       rc = getsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, &optlen);
+       assert_return_code(rc, errno);
+       assert_int_equal(opt, 0);
+
+       opt = 1; /* Turn on TCP_NODELAY */
+       optlen = sizeof(int);
+       rc = setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, optlen);
+       assert_return_code(rc, errno);
+
+       opt = -1;
+       optlen = sizeof(int);
+       rc = getsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, &optlen);
+       assert_return_code(rc, errno);
+       assert_int_equal(opt, 1);
+
+       close(s);
+}
+
 int main(void) {
        int rc;
 
@@ -311,6 +357,9 @@ int main(void) {
                                                setup_ipv6,
                                                teardown),
 #endif
+               cmocka_unit_test_setup_teardown(test_sockopt_tcp,
+                                               setup_echo_srv_tcp_ipv4,
+                                               teardown),
        };
 
        rc = cmocka_run_group_tests(sockopt_tests, NULL, NULL);


-- 
Socket Wrapper Repository

Reply via email to