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
13 changes: 13 additions & 0 deletions service/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,19 @@ if(MOQ_BUILD_TESTS)
${PROJECT_SOURCE_DIR}/tests/unit)
add_test(NAME endpoint_keepalive_default
COMMAND test_endpoint_keepalive_default)

add_executable(test_endpoint_socket_buffer_default
tests/test_endpoint_socket_buffer_default.c)
target_link_libraries(test_endpoint_socket_buffer_default PRIVATE
moq-service-ka-test-internals moq::core Threads::Threads
${_MOQ_SERVICE_FACADE_LIBS})
target_compile_definitions(test_endpoint_socket_buffer_default PRIVATE
${_MOQ_SERVICE_FACADE_DEFS})
target_include_directories(test_endpoint_socket_buffer_default PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${PROJECT_SOURCE_DIR}/tests/unit)
add_test(NAME endpoint_socket_buffer_default
COMMAND test_endpoint_socket_buffer_default)
endif()

if(MOQ_BUILD_PICO_WT_MANAGED)
Expand Down
6 changes: 6 additions & 0 deletions service/src/endpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,12 @@ static moq_result_t ep_create_pq(moq_endpoint_t *ep,
if (cfg->struct_size >= offsetof(moq_endpoint_cfg_t, send_queue_cap_bytes) +
sizeof(cfg->send_queue_cap_bytes))
fc.send_queue_cap_bytes = cfg->send_queue_cap_bytes;
#ifdef __linux__
/* The default UDP receive buffer (about 208 KB) overflows at media rates.
* Linux caps the request at net.core.rmem_max without failing. macOS
* refuses a size above kern.ipc.maxsockbuf, so other systems keep theirs. */
fc.socket_buffer_bytes = 8u * 1024u * 1024u;
#endif
moq_pq_threaded_t *fac = NULL;
moq_result_t crc = moq_pq_threaded_create(&fc, &fac);
if (crc < 0) return crc;
Expand Down
72 changes: 72 additions & 0 deletions service/tests/test_endpoint_socket_buffer_default.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Service picoquic socket buffer default: on Linux, the raw-threaded client
* that the service endpoint builds must ask for 8 MB UDP socket buffers
* (socket_buffer_bytes), so a burst does not overflow the kernel's default
* receive buffer of about 208 KB. Elsewhere it must leave the system default
* (0), because macOS refuses a size above kern.ipc.maxsockbuf and the socket
* would not open.
*
* It uses the same seam as test_endpoint_keepalive_default.c: the endpoint
* object set this binary links calls the recorder below in place of
* moq_pq_threaded_create, which forwards to the real create. Nothing listens
* on the port, and destroy() tears the connection down.
*/
#include "endpoint_internal.h"
#include "test_support.h"

#include <moq/picoquic_threaded.h>

#include <stdlib.h>
#include <string.h>

static int failures = 0;

#define DEAD_PEER_URL_QUIC "moqt://127.0.0.1:14454"
#ifdef __linux__
#define WANT_SOCKET_BUFFER_BYTES 8388608u
#else
#define WANT_SOCKET_BUFFER_BYTES 0u
#endif

static unsigned g_calls; /* how often create was reached */
static uint32_t g_buf_bytes; /* socket_buffer_bytes it carried */

moq_result_t moq_test_pq_threaded_create(const moq_pq_threaded_cfg_t *cfg,
moq_pq_threaded_t **out);
moq_result_t moq_test_pq_threaded_create(const moq_pq_threaded_cfg_t *cfg,
moq_pq_threaded_t **out)
{
g_calls++;
g_buf_bytes = cfg->socket_buffer_bytes;
return moq_pq_threaded_create(cfg, out);
}

static moq_bytes_t B(const char *s)
{
moq_bytes_t b = { (const uint8_t *)s, strlen(s) };
return b;
}

int main(void)
{
moq_endpoint_cfg_t c;
moq_endpoint_cfg_init_sized(&c, sizeof(c));
c.url = B(DEAD_PEER_URL_QUIC);
c.protocol = MOQ_TRANSPORT_PROTOCOL_RAW_QUIC;
c.insecure_skip_verify = true;

moq_endpoint_t *ep = NULL;
moq_result_t rc = moq_endpoint_connect(&c, &ep);
MOQ_TEST_CHECK_EQ_INT((int)rc, (int)MOQ_OK);
MOQ_TEST_CHECK(ep != NULL);
if (rc == MOQ_OK && ep != NULL) {
MOQ_TEST_CHECK_EQ_U64((uint64_t)g_calls, 1);
MOQ_TEST_CHECK_EQ_U64((uint64_t)g_buf_bytes, (uint64_t)WANT_SOCKET_BUFFER_BYTES);
moq_endpoint_stop(ep);
moq_endpoint_destroy(ep);
}

if (failures) return 1;
printf("PASS: endpoint_socket_buffer_default\n");
return 0;
}
Loading