Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions include/tinycsocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#ifndef TINYCSOCKET_INTERNAL_H_
#define TINYCSOCKET_INTERNAL_H_

static const char* const TCS_VERSION_TXT = "v0.3.81";
static const char* const TCS_VERSION_TXT = "v0.3.82";
extern const char* const TCS_LICENSE_TXT;

/*
Expand Down Expand Up @@ -98,8 +98,8 @@ extern const char* const TCS_LICENSE_TXT;
* - TcsResult tcs_opt_receive_timeout_get(TcsSocket socket, int* out_timeout_ms);
* - TcsResult tcs_opt_linger_set(TcsSocket socket, bool do_linger, int timeout_seconds);
* - TcsResult tcs_opt_linger_get(TcsSocket socket, bool* out_do_linger, int* out_timeout_seconds);
* - TcsResult tcs_opt_ip_no_delay_set(TcsSocket socket, bool use_no_delay);
* - TcsResult tcs_opt_ip_no_delay_get(TcsSocket socket, bool* out_is_no_delay_used);
* - TcsResult tcs_opt_tcp_no_delay_set(TcsSocket socket, bool use_no_delay);
* - TcsResult tcs_opt_tcp_no_delay_get(TcsSocket socket, bool* out_is_no_delay_used);
* - TcsResult tcs_opt_out_of_band_inline_set(TcsSocket socket, bool enable_oob);
* - TcsResult tcs_opt_out_of_band_inline_get(TcsSocket socket, bool* out_is_oob_enabled);
* - TcsResult tcs_opt_priority_set(TcsSocket socket, int priority);
Expand Down Expand Up @@ -1629,7 +1629,7 @@ TcsResult tcs_opt_linger_get(TcsSocket socket, bool* out_do_linger, int* out_tim
* @param[in] use_no_delay set to true to disable Nagle's algorithm (lower latency), false to enable it.
* @return #TCS_SUCCESS if successful, otherwise the error code.
*/
TcsResult tcs_opt_ip_no_delay_set(TcsSocket socket, bool use_no_delay);
TcsResult tcs_opt_tcp_no_delay_set(TcsSocket socket, bool use_no_delay);

/**
* @brief Query whether Nagle's algorithm is disabled on a socket.
Expand All @@ -1638,7 +1638,7 @@ TcsResult tcs_opt_ip_no_delay_set(TcsSocket socket, bool use_no_delay);
* @param[out] out_is_no_delay_used pointer to receive the current setting.
* @return #TCS_SUCCESS if successful, otherwise the error code.
*/
TcsResult tcs_opt_ip_no_delay_get(TcsSocket socket, bool* out_is_no_delay_used);
TcsResult tcs_opt_tcp_no_delay_get(TcsSocket socket, bool* out_is_no_delay_used);

