[crossplatform] Disconnect Event for Client

Share your advanced PureBasic knowledge/code with the community.
DarkPlayer
Enthusiast
Enthusiast
Posts: 107
Joined: Thu May 06, 2010 11:36 pm

Re: [crossplatform] Disconnect Event for Client

Post by DarkPlayer »

Hi,

this is no error. If you compile the following C code:

Code: Select all

#include <stdio.h>
#include <sys/select.h>

int main(){ 
	printf("Size of FD_SET: %d\n", sizeof(fd_set)); 
}
for 32 and 64 bit, you will see that the size is always 128.

We are using bits and it's irrelevant if we are always using longs(fds_bits.l), like in my code:

Code: Select all

  Structure FD_SET
   fds_bits.l[#__FD_SETSIZE / #__NFDBITS]
  EndStructure
or if you use integers, but then you need to adjust __NFDBITS depending on the size of an integer. But you are right that it would be better to use integers on 64 bit systems, still this is no error just an improvement.

DarkPlayer
auser
Enthusiast
Enthusiast
Posts: 195
Joined: Wed Sep 06, 2006 6:59 am

Re: [crossplatform] Disconnect Event for Client

Post by auser »

DarkPlayer wrote:for 32 and 64 bit, you will see that the size is always 128
Yes, the final size because even the size of type fd_mask changes. 32*4 = 16*8 regarding size but not regarding usage (if you would use the array manually yourself). fds_bits[17] = 1 would segfault on linux using C on 64bit while it's ok on 32 bit.
However you use FD_SET for feeding that afterwards anyway so I don't say that it's not working in any case. It just looks similar like the stuff in the headerfile (8*sizeof()) but in fact is different. 8*sizeof(LONG) is 32 on 32 bit and 64bit PB.

Code: Select all

#include <stdio.h>
#include <sys/select.h>

int main(){
   printf("Array could contain %d objects with sizeof %d bytes\n",__FD_SETSIZE / __NFDBITS,sizeof(__fd_mask));
}
Post Reply