[freetds] connect(2) for UDP
James K. Lowden
jklowden at freetds.org
Wed Dec 17 10:45:39 EST 2008
Frediano Ziglio wrote:
> > 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.
> * on cluster environment is possible that reply packet came
> from * different IP so do not filter by ip with connect
> I think we can solve this problem using two sockets,
> one connected and another not connected.
1. gethostbyname() fails. Don't try 1434.
2. connect/write/read to 1434 succeeds. Hurrah!
3. connect/write/read to 1434 yields ECONNREFUSED. Named instances
4. connect/write/read to 1434 times out. Host down *or* host responding
from different interface.
Well, first try connected. It's quicker if it works, and it establishes
(#3) whether or not anyone's listening to 1434.
For autodetection, for #4 I would assume the host is down, because
retrying is too slow (especially if it's actually a 5.0 server). But if,
say, freetds.conf had "port = AUTO", then I'd try unconnected UDP. I'm
also tempted to fork(2) and try both at the same time. (The child could
write the results to the parent via a pipe.)
More information about the FreeTDS