/**
* @brief Enable or disable inline reception of out-of-band data.
Expand Down Expand Up @@ -2471,11 +2471,13 @@ const int32_t TCS_SO_PRIORITY = -1;
#endif

// IP options
const int32_t TCS_TCP_NODELAY = TCP_NODELAY;
const int32_t TCS_IP_MEMBERSHIP_ADD = IP_ADD_MEMBERSHIP;
const int32_t TCS_IP_MEMBERSHIP_DROP = IP_DROP_MEMBERSHIP;
const int32_t TCS_IP_MULTICAST_LOOP = IP_MULTICAST_LOOP;

// TCP options
const int32_t TCS_TCP_NODELAY = TCP_NODELAY;

#if TCS_HAS_AF_PACKET
const int32_t TCS_PACKET_MEMBERSHIP_ADD = PACKET_ADD_MEMBERSHIP;
const int32_t TCS_PACKET_MEMBERSHIP_DROP = PACKET_DROP_MEMBERSHIP;
Expand Down Expand Up @@ -3569,8 +3571,8 @@ TcsResult tcs_opt_linger_get(TcsSocket socket, bool* do_linger, int* timeout_sec
return sts;
}

// tcs_opt_ip_no_delay_set() is defined in tinycsocket_common.c
// tcs_opt_ip_no_delay_get() is defined in tinycsocket_common.c
// tcs_opt_tcp_no_delay_set() is defined in tinycsocket_common.c
// tcs_opt_tcp_no_delay_get() is defined in tinycsocket_common.c
// tcs_opt_out_of_band_inline_set() is defined in tinycsocket_common.c
// tcs_opt_out_of_band_inline_get() is defined in tinycsocket_common.c
// tcs_opt_priority_set() is defined in tinycsocket_common.c
Expand Down Expand Up @@ -4494,11 +4496,13 @@ const int32_t TCS_SO_OOBINLINE = SO_OOBINLINE;
const int32_t TCS_SO_PRIORITY = -1;

// IP options
const int32_t TCS_TCP_NODELAY = TCP_NODELAY;
const int32_t TCS_IP_MEMBERSHIP_ADD = IP_ADD_MEMBERSHIP;
const int32_t TCS_IP_MEMBERSHIP_DROP = IP_DROP_MEMBERSHIP;
const int32_t TCS_IP_MULTICAST_LOOP = IP_MULTICAST_LOOP;

// TCP options
const int32_t TCS_TCP_NODELAY = TCP_NODELAY;

// ######## Internal Helpers ########

static TcsResult wsaerror2retcode(int wsa_error)
Expand Down Expand Up @@ -5578,8 +5582,8 @@ TcsResult tcs_opt_linger_get(TcsSocket socket, bool* do_linger, int* timeout_sec
return sts;
}

// tcs_opt_ip_no_delay_set() is defined in tinycsocket_common.c
// tcs_opt_ip_no_delay_get() is defined in tinycsocket_common.c
// tcs_opt_tcp_no_delay_set() is defined in tinycsocket_common.c
// tcs_opt_tcp_no_delay_get() is defined in tinycsocket_common.c
// tcs_opt_out_of_band_inline_set() is defined in tinycsocket_common.c
// tcs_opt_out_of_band_inline_get() is defined in tinycsocket_common.c
// tcs_opt_priority_set() is defined in tinycsocket_common.c
Expand Down Expand Up @@ -6993,22 +6997,22 @@ TcsResult tcs_opt_receive_buffer_size_get(TcsSocket socket, size_t* receive_buff
// tcs_opt_linger_set() is defined in OS specific files
// tcs_opt_linger_get() is defined in OS specific files

TcsResult tcs_opt_ip_no_delay_set(TcsSocket socket, bool use_no_delay)
TcsResult tcs_opt_tcp_no_delay_set(TcsSocket socket, bool use_no_delay)
{
if (socket == TCS_SOCKET_INVALID)
return TCS_ERROR_INVALID_ARGUMENT;

int b = use_no_delay ? 1 : 0;
return tcs_opt_set(socket, TCS_SOL_IP, TCS_TCP_NODELAY, &b, sizeof(b));
return tcs_opt_set(socket, TCS_SOL_TCP, TCS_TCP_NODELAY, &b, sizeof(b));
}

TcsResult tcs_opt_ip_no_delay_get(TcsSocket socket, bool* is_no_delay_used)
TcsResult tcs_opt_tcp_no_delay_get(TcsSocket socket, bool* is_no_delay_used)
{
if (socket == TCS_SOCKET_INVALID || is_no_delay_used == NULL)
return TCS_ERROR_INVALID_ARGUMENT;
int b = 0;
size_t s = sizeof(b);
TcsResult sts = tcs_opt_get(socket, TCS_SOL_IP, TCS_TCP_NODELAY, &b, &s);
TcsResult sts = tcs_opt_get(socket, TCS_SOL_TCP, TCS_TCP_NODELAY, &b, &s);
*is_no_delay_used = b;
return sts;
}
Expand Down
8 changes: 4 additions & 4 deletions src/tinycsocket_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,22 +828,22 @@ TcsResult tcs_opt_receive_buffer_size_get(TcsSocket socket, size_t* receive_buff
// tcs_opt_linger_set() is defined in OS specific files
// tcs_opt_linger_get() is defined in OS specific files

TcsResult tcs_opt_ip_no_delay_set(TcsSocket socket, bool use_no_delay)
TcsResult tcs_opt_tcp_no_delay_set(TcsSocket socket, bool use_no_delay)
{
if (socket == TCS_SOCKET_INVALID)
return TCS_ERROR_INVALID_ARGUMENT;

int b = use_no_delay ? 1 : 0;
return tcs_opt_set(socket, TCS_SOL_IP, TCS_TCP_NODELAY, &b, sizeof(b));
return tcs_opt_set(socket, TCS_SOL_TCP, TCS_TCP_NODELAY, &b, sizeof(b));
}

TcsResult tcs_opt_ip_no_delay_get(TcsSocket socket, bool* is_no_delay_used)
TcsResult tcs_opt_tcp_no_delay_get(TcsSocket socket, bool* is_no_delay_used)
{
if (socket == TCS_SOCKET_INVALID || is_no_delay_used == NULL)
return TCS_ERROR_INVALID_ARGUMENT;
int b = 0;
size_t s = sizeof(b);
TcsResult sts = tcs_opt_get(socket, TCS_SOL_IP, TCS_TCP_NODELAY, &b, &s);
TcsResult sts = tcs_opt_get(socket, TCS_SOL_TCP, TCS_TCP_NODELAY, &b, &s);
*is_no_delay_used = b;
return sts;
}
Expand Down
10 changes: 5 additions & 5 deletions src/tinycsocket_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#ifndef TINYCSOCKET_INTERNAL_H_
#define TINYCSOCKET_INTERNAL_H_

static const char* const TCS_VERSION_TXT = "v0.3.81";
static const char* const TCS_VERSION_TXT = "v0.3.82";
extern const char* const TCS_LICENSE_TXT;

/*
Expand Down Expand Up @@ -92,8 +92,8 @@ extern const char* const TCS_LICENSE_TXT;
* - TcsResult tcs_opt_receive_timeout_get(TcsSocket socket, int* out_timeout_ms);
* - TcsResult tcs_opt_linger_set(TcsSocket socket, bool do_linger, int timeout_seconds);
* - TcsResult tcs_opt_linger_get(TcsSocket socket, bool* out_do_linger, int* out_timeout_seconds);
* - TcsResult tcs_opt_ip_no_delay_set(TcsSocket socket, bool use_no_delay);
* - TcsResult tcs_opt_ip_no_delay_get(TcsSocket socket, bool* out_is_no_delay_used);
* - TcsResult tcs_opt_tcp_no_delay_set(TcsSocket socket, bool use_no_delay);
* - TcsResult tcs_opt_tcp_no_delay_get(TcsSocket socket, bool* out_is_no_delay_used);
* - TcsResult tcs_opt_out_of_band_inline_set(TcsSocket socket, bool enable_oob);
* - TcsResult tcs_opt_out_of_band_inline_get(TcsSocket socket, bool* out_is_oob_enabled);
* - TcsResult tcs_opt_priority_set(TcsSocket socket, int priority);
Expand Down Expand Up @@ -1623,7 +1623,7 @@ TcsResult tcs_opt_linger_get(TcsSocket socket, bool* out_do_linger, int* out_tim
* @param[in] use_no_delay set to true to disable Nagle's algorithm (lower latency), false to enable it.
* @return #TCS_SUCCESS if successful, otherwise the error code.
*/
TcsResult tcs_opt_ip_no_delay_set(TcsSocket socket, bool use_no_delay);
TcsResult tcs_opt_tcp_no_delay_set(TcsSocket socket, bool use_no_delay);

/**
* @brief Query whether Nagle's algorithm is disabled on a socket.
Expand All @@ -1632,7 +1632,7 @@ TcsResult tcs_opt_ip_no_delay_set(TcsSocket socket, bool use_no_delay);
* @param[out] out_is_no_delay_used pointer to receive the current setting.
* @return #TCS_SUCCESS if successful, otherwise the error code.
*/
TcsResult tcs_opt_ip_no_delay_get(TcsSocket socket, bool* out_is_no_delay_used);
TcsResult tcs_opt_tcp_no_delay_get(TcsSocket socket, bool* out_is_no_delay_used);

/**
* @brief Enable or disable inline reception of out-of-band data.
Expand Down
8 changes: 5 additions & 3 deletions src/tinycsocket_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,13 @@ const int32_t TCS_SO_PRIORITY = -1;
#endif

// IP options
const int32_t TCS_TCP_NODELAY = TCP_NODELAY;
const int32_t TCS_IP_MEMBERSHIP_ADD = IP_ADD_MEMBERSHIP;
const int32_t TCS_IP_MEMBERSHIP_DROP = IP_DROP_MEMBERSHIP;
const int32_t TCS_IP_MULTICAST_LOOP = IP_MULTICAST_LOOP;

// TCP options
const int32_t TCS_TCP_NODELAY = TCP_NODELAY;

#if TCS_HAS_AF_PACKET
const int32_t TCS_PACKET_MEMBERSHIP_ADD = PACKET_ADD_MEMBERSHIP;
const int32_t TCS_PACKET_MEMBERSHIP_DROP = PACKET_DROP_MEMBERSHIP;
Expand Down Expand Up @@ -1271,8 +1273,8 @@ TcsResult tcs_opt_linger_get(TcsSocket socket, bool* do_linger, int* timeout_sec
return sts;
}

// tcs_opt_ip_no_delay_set() is defined in tinycsocket_common.c
// tcs_opt_ip_no_delay_get() is defined in tinycsocket_common.c
// tcs_opt_tcp_no_delay_set() is defined in tinycsocket_common.c
// tcs_opt_tcp_no_delay_get() is defined in tinycsocket_common.c
// tcs_opt_out_of_band_inline_set() is defined in tinycsocket_common.c
// tcs_opt_out_of_band_inline_get() is defined in tinycsocket_common.c
// tcs_opt_priority_set() is defined in tinycsocket_common.c
Expand Down
8 changes: 5 additions & 3 deletions src/tinycsocket_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,13 @@ const int32_t TCS_SO_OOBINLINE = SO_OOBINLINE;
const int32_t TCS_SO_PRIORITY = -1;

// IP options
const int32_t TCS_TCP_NODELAY = TCP_NODELAY;
const int32_t TCS_IP_MEMBERSHIP_ADD = IP_ADD_MEMBERSHIP;
const int32_t TCS_IP_MEMBERSHIP_DROP = IP_DROP_MEMBERSHIP;
const int32_t TCS_IP_MULTICAST_LOOP = IP_MULTICAST_LOOP;

// TCP options
const int32_t TCS_TCP_NODELAY = TCP_NODELAY;

// ######## Internal Helpers ########

static TcsResult wsaerror2retcode(int wsa_error)
Expand Down Expand Up @@ -1234,8 +1236,8 @@ TcsResult tcs_opt_linger_get(TcsSocket socket, bool* do_linger, int* timeout_sec
return sts;
}

// tcs_opt_ip_no_delay_set() is defined in tinycsocket_common.c
// tcs_opt_ip_no_delay_get() is defined in tinycsocket_common.c
// tcs_opt_tcp_no_delay_set() is defined in tinycsocket_common.c
// tcs_opt_tcp_no_delay_get() is defined in tinycsocket_common.c
// tcs_opt_out_of_band_inline_set() is defined in tinycsocket_common.c
// tcs_opt_out_of_band_inline_get() is defined in tinycsocket_common.c
// tcs_opt_priority_set() is defined in tinycsocket_common.c
Expand Down
56 changes: 56 additions & 0 deletions tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,62 @@ TEST_CASE("TCS_SO_OOBINLINE")
REQUIRE(tcs_lib_cleanup() == TCS_SUCCESS);
}

TEST_CASE("TCS_TCP_NODELAY")
{
// Setup
REQUIRE(tcs_lib_init() == TCS_SUCCESS);

// Given
TcsSocket socket_false = TCS_SOCKET_INVALID;
TcsSocket socket_true = TCS_SOCKET_INVALID;
TcsSocket socket_null = TCS_SOCKET_INVALID;

CHECK(tcs_socket(&socket_false, TCS_FAMILY_IPV4, TCS_SOCKET_STREAM, TCS_PROTOCOL_IP_TCP) == TCS_SUCCESS);
CHECK(tcs_socket(&socket_true, TCS_FAMILY_IPV4, TCS_SOCKET_STREAM, TCS_PROTOCOL_IP_TCP) == TCS_SUCCESS);

// When
CHECK(tcs_opt_tcp_no_delay_set(socket_false, false) == TCS_SUCCESS);
CHECK(tcs_opt_tcp_no_delay_set(socket_true, true) == TCS_SUCCESS);
CHECK(tcs_opt_tcp_no_delay_set(socket_null, true) == TCS_ERROR_INVALID_ARGUMENT);

// Then
bool socket_false_value = true;
bool socket_true_value = false;
bool socket_null_value = false;
CHECK(tcs_opt_tcp_no_delay_get(socket_false, &socket_false_value) == TCS_SUCCESS);
CHECK(tcs_opt_tcp_no_delay_get(socket_true, &socket_true_value) == TCS_SUCCESS);
CHECK(tcs_opt_tcp_no_delay_get(socket_null, &socket_null_value) == TCS_ERROR_INVALID_ARGUMENT);
CHECK(tcs_opt_tcp_no_delay_get(socket_true, NULL) == TCS_ERROR_INVALID_ARGUMENT);

CHECK(socket_false_value == false);
CHECK(socket_true_value == true);

// The option must end up as TCP_NODELAY on the TCP level, verify through the raw option API
int native_false = -1;
int native_true = -1;
size_t native_size = sizeof(native_false);
CHECK(tcs_opt_get(socket_false, TCS_SOL_TCP, TCS_TCP_NODELAY, &native_false, &native_size) == TCS_SUCCESS);
native_size = sizeof(native_true);
CHECK(tcs_opt_get(socket_true, TCS_SOL_TCP, TCS_TCP_NODELAY, &native_true, &native_size) == TCS_SUCCESS);
CHECK(native_false == 0);
CHECK(native_true != 0);

// Toggling back must clear it again
CHECK(tcs_opt_tcp_no_delay_set(socket_true, false) == TCS_SUCCESS);
socket_true_value = true;
CHECK(tcs_opt_tcp_no_delay_get(socket_true, &socket_true_value) == TCS_SUCCESS);
CHECK(socket_true_value == false);
native_true = -1;
native_size = sizeof(native_true);
CHECK(tcs_opt_get(socket_true, TCS_SOL_TCP, TCS_TCP_NODELAY, &native_true, &native_size) == TCS_SUCCESS);
CHECK(native_true == 0);

// Clean up
CHECK(tcs_close(&socket_false) == TCS_SUCCESS);
CHECK(tcs_close(&socket_true) == TCS_SUCCESS);
REQUIRE(tcs_lib_cleanup() == TCS_SUCCESS);
}

TEST_CASE("Simple Multicast Add Membership")
{
// Setup
Expand Down
Loading