Hi Daniel,
in theory you need not share the $SOCK, you can just use it in your threads, if
you have declared it before starting them. However, this does not work on
windows (at least in my experiments) with IO::Socket. You have to dig out the
plain sockets, which work (with some caveats) in a threaded env.
If this is the way you would go, I may give you some further hints. If you need
to stick to IO::Socket, this will not help you.
Dietmar
-----Ursprüngliche Nachricht-----
Von: Daniel McBrearty [mailto:[EMAIL PROTECTED]
Gesendet: Fr 27.10.2006 11:59
An: [email protected]
Cc:
Betreff: sharing access to a socket
Hi
I have an app I'm writing which runs as a background process,
communicating with the main app over a localhost socket. It's a little
server.
the basic code looks like this:
<SNIP>
my $SOCK;
my $sock = new IO::Socket::INET ....
$SOCK = $sock.accept();
while (1) {
my $line;
while ($line = <$SOCK>) {
# process line ...
sockout($response);
}
}
sub sockout{ print $SOCK shift.$CRLF; }
<?SNIP>
and this works fine.
Now I want to run a thread inside this app that sends back info
regularly. It needs to run in a seperate thread, and be startable and
stoppable, which I have working. I don't care if the responses from
the main thread and the reporter thread lines are mixed up ... ie
OK
report : 27
OK
Ok
report : 89
is fine.
So I try these changes ... :
my $SOCK :shared;
.
.
.
sub sockout {
my $r = shift;
lock ($SOCK);
print $SOCK $r.$CRLF;
}
and just call sockout from the reporter thread. But I get this error:
"Invalid value for shared scalar" when it hits $SOCK =
$sock.accept(); ... and I can see why in the threads::shared docs
so my q is : how do I share access to the socket between threads in
the simplest way?
thanks perlers!
--
Daniel McBrearty
email : danielmcbrearty at gmail.com
www.engoi.com : the multi - language vocab trainer
BTW : 0873928131
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs