You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Stas Bekman <st...@stason.org> on 2004/04/27 10:00:38 UTC

[mp2] changing the socket recv/send interface

I'm thinking to make recv/send perlish, similar to read()/print()

   my $read  = $sock->recv($buf, $len);
   my $wrote = $sock->send($buf, $len);

the only difference will be that we will croak on error. I know I'm going to 
break someone's code but better early than later.

But ideally I'd just have this simple API:

   my $buf   = $sock->recv($len);
   my $wrote = $sock->send($buf);

since modifying the variable that you pass to the function is going to be very 
confusing to many users. We code in perl, not C.

In the first call you can check length of $buf, if you need to know how much 
was read.

In the second call, you don't need to pass the len argument. It's just silly 
to do, since we know it already, and it doesn't cost us anything to retrieve 
it from C.

I'm in favor of the latter API.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] changing the socket recv/send interface

Posted by Stas Bekman <st...@stason.org>.
Unfortunately I've to drop this idea, since when you want to do IO with 
controlled timeout you should be able to get the TIMEUP events trappable. So 
I'll just leave things as they are now :( We may add the simple API later, 
even if through a 3rd party module...

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] changing the socket recv/send interface

Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
>>But ideally I'd just have this simple API:
>>
>>  my $buf   = $sock->recv($len);
>>  my $wrote = $sock->send($buf);
>>
>>since modifying the variable that you pass to the function is going to
>>be very confusing to many users. We code in perl, not C.
> 
> 
> yeah, I think this is better.  I fluxuate between making things a C API
> interface in Perl to making them perlish.  in this case (and probably
> others) it looks like the perl interface is just better :)

:)

heh, talking about C vs. perl, the test still has:

  for (;;)

instead of

  while (1)

:)

>>In the first call you can check length of $buf, if you need to know how
>>much was read.
>>
>>In the second call, you don't need to pass the len argument. It's just
>>silly to do, since we know it already, and it doesn't cost us anything
>>to retrieve it from C.
> 
> 
> you mean we have the length stored in the sv, right?

Yup!

> sounds good to me. make it so, number one ;)

I will. Thanks for the feedback, Geoff!

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] changing the socket recv/send interface

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> But ideally I'd just have this simple API:
> 
>   my $buf   = $sock->recv($len);
>   my $wrote = $sock->send($buf);
> 
> since modifying the variable that you pass to the function is going to
> be very confusing to many users. We code in perl, not C.

yeah, I think this is better.  I fluxuate between making things a C API
interface in Perl to making them perlish.  in this case (and probably
others) it looks like the perl interface is just better :)

> 
> In the first call you can check length of $buf, if you need to know how
> much was read.
> 
> In the second call, you don't need to pass the len argument. It's just
> silly to do, since we know it already, and it doesn't cost us anything
> to retrieve it from C.

you mean we have the length stored in the sv, right?

sounds good to me. make it so, number one ;)

--Geoff

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org