Opened 6 years ago

Closed 5 years ago

#1252 closed defect (fixed)

OSX udp socket, "Socket is already connected (error #56) during sendto"

Reported by: jkordani Owned by: rme
Priority: normal Milestone:
Component: other Version: trunk
Keywords: udp socket send-to Cc: jkordani@…


on osx 10.7.5.

when attempting to call send-to on a socket that already has remote-port/host or local-port set, ccl reports "socket is already connected (error #56) during send-to"

code example to tickle this problem

after evaluating the defparameters calls to create the test vector and the socket, all three of the send-to calls fail with the same problem

Similar problems are encountered in python apparently. see

Change History (5)

comment:1 Changed 6 years ago by rme

What do you think the correct behavior would be?

On OS X, sendto(2) notes that sendto may return EISCONN (56) if a destination address is specified and the socket is already connected. I realize that this seems to conflict with the first sentence of the man page, which says "sendto ... may be used at any time."

comment:2 Changed 6 years ago by jkordani

After reading the man page, I can see how there isn't any explanation of what "at any time" means. In practice it seems that it means "any time before the socket is connected, but not after" where send is specified for use "only after the socket is connected".

So does a call to send-to attempt to reconnect, even if the specified destination was already used to connect the port?

or rather, it seems that in ccl there is no equivalent of the send behavior, i.e. that you can connect a socket ahead of time and issue a send call on it. While i'm sure the ccl layer can infer that the socket is connected already and change the underlying call from send-to to send, i guess linux does this for you and osx doesn't. right?

comment:3 Changed 6 years ago by jkordani

Additionally, the ccl documentation suggests that these calls can be used in this way, hence me reaching this point. So I guess, is it expected to work per the documentation and this is a bug, or there was no expectation that it would work on osx given how it was implemented and the doc should be changed?

comment:4 Changed 6 years ago by rme

  • Owner set to rme

If a UDP socket is connected, and send-to specifies a destination, I believe that it is correct to treat that as an error.

Table 8.14 in the 3rd edition of Unix Network Programming by Stevens, et al. supports this view also, if you believe that book to be a credible source.

It appears that Linux chooses not to treat this case an error.

I think we need to review the socket code and our documentation and make sure that it is clear when a udp socket is connected (by using #_connect) and when it is not.

comment:5 Changed 5 years ago by svspire

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.