|
|
|
@ -3,12 +3,15 @@ |
|
|
|
#include <stdlib.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include <string.h> |
|
|
|
#include <string.h> |
|
|
|
#include <errno.h> |
|
|
|
#include <errno.h> |
|
|
|
|
|
|
|
#ifndef _WIN32 |
|
|
|
#include <unistd.h> |
|
|
|
#include <unistd.h> |
|
|
|
#include <signal.h> |
|
|
|
#include <signal.h> |
|
|
|
#include <sys/socket.h> |
|
|
|
#include <sys/socket.h> |
|
|
|
#include <netinet/in.h> |
|
|
|
#include <netinet/in.h> |
|
|
|
#include <arpa/inet.h> |
|
|
|
#include <arpa/inet.h> |
|
|
|
#include <sys/wait.h> |
|
|
|
#include <sys/wait.h> |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
#include "../lib/platform_compat.h" |
|
|
|
#include "../lib/tcp_io.h" |
|
|
|
#include "../lib/tcp_io.h" |
|
|
|
#include "../lib/u_async.h" |
|
|
|
#include "../lib/u_async.h" |
|
|
|
#include "../lib/ll_queue.h" |
|
|
|
#include "../lib/ll_queue.h" |
|
|
|
@ -20,10 +23,13 @@ |
|
|
|
#define PAYLOAD_SIZE 64 |
|
|
|
#define PAYLOAD_SIZE 64 |
|
|
|
|
|
|
|
|
|
|
|
static int g_ok = 0, g_done = 0; |
|
|
|
static int g_ok = 0, g_done = 0; |
|
|
|
|
|
|
|
#ifndef _WIN32 |
|
|
|
static pid_t echo_pid = 0; |
|
|
|
static pid_t echo_pid = 0; |
|
|
|
|
|
|
|
#endif |
|
|
|
static uint8_t send_buf[PAYLOAD_SIZE]; |
|
|
|
static uint8_t send_buf[PAYLOAD_SIZE]; |
|
|
|
static void* timeout_id = NULL; |
|
|
|
static void* timeout_id = NULL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _WIN32 |
|
|
|
static void echo_server(void) { |
|
|
|
static void echo_server(void) { |
|
|
|
int srv = socket(AF_INET, SOCK_STREAM, 0); |
|
|
|
int srv = socket(AF_INET, SOCK_STREAM, 0); |
|
|
|
if (srv < 0) _exit(1); |
|
|
|
if (srv < 0) _exit(1); |
|
|
|
@ -39,6 +45,7 @@ static void echo_server(void) { |
|
|
|
} |
|
|
|
} |
|
|
|
done: close(cli); close(srv); |
|
|
|
done: close(cli); close(srv); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
static void on_fin_cb(struct tcp_conn* tc, void* arg) { (void)tc; (void)arg; } |
|
|
|
static void on_fin_cb(struct tcp_conn* tc, void* arg) { (void)tc; (void)arg; } |
|
|
|
static void on_error_cb(struct tcp_conn* tc, int err, void* arg) { (void)tc; (void)arg; (void)err; } |
|
|
|
static void on_error_cb(struct tcp_conn* tc, int err, void* arg) { (void)tc; (void)arg; (void)err; } |
|
|
|
@ -63,9 +70,14 @@ int main(void) { |
|
|
|
debug_config_init(); |
|
|
|
debug_config_init(); |
|
|
|
debug_set_level(DEBUG_LEVEL_WARN); |
|
|
|
debug_set_level(DEBUG_LEVEL_WARN); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32 |
|
|
|
|
|
|
|
printf("[SKIP] test_tcp_proxy_server — fork() not available on Windows\n"); |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
#else |
|
|
|
echo_pid = fork(); |
|
|
|
echo_pid = fork(); |
|
|
|
if (echo_pid == 0) { echo_server(); _exit(0); } |
|
|
|
if (echo_pid == 0) { echo_server(); _exit(0); } |
|
|
|
usleep(50000); // даём серверу запуститься
|
|
|
|
usleep(50000); // даём серверу запуститься
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
struct UASYNC* ua = uasync_create(); |
|
|
|
struct UASYNC* ua = uasync_create(); |
|
|
|
if (!ua) return 1; |
|
|
|
if (!ua) return 1; |
|
|
|
@ -115,7 +127,9 @@ int main(void) { |
|
|
|
|
|
|
|
|
|
|
|
tcp_conn_destroy(tc); |
|
|
|
tcp_conn_destroy(tc); |
|
|
|
uasync_destroy(ua, 0); |
|
|
|
uasync_destroy(ua, 0); |
|
|
|
|
|
|
|
#ifndef _WIN32 |
|
|
|
kill(echo_pid, SIGKILL); |
|
|
|
kill(echo_pid, SIGKILL); |
|
|
|
waitpid(echo_pid, NULL, 0); |
|
|
|
waitpid(echo_pid, NULL, 0); |
|
|
|
|
|
|
|
#endif |
|
|
|
return g_ok ? 0 : 1; |
|
|
|
return g_ok ? 0 : 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|