mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-30 00:00:16 +01:00
freertos: have lwip choose the cancel pipe port
Rather than a magic port, let's have lwip pick the port for the UDP cancel "pipe", so no chance of conflict.
This commit is contained in:
parent
2d4f1045d1
commit
d1c84587bc
1 changed files with 21 additions and 2 deletions
|
@ -30,11 +30,15 @@ lws_plat_pipe_create(struct lws *wsi)
|
||||||
struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi];
|
struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi];
|
||||||
struct sockaddr_in *si = &wsi->a.context->frt_pipe_si;
|
struct sockaddr_in *si = &wsi->a.context->frt_pipe_si;
|
||||||
lws_sockfd_type *fd = pt->dummy_pipe_fds;
|
lws_sockfd_type *fd = pt->dummy_pipe_fds;
|
||||||
|
socklen_t sl;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* There's no pipe abstraction on lwip / freertos... use a UDP socket
|
* There's no pipe abstraction on lwip / freertos... use a UDP socket
|
||||||
* listening on 127.0.0.1:54321 and send a byte to it from a second UDP
|
* listening on 127.0.0.1:xxxx and send a byte to it from a second UDP
|
||||||
* socket to cancel the wait.
|
* socket to cancel the wait.
|
||||||
|
*
|
||||||
|
* Set the port to 0 at the bind, so lwip will choose a free one in the
|
||||||
|
* ephemeral range for us.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fd[0] = socket(AF_INET, SOCK_DGRAM, 0);
|
fd[0] = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
@ -53,11 +57,26 @@ lws_plat_pipe_create(struct lws *wsi)
|
||||||
|
|
||||||
si->sin_family = AF_INET;
|
si->sin_family = AF_INET;
|
||||||
si->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
si->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||||
si->sin_port = htons(54321);
|
si->sin_port = 0;
|
||||||
|
|
||||||
if (bind(fd[0], (const struct sockaddr *)si, sizeof(*si)) < 0)
|
if (bind(fd[0], (const struct sockaddr *)si, sizeof(*si)) < 0)
|
||||||
goto bail;
|
goto bail;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Query the socket to set context->frt_pipe_si to the full sockaddr it
|
||||||
|
* wants to be addressed by, including the port that lwip chose.
|
||||||
|
*
|
||||||
|
* Afterwards, we can use this prepared sockaddr stashed in the context
|
||||||
|
* to trigger the "pipe" without any other preliminaries.
|
||||||
|
*/
|
||||||
|
|
||||||
|
sl = sizeof(*si);
|
||||||
|
if (getsockname(fd[0], (struct sockaddr *)si, &sl))
|
||||||
|
goto bail;
|
||||||
|
|
||||||
|
lwsl_info("%s: cancel UDP skt port %d\n", __func__,
|
||||||
|
ntohs(si->sin_port));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
|
|
Loading…
Add table
Reference in a new issue