uasync: pass socket name to all add_socket call sites

This commit is contained in:
evgeny committed 2026-09-20 01:13:38 +03:00
1 parent c36cebe357
commit b33caa56b8
31 files changed
+61 -59

No files matched your search

+2 -2
View File
@@ -126,7 +126,7 @@ static void benchmark_with_sockets(void) {
int flags = fcntl(sockets[i], F_GETFL, 0);
fcntl(sockets[i], F_SETFL, flags | O_NONBLOCK);
socket_ids[i] = uasync_add_socket(ua, sockets[i], socket_callback, NULL, NULL, NULL);
socket_ids[i] = uasync_add_socket(ua, sockets[i], socket_callback, NULL, NULL, "bench", NULL);
if (!socket_ids[i]) {
fprintf(stderr, "Failed to add socket %d to uasync\n", i);
for (int j = 0; j <= i; j++) {
@@ -259,7 +259,7 @@ int main(void) {
sockets[i] = socket(AF_INET, SOCK_DGRAM, 0);
int flags = fcntl(sockets[i], F_GETFL, 0);
fcntl(sockets[i], F_SETFL, flags | O_NONBLOCK);
socket_ids[i] = uasync_add_socket(ua, sockets[i], socket_callback, NULL, NULL, NULL);
socket_ids[i] = uasync_add_socket(ua, sockets[i], socket_callback, NULL, NULL, "bench", NULL);
}
printf("Created %d sockets\n\n", NUM_SOCKETS);
+1 -1
View File
@@ -24,7 +24,7 @@ int main() {
int sock = socket(AF_INET, SOCK_DGRAM, 0);
DEBUG_INFO(DEBUG_CATEGORY_SYS, "Created socket with fd=%d", sock);
void* id = uasync_add_socket(ua, sock, test_callback, NULL, NULL, NULL);
void* id = uasync_add_socket(ua, sock, test_callback, NULL, NULL, "test", NULL);
DEBUG_INFO(DEBUG_CATEGORY_SYS, "Added socket: fd=%d, id=%p", sock, id);
// Check if fd is still correct (internal struct socket_node not exposed)
+1 -1
View File
@@ -259,7 +259,7 @@ static int hs_connect(struct hs_ctx* t, struct hs_conn* c, int port) {
socket_close_wrapper(c->fd); c->fd = SOCKET_INVALID; return -1;
}
socket_set_nonblocking(c->fd);
c->socket_id = uasync_add_socket_t(t->ua, c->fd, hs_recv_cb, NULL, NULL, c);
c->socket_id = uasync_add_socket_t(t->ua, c->fd, hs_recv_cb, NULL, NULL, "test_call", c);
if (!c->socket_id) { socket_close_wrapper(c->fd); c->fd = SOCKET_INVALID; return -1; }
return 0;
}
+2 -2
View File
@@ -224,8 +224,8 @@ static int run_scenario(const char* name,
}
/* Добавляем сокеты в uasync */
uasync_add_socket_t(st.ua, st.sock_a, recv_callback_a, NULL, NULL, &st);
uasync_add_socket_t(st.ua, st.sock_b, recv_callback_b, NULL, NULL, &st);
uasync_add_socket_t(st.ua, st.sock_a, recv_callback_a, NULL, NULL, "dummynet_a", &st);
uasync_add_socket_t(st.ua, st.sock_b, recv_callback_b, NULL, NULL, "dummynet_b", &st);
/* Создаем dummynet */
st.dn = dummynet_create(st.ua, "127.0.0.1", LISTEN_PORT);
+1 -1
View File
@@ -251,7 +251,7 @@ static int hr_connect(struct hr_ctx* t, struct hr_conn* c, int port) {
socket_close_wrapper(c->fd); c->fd = SOCKET_INVALID; return -1;
}
socket_set_nonblocking(c->fd);
c->socket_id = uasync_add_socket_t(t->ua, c->fd, hr_recv_cb, NULL, NULL, c);
c->socket_id = uasync_add_socket_t(t->ua, c->fd, hr_recv_cb, NULL, NULL, "test_radio", c);
if (!c->socket_id) { socket_close_wrapper(c->fd); c->fd = SOCKET_INVALID; return -1; }
return 0;
}
+6 -6
View File
@@ -98,7 +98,7 @@ static void mock_accept_cb(socket_t sock, void *arg) {
m->conn_sock = accept(sock, (struct sockaddr *)&sa, &sl);
if (m->conn_sock == SOCKET_INVALID) return;
socket_set_nonblocking(m->conn_sock);
m->conn_id = uasync_add_socket_t(m->ua, m->conn_sock, mock_read_cb, NULL, NULL, m);
m->conn_id = uasync_add_socket_t(m->ua, m->conn_sock, mock_read_cb, NULL, NULL, "mock_conn", m);
}
static int mock_start(struct mock *m, struct UASYNC *ua, int port, uint8_t mode) {
@@ -112,7 +112,7 @@ static int mock_start(struct mock *m, struct UASYNC *ua, int port, uint8_t mode)
a.sin_family = AF_INET; a.sin_addr.s_addr = htonl(INADDR_LOOPBACK); a.sin_port = htons((uint16_t)port);
if (bind(m->listen_sock, (struct sockaddr *)&a, sizeof(a)) < 0) return -1;
if (listen(m->listen_sock, 8) < 0) return -1;
m->listen_id = uasync_add_socket_t(ua, m->listen_sock, mock_accept_cb, NULL, NULL, m);
m->listen_id = uasync_add_socket_t(ua, m->listen_sock, mock_accept_cb, NULL, NULL, "mock_listen", m);
return m->listen_id ? 0 : -1;
}
@@ -200,7 +200,7 @@ static void umock_accept_cb(socket_t sock, void *arg) {
m->ctrl_sock = cs;
m->cstate = 0;
m->cblen = 0;
m->ctrl_id = uasync_add_socket_t(m->ua, cs, umock_ctrl_read_cb, NULL, NULL, m);
m->ctrl_id = uasync_add_socket_t(m->ua, cs, umock_ctrl_read_cb, NULL, NULL, "umock_ctrl", m);
}
// Релей: принять обёрнутую датаграмму, сохранить dst (peer) + payload, отправить эхо с SRC=peer.
@@ -265,7 +265,7 @@ static int umock_start(struct udp_mock *m, struct UASYNC *ua, int listen_port) {
a.sin_family = AF_INET; a.sin_addr.s_addr = htonl(INADDR_LOOPBACK); a.sin_port = htons((uint16_t)listen_port);
if (bind(m->listen_sock, (struct sockaddr *)&a, sizeof(a)) < 0) return -1;
if (listen(m->listen_sock, 8) < 0) return -1;
m->listen_id = uasync_add_socket_t(ua, m->listen_sock, umock_accept_cb, NULL, NULL, m);
m->listen_id = uasync_add_socket_t(ua, m->listen_sock, umock_accept_cb, NULL, NULL, "umock_listen", m);
m->udp_sock = socket(AF_INET, SOCK_DGRAM, 0);
if (m->udp_sock == SOCKET_INVALID) return -1;
@@ -276,7 +276,7 @@ static int umock_start(struct udp_mock *m, struct UASYNC *ua, int listen_port) {
struct sockaddr_in got; socklen_t gl = sizeof(got);
getsockname(m->udp_sock, (struct sockaddr *)&got, &gl);
m->udp_port = ntohs(got.sin_port);
m->udp_id = uasync_add_socket_t(ua, m->udp_sock, umock_udp_read_cb, NULL, NULL, m);
m->udp_id = uasync_add_socket_t(ua, m->udp_sock, umock_udp_read_cb, NULL, NULL, "umock_udp", m);
return (m->listen_id && m->udp_id) ? 0 : -1;
}
@@ -332,7 +332,7 @@ static int test1_noauth_v4(void) {
TASSERT(m.got_connect == 1);
int got = 0;
void *sid = uasync_add_socket_t(ua, g_sock, read_echo_cb, NULL, NULL, &got);
void *sid = uasync_add_socket_t(ua, g_sock, read_echo_cb, NULL, NULL, "echo", &got);
TASSERT(sid != NULL);
uint8_t x = 'A';
send(g_sock, &x, 1, 0);
+5 -5
View File
@@ -361,7 +361,7 @@ static void test_socket_management(void) {
fcntl(sockets[i], F_SETFL, flags | O_NONBLOCK);
/* Add to async */
socket_ids[i] = uasync_add_socket(ua, sockets[i], test_socket_callback, NULL, NULL, &ctx);
socket_ids[i] = uasync_add_socket(ua, sockets[i], test_socket_callback, NULL, NULL, "test", &ctx);
ASSERT_NOT_NULL(socket_ids[i], "Failed to add socket to async");
}
@@ -403,7 +403,7 @@ static void test_error_handling(void) {
ASSERT_EQ(cancel_result, ERR_FAIL, "Should fail with NULL parameters");
/* Test with invalid socket */
void* socket_result = uasync_add_socket(ua, -1, NULL, NULL, NULL, NULL);
void* socket_result = uasync_add_socket(ua, -1, NULL, NULL, NULL, "test_invalid", NULL);
ASSERT_NULL(socket_result, "Should fail with invalid socket");
/* Test callback that simulates errors */
@@ -465,7 +465,7 @@ static void test_concurrent_operations(void) {
for (int i = 0; i < 2; i++) {
int flags = fcntl(sockets[i], F_GETFL, 0);
fcntl(sockets[i], F_SETFL, flags | O_NONBLOCK);
socket_ids[i] = uasync_add_socket(ua, sockets[i], test_socket_callback, NULL, NULL, &socket_ctx);
socket_ids[i] = uasync_add_socket(ua, sockets[i], test_socket_callback, NULL, NULL, "test", &socket_ctx);
ASSERT_NOT_NULL(socket_ids[i], "Failed to add socket to async");
}
@@ -569,7 +569,7 @@ static void test_socket_flags_toggle(void) {
test_context_t read_ctx = {0};
test_context_t write_ctx = {0};
void* s_id = uasync_add_socket(ua, sockets[0], test_socket_callback, NULL, NULL, &read_ctx);
void* s_id = uasync_add_socket(ua, sockets[0], test_socket_callback, NULL, NULL, "test", &read_ctx);
ASSERT_NOT_NULL(s_id, "Failed to add socket");
/* Write data — read callback should fire on sockets[0] */
@@ -597,7 +597,7 @@ static void test_socket_flags_toggle(void) {
ASSERT_TRUE(read_ctx.callback_count > before_count, "Read callback should fire after re-enable");
/* Test write flag toggle — socket is always writable (newly created), so write callback fires */
void* s_id2 = uasync_add_socket(ua, sockets[1], NULL, test_socket_callback, NULL, &write_ctx);
void* s_id2 = uasync_add_socket(ua, sockets[1], NULL, test_socket_callback, NULL, "test", &write_ctx);
ASSERT_NOT_NULL(s_id2, "Failed to add socket for write test");
uasync_poll(ua, 1);
+4 -4
View File
@@ -89,7 +89,7 @@ static void test_socket_callback(int fd, void* arg) {
uint64_t start_time = perf_get_time_us();
int sockets_added = 0;
for (int i = 0; i < num_sockets; i++) {
void* id = uasync_add_socket(ua, sockets[i], test_socket_callback, NULL, NULL, NULL);
void* id = uasync_add_socket(ua, sockets[i], test_socket_callback, NULL, NULL, "test", NULL);
if (!id) {
printf("Failed to add socket %d\n", i);
printf("DEBUG: Only added %d sockets before failure\n", sockets_added);
@@ -184,7 +184,7 @@ static void benchmark_high_frequency(void) {
int flags = fcntl(sockets[i], F_GETFL, 0);
fcntl(sockets[i], F_SETFL, flags | O_NONBLOCK);
socket_ids[i] = uasync_add_socket(ua, sockets[i], test_socket_callback, NULL, NULL, NULL);
socket_ids[i] = uasync_add_socket(ua, sockets[i], test_socket_callback, NULL, NULL, "test", NULL);
}
/* Benchmark: Rapid add/remove cycles */
@@ -203,7 +203,7 @@ static void benchmark_high_frequency(void) {
/* Add them back */
for (int i = 0; i < num_sockets; i++) {
socket_ids[i] = uasync_add_socket(ua, sockets[i], test_socket_callback, NULL, NULL, NULL);
socket_ids[i] = uasync_add_socket(ua, sockets[i], test_socket_callback, NULL, NULL, "test", NULL);
}
/* Poll once per cycle */
@@ -246,7 +246,7 @@ static void benchmark_scalability(void) {
int flags = fcntl(sockets[i], F_GETFL, 0);
fcntl(sockets[i], F_SETFL, flags | O_NONBLOCK);
socket_ids[i] = uasync_add_socket(ua, sockets[i], test_socket_callback, NULL, NULL, NULL);
socket_ids[i] = uasync_add_socket(ua, sockets[i], test_socket_callback, NULL, NULL, "test", NULL);
}
/* Measure poll time */
+1 -1
View File
@@ -138,7 +138,7 @@ int main(void) {
la.sin_addr.s_addr = inet_addr("127.0.0.1");
if (bind(lsock, (struct sockaddr*)&la, sizeof(la)) < 0) { printf("[FAIL] bind: %s\n", strerror(errno)); goto cleanup; }
if (listen(lsock, 1024) < 0) { printf("[FAIL] listen: %s\n", strerror(errno)); goto cleanup; }
uasync_add_socket(g_ua, lsock, on_accept_cb, NULL, NULL, NULL);
uasync_add_socket(g_ua, lsock, on_accept_cb, NULL, NULL, "test_listen", NULL);
for (int i = 0; i < CHILDREN; i++) {
pid_t pid = fork();
+1 -1
View File
@@ -172,7 +172,7 @@ int main(void) {
struct sockaddr_in ea = {.sin_family = AF_INET, .sin_addr = {.s_addr = inet_addr("127.0.0.1")}, .sin_port = htons(UDP_ECHO_PORT)};
if (bind(g_echo_sock, (struct sockaddr*)&ea, sizeof(ea)) < 0) { printf("[FAIL] echo bind: %s\n", strerror(errno)); goto done; }
socket_set_nonblocking(g_echo_sock);
g_echo_id = uasync_add_socket_t(ua, g_echo_sock, udp_echo_cb, NULL, NULL, NULL);
g_echo_id = uasync_add_socket_t(ua, g_echo_sock, udp_echo_cb, NULL, NULL, "udp_echo", NULL);
g_to_id = uasync_set_timeout(ua, 100, NULL, monitor, "mon");
void* to_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS * 10, NULL, test_timeout, "to");