Files
utun2/tests/simple_test.c
T

43 lines
1.1 KiB
C

#include "../lib/u_async.h"
#include "../lib/debug_config.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <fcntl.h>
static void test_callback(int fd, void* arg) {
(void)fd; (void)arg;
}
int main() {
debug_config_init();
debug_set_level(DEBUG_LEVEL_TRACE);
debug_set_categories(DEBUG_CATEGORY_ALL);
uasync_t* ua = uasync_create();
if (!ua) return 1;
DEBUG_INFO(DEBUG_CATEGORY_ALL, "=== Simple Corruption Test ===");
// Create just one socket
int sock = socket(AF_INET, SOCK_DGRAM, 0);
DEBUG_INFO(DEBUG_CATEGORY_ALL, "Created socket with fd=%d", sock);
void* id = uasync_add_socket(ua, sock, test_callback, NULL, NULL, NULL);
DEBUG_INFO(DEBUG_CATEGORY_ALL, "Added socket: fd=%d, id=%p", sock, id);
// Check if fd is still correct
struct socket_node* node = (struct socket_node*)id;
DEBUG_INFO(DEBUG_CATEGORY_ALL, "Node fd after add: %d", node->fd);
// Try to remove immediately (no polling)
int result = uasync_remove_socket(ua, id);
DEBUG_INFO(DEBUG_CATEGORY_ALL, "Remove result: %d", result);
close(sock);
uasync_destroy(ua, 0);
return 0;
}