Re: connect(2) for UDP
"Frediano Ziglio" <[email protected]>
| Newsgroups | gmane.comp.db.tds.freetds |
|---|---|
| Message-ID | <[email protected]> |
2008/12/15 James K. Lowden <[email protected]>: > Hello Frediano! > > /* > * Request the instance's port from the server. > * There is no easy way to detect if port is closed so we always try to > * get a reply from server 16 times. > */ > for (num_try = 0; num_try < 16; ++num_try) { > > But there is an easy way: use connect(2) and write(2) instead of sendto! > connect(2) sets errno to ECONNREFUSED if no one is listening to the port, > even for UDP. > > This would let us know immediately if port 1434 is reachable, and could > reduce our retry loop to, say, three tries. > Mmmm... from comments /* * on cluster environment is possible that reply packet came from * different IP so do not filter by ip with connect */ the problem is not that easy... if server has two interfaces configured server reply from a single interface so it can happen that client ask to an interface with a given IP but server reply from another IP, in such situation with connect used recv don't receive server reply :( I think we can solve this problem using two sockets, one connected and another not connected. freddy77