DNSlib issues?

Matthew Dixon Cowles matt at mondoinfo.com
Wed Jun 13 22:00:53 EDT 2001


On Wed, 13 Jun 2001 23:50:33 GMT, Benjamin Schollnick
<junkster at rochester.rr.com> wrote:

Benjamin,

>If I give an invalid DNS server address in the DNSLIB demo, the App
>waits for keyboard manual entry....(i.e. instead of failing with a
>socket error, the socket seems to be connecting to stdin)...

I don't think that the problem is that the socket is connected
weirdly. It's that the socket is waiting forever for a reply that's
never going to arrive. There's no default timeout on a recv(). Since
the code is a demo, it's pretty reasonable that it doesn't try to
check for lots of error conditions.

> Is there anyway for me to catch this?

Yes, there is. You can use select() from the select module to decide
how long to wait. The thing to do is to change the code that does the
sending and receiving to something like this:

if protocol == 'udp':
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  s.connect((server, port))
  s.send(request)
  # New
  r,w,e=select.select([s],[],[],10) # Timeout 10 seconds
  if len(r)==0:
    print "Too long, I'm bored"
    sys.exit(1)
  # end of new code
  reply = s.recv(1024)

Regards,
Matt



More information about the Python-list mailing list