Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Simultaneously reading from a file and serving data

by grondilu (Pilgrim)
on Feb 27, 2014 at 17:45 UTC ( #1076425=note: print w/ replies, xml ) Need Help??


in reply to Simultaneously reading from a file and serving data

I'm no expert but: can't you just use a fork? I haven't used it for a while but IIRC it's actually not very hard to use and there are several nice examples in perlipc.

Something like:

if (my $pid = fork()) { # network stuff } else { # file stuff }


Comment on Re: Simultaneously reading from a file and serving data
Download Code
Re^2: Simultaneously reading from a file and serving data
by wazoox (Prior) on Feb 27, 2014 at 19:50 UTC
    The problem with a fork is that the %data won't be shared between processes...

      WARNING: I'm afraid this message is actually irrelevant. See EDIT note at the end.

      Well, you can have your two processes communicate with yet another named pipe. I really think you should (re-)read perlipc. There are lots of examples for this kind of stuff. Check out the open() command for instance. You can use it to fork and create a named pipe in the same time. See the "Safe Pipe Opens" section.

      Maybe something like this:

      if (my $pid = open(JSON, '|-') { # database stuff print JSON $json; } else { # this is the child fork. # STDIN here is actually JSON in the other fork. # network stuff my $json = <>; # some more network stuff I guess }

      EDIT I've just realized this wont solve your issue since the child process would block waiting for data from the parent process. It can't do that *AND* act as a network server at the same time. It only moves the blocking problem from one place to an other. So I'm sorry, I don't know.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1076425]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-12-19 02:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (70 votes), past polls