[33042] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4318 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 28 09:09:17 2014

Date: Fri, 28 Nov 2014 06:09:03 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 28 Nov 2014     Volume: 11 Number: 4318

Today's topics:
    Re: [Q] How does a sub know it is called during compila <bauhaus@futureapps.invalid>
    Re: answers sackyhack@yahoo.com.au
    Re: answers <rweikusat@mobileactivedefense.com>
        half-blocking sockets <luca_remove@alice.it>
    Re: half-blocking sockets <gravitalsun@hotmail.foo>
    Re: half-blocking sockets <whynot@pozharski.name>
    Re: half-blocking sockets <gamo@telecable.es>
        Sockets. Threads, Demons...confused. <luca_remove@alice.it>
    Re: Sockets. Threads, Demons...confused. <news@todbe.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 26 Nov 2014 16:06:14 +0100
From: "G.B." <bauhaus@futureapps.invalid>
Subject: Re: [Q] How does a sub know it is called during compilation?
Message-Id: <m54q8n$vla$1@dont-email.me>

On 25.11.14 15:22, Peter Makholm wrote:
> "G.B." <bauhaus@futureapps.invalid> writes:
>
>> As first approximation, I am trying the following sub:
>>
>> sub is_BEGIN_in_caller
>> {
>
> Since Perl 5.14.0 there is a ${^GLOBAL_PHASE}

Thanks to all for the suggestions.  Unfortunately, I'm stuck
with Perl 5.10.0. But I'll tweak a test installation for
trying solutions in all cases I can think of, injecting errors
and finding the elephant in Africa mathematically.



------------------------------

Date: Wed, 26 Nov 2014 04:17:48 -0800 (PST)
From: sackyhack@yahoo.com.au
Subject: Re: answers
Message-Id: <3069b326-4b37-41c9-ae2b-a5ca6f99f6d6@googlegroups.com>

deez posts are like really old yo. lolz


------------------------------

Date: Wed, 26 Nov 2014 14:53:10 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: answers
Message-Id: <87a93e6mjt.fsf@doppelsaurus.mobileactivedefense.com>

sackyhack@yahoo.com.au writes:
> deez posts are like really old yo. lolz

It's more that you're stuck in the past.



------------------------------

Date: Wed, 26 Nov 2014 16:01:35 -0500
From: Luca <luca_remove@alice.it>
Subject: half-blocking sockets
Message-Id: <Qcrdw.718130$Ub6.714083@fx20.iad>


Is there a way for me to look at the $clientdata object and understand 
if a non-blocking socket has produced some value or not?

$socket = new IO::Socket::INET (
     LocalHost => '127.0.0.1',
     LocalPort => '1055',
     Proto => 'tcp',
     Listen => 1,
     Reuse => 1,
     # Blocking => 1
) or die "Oops: $@ \n";

print "Waiting for the Client.\n";

$clientsocket = $socket->accept();

while (1) {

   while ($clientdata = <$clientsocket>;) {

       #print Dumper($clientdata);
       if ($clientdata) {...}

Thanks


------------------------------

Date: Thu, 27 Nov 2014 00:58:52 +0200
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: half-blocking sockets
Message-Id: <m55lvl$2qa4$1@news.ntua.gr>

On 26/11/2014 23:01, Luca wrote:
>
> Is there a way for me to look at the $clientdata object and understand
> if a non-blocking socket has produced some value or not?
>
> $socket = new IO::Socket::INET (
>      LocalHost => '127.0.0.1',
>      LocalPort => '1055',
>      Proto => 'tcp',
>      Listen => 1,
>      Reuse => 1,
>      # Blocking => 1
> ) or die "Oops: $@ \n";
>
> print "Waiting for the Client.\n";
>
> $clientsocket = $socket->accept();
>
> while (1) {
>
>    while ($clientdata = <$clientsocket>;) {
>
>        #print Dumper($clientdata);
>        if ($clientdata) {...}
>
> Thanks


if you read the $clientdata then you have a value from the socket!
your while loop is blocking.
by the way have a look at the module  Net-Server


------------------------------

Date: Thu, 27 Nov 2014 09:28:04 +0200
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: half-blocking sockets
Message-Id: <slrnm7dkk4.bri.whynot@orphan.zombinet>

with <Qcrdw.718130$Ub6.714083@fx20.iad> Luca wrote:

> Is there a way for me to look at the $clientdata object and understand
> if a non-blocking socket has produced some value or not?

Yes.  Its name is select(2).  Perl has IO::Select readily available.

p.s.  Also:

	perldoc perlipc

You might appreciate it.

*CUT*

-- 
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom


------------------------------

Date: Thu, 27 Nov 2014 22:58:11 +0100
From: gamo <gamo@telecable.es>
Subject: Re: half-blocking sockets
Message-Id: <m586pf$h6d$1@speranza.aioe.org>

El 26/11/14 a las 22:01, Luca escribió:
>
> Is there a way for me to look at the $clientdata object and understand
> if a non-blocking socket has produced some value or not?
>

Multitasking servers are covered in Chapter 16 of the Camel book.
Sorry, I have at hand only the second edition.
HTH

-- 
http://www.telecable.es/personales/gamo/


------------------------------

Date: Wed, 26 Nov 2014 10:10:22 -0500
From: Luca <luca_remove@alice.it>
Subject: Sockets. Threads, Demons...confused.
Message-Id: <y3mdw.9245$Mq4.4212@fx25.iad>


Hi, I used to program Perl many years ago (and the fact that it was Perl 
4 isn't helping particularly :).

I am writing the spec for a Unix Demon process  and a corresponding CLI 
utility to interact with it. The tool will be implemented in C/C++, but 
I wanted to impress the engineering team with a fully working proof of 
concept in Perl. Things are not so simple as I was assuming, though. A 
few hours of hacking later, I am sort of stuck with issues that could 
probably greatly benefit from feedback from those who have specific 
experience in the field.
The Client will send in-band directives and the data through a TCP 
socket to the server. The server will respond with processed data (and 
in-band directives) though the same socket. The two programs often get 
stuck waiting for one another to send content down the pipe.

Questions:

- My server.pl is using this code to await data and directives:

while (1) {
   $clientsocket = $socket->accept();
   while ($clientdata = <$clientsocket>) {
      :

Is there a way to tell the system to do something else if no data is coming?

- Would it make sense to spawn sub-processes to handle each connecting 
client? What's the best way to achieve it? Proc::Daemon? should I look 
into threads?
Will I need to pass a reference to the socket to each sub-process/thread?

- Since the in-band directives effectively implement a protocol, I'll 
probably need to manage the state of both client and server at all 
times, to avoid that the two process get stuck waiting on one another. 
Is there a Perl module that helps with that?

I know this is a lot of stuff. Thanks in advance to those who can share 
their advice/experience...



------------------------------

Date: Wed, 26 Nov 2014 22:14:45 -0800
From: "$Bill" <news@todbe.com>
Subject: Re: Sockets. Threads, Demons...confused.
Message-Id: <m56fgj$ott$1@dont-email.me>

On 11/26/2014 07:10, Luca wrote:
>
> Hi, I used to program Perl many years ago (and the fact that it was Perl 4 isn't helping particularly :).
>
> I am writing the spec for a Unix Demon process  and a corresponding CLI utility to interact with it. The tool will be implemented in C/C++, but I wanted to impress the engineering team with a fully working proof of concept in Perl. Things are not so simple as I was assuming, though. A few hours of hacking later, I am sort of stuck with issues that could probably greatly benefit from feedback from those who have specific experience in the field.
> The Client will send in-band directives and the data through a TCP socket to the server. The server will respond with processed data (and in-band directives) though the same socket. The two programs often get stuck waiting for one another to send content down the pipe.
>
> Questions:
>
> - My server.pl is using this code to await data and directives:
>
> while (1) {
>    $clientsocket = $socket->accept();
>    while ($clientdata = <$clientsocket>) {
>       :
>
> Is there a way to tell the system to do something else if no data is coming?
>
> - Would it make sense to spawn sub-processes to handle each connecting client? What's the best way to achieve it? Proc::Daemon? should I look into threads?
> Will I need to pass a reference to the socket to each sub-process/thread?

open/listen/accept/IO::select/IO::can_read are all your friends.  Since you appear to be on
UNIX, I would think it would be a good idea to fork/exec off a process to handle the
transaction unless it just requires a simple response.

Check perlipc man page for additional insight or code for a simple server that someone
has already written for UNIX.






------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 4318
***************************************


home help back first fref pref prev next nref lref last post