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

Re: Perl select() and fd_set differences

Thread Previous | Thread Next
From:
NormW
Date:
September 28, 2009 14:43
Subject:
Re: Perl select() and fd_set differences
Message ID:
4AC12E05.5000007@gknw.net
G/Morning,
Nicholas Clark wrote:
> Sorry for the delay in replying. I've been busy (and unfortunately still am) -
> I see that you've sent another message to the list, but I've not had time to
> read it (or several others).
> 
> I've attached a copy of your original message to me, that you don't have,
> although it might be a bit late by now. Oops.
> 
> (I don't think that my mailer will let me reply to one message and attach
> another message. Or if it does, it's not obvious to me how)
> 
> Nicholas Clark
> 
> 
> ------------------------------------------------------------------------
> 
> Subject:
> Re: Perl select() and fd_set differences
> From:
> NormW <normw@gknw.net>
> Date:
> Fri, 25 Sep 2009 08:12:55 +1000
> To:
> Nicholas Clark <nick@ccl4.org>
> 
> To:
> Nicholas Clark <nick@ccl4.org>
> 
> Return-path:
> <normw@gknw.net>
> Envelope-to:
> nick@ccl4.org
> Delivery-date:
> Thu, 24 Sep 2009 23:13:07 +0100
> Received:
> from dm.gbnet.net ([194.70.142.30]) by mailbox.flirble.org with esmtps 
> (TLSv1:RC4-SHA:128) (Exim 4.69 (FreeBSD)) (envelope-from 
> <normw@gknw.net>) id 1MqwYk-0006CB-Cf for nick@ccl4.org; Thu, 24 Sep 
> 2009 23:13:06 +0100
> X-IronPort-Anti-Spam-Filtered:
> true
> X-IronPort-Anti-Spam-Result:
> An4BAI6Lu0o9CaiJkWdsb2JhbACbAAEBAQEJCwoHEwO7KIQcBQ
> X-IronPort-AV:
> E=Sophos;i="4.44,447,1249254000"; d="scan'208";a="137063749"
> Received:
> from nskntmtas01p.mx.bigpond.com ([61.9.168.137]) by mx2.flirble.org 
> with ESMTP; 24 Sep 2009 23:13:03 +0100
> Received:
> from nskntotgx02p.mx.bigpond.com ([121.216.29.108]) by 
> nskntmtas01p.mx.bigpond.com with ESMTP id 
> <20090924221252.UQJV10503.nskntmtas01p.mx.bigpond.com@nskntotgx02p.mx.bigpond.com> 
> for <nick@ccl4.org>; Thu, 24 Sep 2009 22:12:52 +0000
> Received:
> from [10.202.65.180] (really [121.216.29.108]) by 
> nskntotgx02p.mx.bigpond.com with ESMTP id 
> <20090924221250.PSWF6148.nskntotgx02p.mx.bigpond.com@[10.202.65.180]> 
> for <nick@ccl4.org>; Thu, 24 Sep 2009 22:12:50 +0000
> Message-ID:
> <4ABBEEE7.2010405@gknw.net>
> User-Agent:
> Thunderbird 2.0.0.23 (Windows/20090812)
> MIME-Version:
> 1.0
> References:
> <4ABADD60.5010408@gknw.net> <20090924090214.GT60303@plum.flirble.org>
> In-Reply-To:
> <20090924090214.GT60303@plum.flirble.org>
> Content-Type:
> text/plain; charset=ISO-8859-1; format=flowed
> Content-Transfer-Encoding:
> 7bit
> X-Authentication-Info:
> Submitted using SMTP AUTH PLAIN at nskntotgx02p.mx.bigpond.com from 
> [121.216.29.108] using ID normanwheeler@bigpond.com at Thu, 24 Sep 2009 
> 22:12:48 +0000
> X-RPD-ScanID:
> Class unknown; VirusThreatLevel unknown, RefID 
> str=0001.0A150201.4ABBEEE3.002C,ss=1,fgs=0
> 
> 
> Hi Nicholas and thanks for replying.
> The code block would of course be conditional, but will write it now as 
> if 'standalone' to keep it readable.
> The vars (at this point) look like:
>>     register I32 i;
>>     NV value;
>>     struct timeval timebuf;
>>     struct timeval *tbuf = &timebuf;
>>     int    maxlen = 0,nfound,fd;
>>     fd_set *rdfds,*wrfds, *exfds;
> 
> Assuming IO::select could (for ^O=='NetWare') pass 3 socket (int) arrays 
> in place of the bit-vectors, then on the incoming side to pp_sselect the 
> (pseudo) code for the first array (canreads) should look something like:
> 
>>     XXX = SP[1];
>>     if (defined XXX && ArrayType) {
>>         FD_ZERO(rdfds);
>>         foreach fd (@XXX) {
>>             FD_SET(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;
>>     }
>>     else
>>         rdfds = NULL;
> 
> I'm not sure if it's possible to modify arrays directly on the stack so 
> this might need to be a POP fetch rather than just a stack read.
> 
> One the outgoing side, the function needs to return (max) 3 socket int 
> arrays, and the (pseudo) should look something look the following part 
> for (canread):
> 
>>     if (rdfds != NULL) {
>>         XXX = ();
>>         for (i = 0 ; i < rdfds->fd_count ; i++) {
>>             push(XXX, rdfds->fd_array[i]);
>>         }
>>         push(SP[1],XXX);
>>     }
>>     else
>>         push(SP[1],'undef');
> 
> Any assistance with replacing the 'pseudo' with 'C' would be greatly 
> appreciated!
> Regards,
> Norm
> 
> Nicholas Clark wrote:
>> On Thu, Sep 24, 2009 at 12:45:52PM +1000, NormW wrote:
>>> Hi all,
>>> Trying to port the ASSP app to NetWare, and found that NetWare has an 
>>> fd_set typedef somewhat different to most:
>>>
>>>> typedef struct fd_set
>>>> {
>>>>   int   fd_count;
>>>>   int   fd_array[FD_SETSIZE];
>>>> } fd_set;
>>>>
>>> where fd_count is the numeric size of the active portion of the 
>>> fd_array for both input and output. It does have the FD_CLR, FD_SET, 
>>> FD_ZERO and FD_ISSET macro's.
>>>
>>> AFAICT this is a 'different' approach to that used by Perl 
>>> pp_sselect(), (pp_sys.c) which uses a bit-map vector method.
>>
>> However IO::Select is implemented using the builtin select, with 
>> parameters
>> conforming to its interface documented in perlfunc.pod, so ultimately 
>> it is
>> just calling down into pp_sselect
>>
>>> Can anyone suggest what changes are needed to get IO::Select working 
>>> with this 'fd_set' structure on Perl (5.8.9)? Any assistance would be 
>>> much appreciated, and a working diff will be made available if I can 
>>> get it working.
>>
>> I'd suggest adding conditionally compiled code to pp_sselect to map 
>> from the
>> interface that Perl-space expects into the structures that NetWare 
>> requires.
>>
>> I assume that this will need 3 local structures, and some 
>> size-constrained
>> copying.
>>
>> Nicholas Clark
>>
Since I'd been able to 'advance' my 'code' a little, I thought I might 
as well send my latest 'effort' rather than 'go backwards'...

As my project doesn't really have a 'schedule' if your other projects 
are more pressing feel free to put this at the bottom of the list.

Have done some further digging in the Perl code and api doc and now have 
the following 'in' and 'out' code blocks:
>     ar = SP[1];
>     if (ar) {
>         FD_ZERO(rdfds);
>         fd = av_pop(ar);
>         while (fd != &PL_sv_undef) {
>             FD_SET(SvIV(fd), rdfds);
>             if (rdfds->fd_count >= FD_SETSIZE)
>                 DIE(aTHX_ "Too many sockets passed to select(rd): Max FD_SETSIZE");
>             fd = av_pop(ar);
>         }
>         if (maxlen < rdfds->fd_count)
>             maxlen = rdfds->fd_count;
>     }
>     else
>         rdfds = NULL;
* 'if (ar)' should check if 'undefined' and at least an empty array, an 
empty array being acceptable and different from 'undef'; if 'undef' and 
NOT an array then a 'bailout' seems necessary, as the current pp_sselect 
tests for strings and updateable;
* api doc says popping an empty array returns 'undef' and I'm assuming 
so does a pop past the end of an array;
* converting from a SV to 'int' is a little unclear.

>     if (rdfds != NULL) {
>         av_clear(ar);
>         for ( i = 0 ; i < rdfds->fd_count ; i++) {
>             av_push(ar, sv_setpviv(fd,rdfds->fd_array[i]));
>         }
>         SP[1] = ar;
>     }
>     else
>         SP[1] = &PL_sv_undef;
* I think this a closer, but again converting from int to SV is fuzzy 
and no means to choose which macro to use.

Cheers,
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