T
Tresh
Hello !
I'm developping an application for testing purpose which is based on a
HTML page with perlScript.
This application communicates thru sockets (i'm coding both client and
server version of the application)
Basically, it waits for some message and do some actions when the
correct message has been received.
these actions include a reply to the received message.
perlScript is used here to create powerful scenarios, which can be made
by the users of the application.
The main problem here comes from the blocking read of the socket. For
example, a scenario is launched from the HTML interface. This scenario
connects the client socket to a server and then waits for a message
from this socket. When perl executes this, while waiting, the HTML
interface freezes, so we can't click on the "stop button" of the
scenario.
That's the problem.
I'm giving a part of the code :
function testSocket which checks during 100ms if there is some data to
read on the socket.
function waitMsg which calls testSocket and handles a timeout
sub testSocket()
{
# timeout 100 ms
my $timeout = 0.1;
@ready = $sel->can_read($timeout);
if (@ready > 0)
{
foreach $fh (@ready)
{
if ($fh == $sock)
{
return 1; #data ok : will read it
}
else
{
# Maybe we have finished with the socket
$sel->remove($fh);
$fh->close;
}
}
}
return 0;
}
sub waitMsg(;$)
{
#timeout in ms (now must be a multiple of 100)
my $timeout = shift;
my $res = testSocket();
if ($res == 1)
{
return getMsg();
}
else
{
if ($timeout eq "")
{
# no timeout, infinite wait
return waitMsg();
}
else
{
if ($timeout == 0)
{
#timeout !!!
return (-1, "");
}
#recursive call
return waitMsg($timeout - 100);
}
}
The scenario must NOT continue until we have received a message or
until we reach the timeout. But the HTML-page must also NOT freeze so
that we can use the buttons on the page
Any Idea ?
Thanks !
Tresh
I'm developping an application for testing purpose which is based on a
HTML page with perlScript.
This application communicates thru sockets (i'm coding both client and
server version of the application)
Basically, it waits for some message and do some actions when the
correct message has been received.
these actions include a reply to the received message.
perlScript is used here to create powerful scenarios, which can be made
by the users of the application.
The main problem here comes from the blocking read of the socket. For
example, a scenario is launched from the HTML interface. This scenario
connects the client socket to a server and then waits for a message
from this socket. When perl executes this, while waiting, the HTML
interface freezes, so we can't click on the "stop button" of the
scenario.
That's the problem.
I'm giving a part of the code :
function testSocket which checks during 100ms if there is some data to
read on the socket.
function waitMsg which calls testSocket and handles a timeout
sub testSocket()
{
# timeout 100 ms
my $timeout = 0.1;
@ready = $sel->can_read($timeout);
if (@ready > 0)
{
foreach $fh (@ready)
{
if ($fh == $sock)
{
return 1; #data ok : will read it
}
else
{
# Maybe we have finished with the socket
$sel->remove($fh);
$fh->close;
}
}
}
return 0;
}
sub waitMsg(;$)
{
#timeout in ms (now must be a multiple of 100)
my $timeout = shift;
my $res = testSocket();
if ($res == 1)
{
return getMsg();
}
else
{
if ($timeout eq "")
{
# no timeout, infinite wait
return waitMsg();
}
else
{
if ($timeout == 0)
{
#timeout !!!
return (-1, "");
}
#recursive call
return waitMsg($timeout - 100);
}
}
The scenario must NOT continue until we have received a message or
until we reach the timeout. But the HTML-page must also NOT freeze so
that we can use the buttons on the page
Any Idea ?
Thanks !
Tresh