picotcp: close connecting sockets when notified

This commit is contained in:
Flyinghead 2020-11-26 14:08:37 +01:00
parent 93dc87f17f
commit d485da19b7
1 changed files with 16 additions and 14 deletions

View File

@ -184,8 +184,6 @@ static void read_from_dc_socket(pico_socket *pico_sock, sock_t nat_sock)
static void tcp_callback(uint16_t ev, struct pico_socket *s) static void tcp_callback(uint16_t ev, struct pico_socket *s)
{ {
int r = 0;
if (ev & PICO_SOCK_EV_RD) if (ev & PICO_SOCK_EV_RD)
{ {
auto it = tcp_sockets.find(s); auto it = tcp_sockets.find(s);
@ -202,7 +200,6 @@ static void tcp_callback(uint16_t ev, struct pico_socket *s)
if (ev & PICO_SOCK_EV_CONN) if (ev & PICO_SOCK_EV_CONN)
{ {
uint32_t ka_val = 0;
struct pico_ip4 orig; struct pico_ip4 orig;
uint16_t port; uint16_t port;
char peer[30]; char peer[30];
@ -221,7 +218,7 @@ static void tcp_callback(uint16_t ev, struct pico_socket *s)
//printf("Connection established from %s:%d to %08x:%d\n", peer, short_be(port), sock_a->local_addr.ip4.addr, short_be(sock_a->local_port)); //printf("Connection established from %s:%d to %08x:%d\n", peer, short_be(port), sock_a->local_addr.ip4.addr, short_be(sock_a->local_port));
pico_socket_setoption(sock_a, PICO_TCP_NODELAY, &yes); pico_socket_setoption(sock_a, PICO_TCP_NODELAY, &yes);
/* Set keepalive options */ /* Set keepalive options */
// ka_val = 5; // uint32_t ka_val = 5;
// pico_socket_setoption(sock_a, PICO_SOCKET_OPT_KEEPCNT, &ka_val); // pico_socket_setoption(sock_a, PICO_SOCKET_OPT_KEEPCNT, &ka_val);
// ka_val = 30000; // ka_val = 30000;
// pico_socket_setoption(sock_a, PICO_SOCKET_OPT_KEEPIDLE, &ka_val); // pico_socket_setoption(sock_a, PICO_SOCKET_OPT_KEEPIDLE, &ka_val);
@ -270,15 +267,22 @@ static void tcp_callback(uint16_t ev, struct pico_socket *s)
if (ev & PICO_SOCK_EV_FIN) { if (ev & PICO_SOCK_EV_FIN) {
auto it = tcp_sockets.find(s); auto it = tcp_sockets.find(s);
if (it == tcp_sockets.end()) if (it != tcp_sockets.end())
{
INFO_LOG(MODEM, "PICO_SOCK_EV_FIN: Unknown socket: remote port %d", short_be(s->remote_port));
}
else
{ {
closesocket(it->second); closesocket(it->second);
tcp_sockets.erase(it); tcp_sockets.erase(it);
} }
else
{
auto it2 = tcp_connecting_sockets.find(s);
if (it2 != tcp_connecting_sockets.end())
{
closesocket(it2->second);
tcp_connecting_sockets.erase(it2);
}
else
INFO_LOG(MODEM, "PICO_SOCK_EV_FIN: Unknown socket: remote port %d", short_be(s->remote_port));
}
} }
if (ev & PICO_SOCK_EV_ERR) { if (ev & PICO_SOCK_EV_ERR) {
@ -670,9 +674,7 @@ static bool pico_thread_running = false;
static void *pico_thread_func(void *) static void *pico_thread_func(void *)
{ {
struct pico_ip4 ipaddr, netmask, zero = { struct pico_ip4 ipaddr;
0
};
if (!pico_stack_inited) if (!pico_stack_inited)
{ {
@ -729,7 +731,7 @@ static void *pico_thread_func(void *)
memset(&saddr, 0, sizeof(saddr)); memset(&saddr, 0, sizeof(saddr));
saddr.sin_family = AF_INET; saddr.sin_family = AF_INET;
saddr.sin_addr.s_addr = INADDR_ANY; saddr.sin_addr.s_addr = INADDR_ANY;
for (int i = 0; i < sizeof(games_udp_ports) / sizeof(uint16_t); i++) for (u32 i = 0; i < sizeof(games_udp_ports) / sizeof(uint16_t); i++)
{ {
uint16_t port = short_be(games_udp_ports[i]); uint16_t port = short_be(games_udp_ports[i]);
sock_t sockfd = find_udp_socket(port); sock_t sockfd = find_udp_socket(port);
@ -746,7 +748,7 @@ static void *pico_thread_func(void *)
} }
} }
for (int i = 0; i < sizeof(games_tcp_ports) / sizeof(uint16_t); i++) for (u32 i = 0; i < sizeof(games_tcp_ports) / sizeof(uint16_t); i++)
{ {
uint16_t port = short_be(games_tcp_ports[i]); uint16_t port = short_be(games_tcp_ports[i]);
saddr.sin_port = port; saddr.sin_port = port;