develooper Front page | perl.perl5.porters | Postings from October 2009

Re: Perl select() and fd_set differences

Thread Previous | Thread Next
From:
NormW
Date:
October 21, 2009 15:24
Subject:
Re: Perl select() and fd_set differences
Message ID:
4ADF8A17.3050005@gknw.net
Hi,
The code below caused a 'crash' so I assume there's either a bug or an 
invalid assumption.
This list seems very 'focused'; can anyone suggest a list where coding 
help with Perl C for 'newbies' might be more appropriately found?
TIA,
Norm

NormW wrote:
> G/Afternoon Nicholas,
> Been doing further digging in apidocs and various source code and now 
> have the following (which at least compiles):
> 
> fd_set looks like:
> 
>> typedef struct fd_set
>> {
>>   int   fd_count;
>>   int   fd_array[FD_SETSIZE];
>> } fd_set;
> 
> pp_sselect vars look like:
> 
>>     SV *fd = NULL;
>>     SV *sv = NULL;
>>     NV value;
>>     struct timeval timebuf;
>>     struct timeval *tbuf = &timebuf;
>>     int    maxlen = 0, nfound = 0, i;
>>     fd_set *rdfds = NULL, *wrfds = NULL, *exfds = NULL;
> 
> Since the 3 incoming arrays are largely identical, for the 'canread' 
> array incoming, I have:
> 
>>     if (SP[1] != &PL_sv_undef) {
>>         FD_ZERO(rdfds);
>>         while (av_len((AV *)SP[1]) >= 0) {
>>           fd = (SV*)av_shift((AV *)SP[1]);
>>             FD_SET(SvIV(fd), rdfds);
>>             if (rdfds->fd_count >= FD_SETSIZE)
>>                 DIE(aTHX_ "Too many sockets passed to select(rd): Max 
>> FD_SETSIZE");
>>         }
>>         if (maxlen < rdfds->fd_count)
>>             maxlen = rdfds->fd_count;
>>     }
> 
> The outgoing code for 'canread' I have is:
> 
>>     if (rdfds != NULL) {
>>         av_clear((AV *)SP[1]);
>>         for ( i = 0 ; i < rdfds->fd_count ; i++ ) {
>>             sv_setpviv( fd, rdfds->fd_array[i] );
>>             av_push( (AV *)SP[1], fd );
>>         }
>>     }
> 
> Any feedback regarding the validity and oversights of this process/code 
> would be greatly appreciated!
> 
> Regards,
> Norm
> 


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About