How to connect () fail and install errno in EADDRINUSE

I'm writing some code and critical at some point you need to install the TCP-connection using connect().

I delve into the POSIX manpages to make sure my code is fully compatible with POSIX and should write unit tests covering all possible cases of errors.

Given this document , I do not understand what the following means:

EADDRINUSE Try to establish a connection that uses addresses that are already in use.

At first glance, I thought that I could be caused by the lack of an ephemeral port, but this error is reported EADDRNOTAVAIL(which I successfully called in the unit test).

Specifically, what does this mean? What condition can lead to this error? I understand the semantics of the errors bind(), but can connect()increase it?

+6
source share
2 answers

My feeling, although this is a hunch, is that this error is for non-TCP sockets, in particular for UNIX sockets - AF_UNIX (also known as AF_LOCAL)

Linux connect () mangpage puts it a little differently than the one you linked:

EADDRINUSE The local address is already in use.

Using the word "Local" led me to a unix manpage that says

EADDRINUSE                               .

+1

, , :

, connect() , , AF_UNIX, .

, .

0

Source: https://habr.com/ru/post/1016283/


All Articles