lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] Handling Socket Errors


From: Simon Goldschmidt
Subject: Re: [lwip-users] Handling Socket Errors
Date: Fri, 3 May 2019 20:41:13 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1



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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]