Silicondust / libhdhomerun

Silicondust library and cli utility for controlling HDHomeRun tuners
GNU Lesser General Public License v2.1
110 stars 44 forks source link

Ensure that errno is set correctly after hdhomerun_sock_connect #16

Open tmm1 opened 6 years ago

tmm1 commented 6 years ago

Makes sure that errno is set correctly after hdhomerun_sock_connect returns, which makes it possible for the caller to notify the user about the exact error condition.

tmm1 commented 6 years ago

I've seen and used the "call connect() again after poll/select" pattern before, which is why I implemented it here.

But according to the linux connect(2) man page, another alternative is to use getsockopt to get the connection status:

After select(2) indicates writability, use getsockopt(2) to read the
SO_ERROR option at level SOL_SOCKET to determine whether
connect() completed successfully (SO_ERROR is zero) or
unsuccessfully (SO_ERROR is one of the usual error codes
listed here, explaining the reason for the failure).