Skip to Content.
Sympa Menu

freetds - Re: [freetds] connect(2) for UDP

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "James K. Lowden" <jklowden AT freetds.org>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] connect(2) for UDP
  • Date: Wed, 17 Dec 2008 10:45:39 -0500

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.

Possible conditions:

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
unsupported.
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.)

--jkl




Archive powered by MHonArc 2.6.24.

Top of Page