Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 18 Feb 2000 12:12:44 -0500 (EST)
From:      Marian Stagarescu <marian@bile.skycache.com>
To:        freebsd-alpha@freebsd.org
Subject:   FD_SET error on 64 bit architecture
Message-ID:  <Pine.NEB.4.05.10002181157100.28545-100000@bile.skycache.com>

next in thread | raw e-mail | index | archive | help
Hello,

I am running FreeBSD 4.0-20000101-CURRENT on a DS-10 Alpha/64 bit and I
am getting an error when trying to FD_SET descriptors with particular
values.

Here is an example:

int fd;
fd_set fdset;
FD_ZERO(&fds);
fd=35;
FD_SET(fd,&fdset);

check: if(FD_ISSET(fd,&fdset)) reports fd unset. 

I was able to identify the cause of the problem (or at least  what I
believe to be the cause);

the macros or FD_SET, FD_ISSET (appended below
from /usr/include/sys/types.h)

work with longs on 8 bytes on alpha-64bit architectures.

having this will result in  a value of 64 for NFDBITS.

Trying to do FD_SET(fd,..) with fd=35 will force a shift 
(1 << fd % NFDBITS)

which translates into 

"shift a 32-bit (the 1 is an int on 32-bit) by 35 bits"

which is shifting 1 out and the result is 0, hence fd unset.

I choose to redefine the FD_SET, FD_ISSET macros to use a (long) 1 instead
of an 1 and this seems to work.

This looks to me as a portability problem to 64-bit arch. Is this correct 
? Does anybody experienced this ? Are there any known problems with
64-bits arch ?

Thanks,
Marian Stagarescu
Cidera, Inc.  




#define NBBY    8               /* number of bits in a byte */

/*
 * Select uses bit masks of file descriptors in longs.  These macros
 * manipulate such bit fields (the filesystem macros use chars).
 * FD_SETSIZE may be defined by the user, but the default here should
 * be enough for most uses.
 */
#ifndef FD_SETSIZE
#define FD_SETSIZE      1024
#endif

typedef long    fd_mask;
#define NFDBITS (sizeof(fd_mask) * NBBY)        /* bits per mask */

#ifndef howmany
#define howmany(x, y)   (((x) + ((y) - 1)) / (y))
#endif
 
typedef struct fd_set {
        fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
} fd_set;

#define FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) %
NFDBITS)))
#define FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) %
NFDBITS)))
#define FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) %
NFDBITS)))
#define FD_COPY(f, t)   bcopy(f, t, sizeof(*(f)))
#define FD_ZERO(p)      bzero(p, sizeof(*(p)))





To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-alpha" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.NEB.4.05.10002181157100.28545-100000>