WIP: rewrite the network stack to use libevent

This commit is contained in:
2022-03-09 21:30:51 +02:00
parent d2f43a8620
commit 64596d344c
43 changed files with 415 additions and 2149 deletions

View File

@@ -96,7 +96,6 @@ int total_bytes_written = 0;
BYTE g_bLogLevel = 0;
socket_t tcp_socket = 0;
socket_t udp_socket = 0;
socket_t p2p_socket = 0;
LPFDWATCH main_fdw = NULL;
@@ -617,15 +616,6 @@ int start(int argc, char **argv)
return 0;
}
#ifndef __UDP_BLOCK__
if ((udp_socket = socket_udp_bind(g_szPublicIP, mother_port)) == INVALID_SOCKET)
{
perror("socket_udp_bind: udp_socket");
return 0;
}
#endif
// if internal ip exists, p2p socket uses internal ip, if not use public ip
//if ((p2p_socket = socket_tcp_bind(*g_szInternalIP ? g_szInternalIP : g_szPublicIP, p2p_port)) == INVALID_SOCKET)
if ((p2p_socket = socket_tcp_bind(g_szPublicIP, p2p_port)) == INVALID_SOCKET)
@@ -635,9 +625,6 @@ int start(int argc, char **argv)
}
fdwatch_add_fd(main_fdw, tcp_socket, NULL, FDW_READ, false);
#ifndef __UDP_BLOCK__
fdwatch_add_fd(main_fdw, udp_socket, NULL, FDW_READ, false);
#endif
fdwatch_add_fd(main_fdw, p2p_socket, NULL, FDW_READ, false);
db_clientdesc = DESC_MANAGER::instance().CreateConnectionDesc(main_fdw, db_addr, db_port, PHASE_DBCLIENT, true);
@@ -691,9 +678,6 @@ void destroy()
sys_log(0, "<shutdown> Closing sockets...");
socket_close(tcp_socket);
#ifndef __UDP_BLOCK__
socket_close(udp_socket);
#endif
socket_close(p2p_socket);
sys_log(0, "<shutdown> fdwatch_delete()...");
@@ -815,28 +799,6 @@ int io_loop(LPFDWATCH fdw)
DESC_MANAGER::instance().AcceptP2PDesc(fdw, p2p_socket);
fdwatch_clear_event(fdw, p2p_socket, event_idx);
}
/*
else if (FDW_READ == fdwatch_check_event(fdw, udp_socket, event_idx))
{
char buf[256];
struct sockaddr_in cliaddr;
socklen_t socklen = sizeof(cliaddr);
int iBytesRead;
if ((iBytesRead = socket_udp_read(udp_socket, buf, 256, (struct sockaddr *) &cliaddr, &socklen)) > 0)
{
static CInputUDP s_inputUDP;
s_inputUDP.SetSockAddr(cliaddr);
int iBytesProceed;
s_inputUDP.Process(NULL, buf, iBytesRead, iBytesProceed);
}
fdwatch_clear_event(fdw, udp_socket, event_idx);
}
*/
continue;
}