Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2003:
[Freeciv-Dev] Re: mingw status (server + lan server bugs)
Home

[Freeciv-Dev] Re: mingw status (server + lan server bugs)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Andreas Røsdal <andrearo@xxxxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: mingw status (server + lan server bugs)
From: Vasco Alexandre Da Silva Costa <vasc@xxxxxxxxxxxxxx>
Date: Tue, 25 Nov 2003 21:28:50 +0000 (WET)

On Tue, 25 Nov 2003, Andreas Røsdal wrote:

> On Tue, 25 Nov 2003, Andreas Røsdal wrote:
> > On Tue, 25 Nov 2003, Vasco Alexandre Da Silva Costa wrote:
> > > On Tue, 25 Nov 2003, Andreas Røsdal wrote:
> > > > On Tue, 25 Nov 2003, Vasco Alexandre Da Silva Costa wrote:
> > > > > On Tue, 25 Nov 2003, Andreas Røsdal wrote:
> > >
> > > > > > I think this is because the socket for UDP multicast is blocking,
> > > > > > even though it's set to be nonblocking.
> > > > > >
> > > > > > This can be fixed by using select(), like it's done several
> > > > > > places in /server/sernet.c.  I can make a patch for this.
> > > > >
> > > > > UDP is connectionless. Make sure you aren't getting bogged down doing
> > > > > a DNS name lookup.
> > > >
> > > > Ok. Here's the patch. The socket is not blocking any more,
> > > > and if DNS lookup fail, then the IP is shown instead.
> > >
> > > Eh no, you didn't understand. gethostbyname calls the resolver and I think
> > > gethostbyaddr calls it too. To make sure you don't block in the resolver,
> > > you need to use the integer address. You can convert a numbers and
> > > dots address (e.g. 190.130.36.2) using inet_addr or inet_aton to integer
> > > address format.  That will not call the resolver.
> > >
> > > Only use resolver calls to get the integer address from a DNS address
> > > (e.g. freeciv.org).
> > >
> > > You should find you do not need to use select at all since UDP is
> > > connectionless.
> >
> > The function blocking is recvfrom(), now gethostbyname().
>
> I meant recvfrom(), *not* gethostbyname().
>
> > How do you get nonblocking sockets without using select(),
> > when my_nonblock() fails?
> >
> > Per, does the patch fix the problem?
> >
> >  Andreas Røsdal

Well yes, certainly it will block in a recvfrom(), even for a
connectionless socket. How can it give you a chunk of data if it has
none? Where it will not block is in sendto(), since it doesn't require
establishing a channel and awaiting confirmation, unlike SOCK_STREAM.

Regarding my_nonblock(), IIRC it sets O_NONBLOCK in the socket. if you
use it in a SOCK_DGRAM, recvfrom() should not block. If a message is
not available in the buffer, the call should return -1 and set errno
to EAGAIN or EWOULDBLOCK.

Using select() or poll() before a read to check for data also does the
trick.

---
Vasco Alexandre da Silva Costa @ Instituto Superior Tecnico, Lisboa



[Prev in Thread] Current Thread [Next in Thread]