On 01.05.19 21:47, Brandon Noel wrote:
Hi,

We are using lwIP’s (STABLE-2.1.2) non-blocking  BSD socket interface in
an application. Our current setup is two threads which each have their
own socket and are communicating with different peers. Currently if
lwip_send() returns -1 we call getsockopt(SOL_SOCKET, SO_ERROR) to get
the error for that socket. We are unsure about what types of errors lwIP
supports with getsockopt() and how to appropriately handle those errors.

What is the appropriate way to handle getsockopt(SOL_SOCKET, SO_ERROR)
returning a fatal error? Should we call lwip_close()? Is it improper to
call lwip_close() (in other words we should do nothing because of
possible double freeing)? Does it depend on the error type? We also
cannot rely on errno because of race conditions between the two threads.

Calling close is required if you're sure that the socket was valid as
it's not closed internally otherwise. The lwIP pcb *is* freed by the
stack, but not the socket.

In contrast, there's no check that the socket is yours, so if you just
call close() with any integer in the socket range, you could close some
connection. There's no risk of double-free though.

About 'errno': it's more or less mandatory for this to be a per-thread
value, so you might want to implement thread-local storage. Implementing
nonblocking socket programs without errno is rather pointless I guess...

Regards,
Simon

_______________________________________________
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to