I am writing a network client application which simply receives some signals from the server and returns responses.
The problem is when a forked child process is trying to write to the socket on the second call, IO::Socket::SSL simply closes the connection.
Though, the first time it's called ( tick() ), it doesn't break the connection and returns a healthy response.
The problem exists:
1)
only on Linux, it works fine on Windows.
2)
only with IO::Socket::SSL, it works fine with IO::Socket::INET
minimized code to reproduce the problem:
use strict;
use warnings;
use IO::Socket::SSL qw(debug4);
my $_pid;
my $connection = IO::Socket::SSL->new(
PeerHost => 'local.btc-node',
PeerPort => 7566,
Proto=> 'tcp',
Timeout => 8,
SSL_verify_mode => 0x00
) or die($!);
while(<$connection>)
{
if(/action1/)
{
# do something, no problem
}
elsif(/tick\s+([^\d\s\t]+)/)
{
my $currency = $1;
tick ($connection, $currency);
}
}
sub tick {
my $socket = shift;
my $currency = shift;
if ($_pid = fork)
{
waitpid($_pid, 0);
}
else
{
if (fork)
{
exit;
}
else
{
my $response =`tick $currency 2>&1 3>&1`;
$socket->print($response . "\n"); # without this line $con
+nection doesn't break on the second call
exit;
}
}
}
I suppose there is a socket reference being missed, or something similar.
What am I doing wrong?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.