Skip to content

Commit

Permalink
feat: activate TCP_NO_DELAY
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Oct 9, 2024
1 parent 3e1532a commit c603432
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ set(Z_FEATURE_LINK_UDP_UNICAST 1 CACHE STRING "Toggle UDP unicast links")
set(Z_FEATURE_MULTICAST_TRANSPORT 1 CACHE STRING "Toggle multicast transport")
set(Z_FEATURE_UNICAST_TRANSPORT 1 CACHE STRING "Toggle unicast transport")
set(Z_FEATURE_RAWETH_TRANSPORT 0 CACHE STRING "Toggle raw ethernet transport")
set(Z_FEATURE_TCP_NODELAY 1 CACHE STRING "Toggle TCP_NODELAY")

add_compile_definitions("Z_BUILD_DEBUG=$<CONFIG:Debug>")
message(STATUS "Building with feature confing:\n\
Expand Down
1 change: 1 addition & 0 deletions include/zenoh-pico/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#define Z_FEATURE_UNICAST_TRANSPORT 1
#define Z_FEATURE_FRAGMENTATION 1
#define Z_FEATURE_ENCODING_VALUES 1
#define Z_FEATURE_TCP_NODELAY 1
// End of CMake generation

/*------------------ Runtime configuration properties ------------------*/
Expand Down
1 change: 1 addition & 0 deletions include/zenoh-pico/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#define Z_FEATURE_UNICAST_TRANSPORT @Z_FEATURE_UNICAST_TRANSPORT@
#define Z_FEATURE_FRAGMENTATION @Z_FEATURE_FRAGMENTATION@
#define Z_FEATURE_ENCODING_VALUES @Z_FEATURE_ENCODING_VALUES@
#define Z_FEATURE_TCP_NODELAY @Z_FEATURE_TCP_NODELAY@
// End of CMake generation

/*------------------ Runtime configuration properties ------------------*/
Expand Down
7 changes: 7 additions & 0 deletions src/system/arduino/esp32/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ z_result_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t re
ret = _Z_ERR_GENERIC;
}

#if Z_FEATURE_TCP_NODELAY == 1
if ((ret == _Z_RES_OK) &&
(setsockopt(sock->_fd, IPPROTO_TCP, TCP_NODELAY, (void *)&optflag, sizeof(optflag)) < 0)) {
ret = _Z_ERR_GENERIC;
}
#endif

#if LWIP_SO_LINGER == 1
struct linger ling;
ling.l_onoff = 1;
Expand Down
7 changes: 7 additions & 0 deletions src/system/espidf/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ z_result_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t re
ret = _Z_ERR_GENERIC;
}

#if Z_FEATURE_TCP_NODELAY == 1
if ((ret == _Z_RES_OK) &&
(setsockopt(sock->_fd, IPPROTO_TCP, TCP_NODELAY, (void *)&optflag, sizeof(optflag)) < 0)) {
ret = _Z_ERR_GENERIC;
}
#endif

#if LWIP_SO_LINGER == 1
struct linger ling;
ling.l_onoff = 1;
Expand Down
8 changes: 7 additions & 1 deletion src/system/unix/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <net/if.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
Expand Down Expand Up @@ -71,7 +72,12 @@ z_result_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t re
(setsockopt(sock->_fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&flags, sizeof(flags)) < 0)) {
ret = _Z_ERR_GENERIC;
}

#if Z_FEATURE_TCP_NODELAY == 1
if ((ret == _Z_RES_OK) &&
(setsockopt(sock->_fd, IPPROTO_TCP, TCP_NODELAY, (void *)&flags, sizeof(flags)) < 0)) {
ret = _Z_ERR_GENERIC;
}
#endif
struct linger ling;
ling.l_onoff = 1;
ling.l_linger = Z_TRANSPORT_LEASE / 1000;
Expand Down
7 changes: 7 additions & 0 deletions src/system/windows/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ z_result_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t re
ret = _Z_ERR_GENERIC;
}

#if Z_FEATURE_TCP_NODELAY == 1
if ((ret == _Z_RES_OK) &&
(setsockopt(sock->_sock._fd, IPPROTO_TCP, TCP_NODELAY, (void *)&flags, sizeof(flags)) < 0)) {
ret = _Z_ERR_GENERIC;
}
#endif

struct linger ling;
ling.l_onoff = 1;
ling.l_linger = Z_TRANSPORT_LEASE / 1000;
Expand Down
9 changes: 9 additions & 0 deletions src/system/zephyr/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <sys/socket.h>
#include <zephyr/net/net_if.h>

#include "zenoh-pico/collections/string.h"
#include "zenoh-pico/config.h"
Expand Down Expand Up @@ -68,6 +69,14 @@ z_result_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t re
// ret = _Z_ERR_GENERIC;
}

#if Z_FEATURE_TCP_NODELAY == 1
int optflag = 1;
if ((ret == _Z_RES_OK) &&
(setsockopt(sock->_fd, IPPROTO_TCP, TCP_NODELAY, (void *)&optflag, sizeof(optflag)) < 0)) {
ret = _Z_ERR_GENERIC;
}
#endif

#if LWIP_SO_LINGER == 1
struct linger ling;
ling.l_onoff = 1;
Expand Down

0 comments on commit c603432

Please sign in to comment.