48 lines
1.4 KiB
C
48 lines
1.4 KiB
C
#include "../lib/u_async.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() {
|
|
uasync_t* ua = uasync_create();
|
|
if (!ua) return 1;
|
|
|
|
printf("=== Debug Performance Test ===\n");
|
|
|
|
// Test 1: Normal add/remove
|
|
int sock1 = socket(AF_INET, SOCK_DGRAM, 0);
|
|
void* id1 = uasync_add_socket(ua, sock1, test_callback, NULL, NULL, NULL);
|
|
printf("Added socket %d: id=%p\n", sock1, id1);
|
|
|
|
size_t alloc1, free1, alloc2, free2;
|
|
uasync_get_stats(ua, &alloc1, &free1, &alloc2, &free2);
|
|
printf("After add: timers %zu/%zu, sockets %zu/%zu\n", alloc1, free1, alloc2, free2);
|
|
|
|
uasync_remove_socket(ua, id1);
|
|
printf("Removed socket %d\n", sock1);
|
|
|
|
uasync_get_stats(ua, &alloc1, &free1, &alloc2, &free2);
|
|
printf("After remove: timers %zu/%zu, sockets %zu/%zu\n", alloc1, free1, alloc2, free2);
|
|
|
|
close(sock1);
|
|
|
|
// Test 2: Failed add
|
|
int sock2 = 9999; // Invalid socket
|
|
void* id2 = uasync_add_socket(ua, sock2, test_callback, NULL, NULL, NULL);
|
|
printf("Tried to add invalid socket %d: id=%p\n", sock2, id2);
|
|
|
|
uasync_get_stats(ua, &alloc1, &free1, &alloc2, &free2);
|
|
printf("After failed add: timers %zu/%zu, sockets %zu/%zu\n", alloc1, free1, alloc2, free2);
|
|
|
|
uasync_destroy(ua, 0);
|
|
printf("Destroyed uasync\n");
|
|
|
|
return 0;
|
|
}
|