[jdev] Why are we doing math on socket handles?
Bresler, Jonathan
Jonathan.Bresler at usi.net
Mon Apr 4 15:13:53 CDT 2005
Perhaps we can drop the sarcasm. Surely they are enough warts on all of us
To spend the rest of the day pointing them out.
Maxfd is used in select() to tell the operating system the highest numbered
Fd that interests you in __this__ particular call to select(). That may vary
>From call to call. This way the OS does not waste time providing information
On sockets (fd's) that are not of interest to you.
At the same time, each time an new socket is created (less frequently activity
Than calling select() on sockets) you may to maintain the value of maxfd.
Alternatively, you can update maxfd before the system call.
Please read the select() man page for you system.
Regarding the hardcoding of magic values (numbers) into the source, this is
A poor practice that started with the beginning of programming. Each programmer
Must learn not to do this. Doesn’t really seem to be a matter of the language or
System that one uses.
Jonathan
-----Original Message-----
From: jdev-bounces at jabber.org [mailto:jdev-bounces at jabber.org] On Behalf Of Tim Anderson
Sent: Monday, April 04, 2005 4:09 PM
To: 'jdev at jabber.org'
Subject: [jdev] Why are we doing math on socket handles?
in mio_connect:
fd = socket(sa.ss_family,SOCK_STREAM,0)
and in mio_fd
if(fd >= m->maxfd)
{
mio_debug(ZONE,"fd to high");
return -1;
}
I know I'm a stupid windows programmer, but who cares what value the socket
handle is? There's a malloced array that uses the socket handle as an index,
obviously. This just seems inherently silly. There's also a problem in that
SOME of these maximum numbers are configurable:
r->mio = mio_new(r->io_max_fds);
c2s->mio = mio_new(c2s->io_max_fds);
and some are hard coded:
r->mio = mio_new(1023);
s2s->mio = mio_new(1024);
sm->mio = mio_new(1024);
So 1) Why are we doing math on socket handles? 2) I'm assuming adding this
into the configuration files is the right way to work around this problem. I
always thought hard coding numbers in code was bad. I guess that's just a
silly habit picked up by coding in windows instead of unix all these years.
Tim
tima at predator-software.com
_______________________________________________
jdev mailing list
jdev at jabber.org
http://mail.jabber.org/mailman/listinfo/jdev
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.859 / Virus Database: 585 - Release Date: 2/14/2005
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.859 / Virus Database: 585 - Release Date: 2/14/2005
More information about the JDev
mailing list