Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I have a server application written to accept data on a socket and spawn a child process using fork(); This applications is meant to accept online traffice to write data to a file for other applications use. I am wondering if there are any known limitations or issues with this type of processing? for example if the 'client' application is sending x amount of data to my listening port are there limitations to the number of child processess that can be kicked off? any comments or insight would be very helpfull!
This is the snippet of code that is handling the incoming connections and parent / child processing.
###################################################################### +########################## # M A I N ###################################################################### +########################## # Wait for a connect from the remote client my $acceptSock; my ($pid, $buf, $bufhdr, $req); while (1) { printf ("%sListening on port $args{p}\n", prHdr()); if (!($acceptSock = $listenSock->accept())) { print "bkpt 1: Accept failed: $!\n" if ($args{d} > 2); next; } # Spawn off a child to handle this connection my $pid = fork(); die "Cannot fork: $!" unless defined($pid); # PID is zero when we're the child if($pid) { print "Parent continues\n" if ($args{d} > 2); next; } printf ("%sAccepted connection from: %s\n", prHdr(), $acceptSock->p +eerhost()); srand(time); # Wait indefinitely for a message while (1) { open (FH, ">>$file"); print "Error reading 2-byte header: $!\n", last if (sysread($acceptSock, $bufhdr, 2) != 2); printf ("%sReceiving request\n", prHdr()); # We got the 2-byte (data length) header my $length = unpack("n", $bufhdr); print "$$: Length from request header = $length\n" if($args{d} > 2); print "Error length ($length) is < e-Header size ($EHDR_SIZE)\n", +last if ($length < $EHDR_SIZE); print "Error reading $length bytes of data: $!\n", last if (sysread($acceptSock, $buf, $length-2) != $length-2); my $msg = join('', $bufhdr, $buf); if($args{d} > 1) { # Got the data, display it &hexDump($bufhdr . $buf); # Got the data, display it &hexDump($bufhdr . $buf); print "\n"; } # Parse the message, creating hashes for the e-Header and ISO mess +age my ($hdr, $req) = &parse8583($bufhdr . $buf); # Dump the e-Header in readable form &printEHdr($hdr,1); if($args{d} && length($req)) { # Dump the individual ISO fields in the request print "ISO Request fields:\n"; for (sort numerically keys %$req) { if ($_ eq "48") { print " $_ =>\n"; &printDE48($req->{$_}); } elsif($_ eq "52") { my ($p1) = unpack("H16", $req->{52}); printf (" $_ => 0x%s\n",$p1); } # ADD processing of DE 127 if ($_ eq "127") { print " $_ =>\n"; &parse127($req->{$_}); } else { print " $_ => '", $req->{$_}, "'\n"; } } print "\n"; } printf("%sSending response\n", prHdr()); syswrite($acceptSock, $msg, length($msg)); close (FH); } printf ("%sChild done, closing socket\n", prHdr()); # Remote connection closed or error occured shutdown($acceptSock, 2); close($acceptSock); exit(0); } # Shouldn't be able to break out of the while(1) close($listenSock); die "Unexpected main loop termination";

In reply to fork processing limitations by djbiv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-19 23:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found