in reply to Re^5: Help designing a threaded service
in thread Help designing a threaded service
With forks (*nix), when you have multiple processes all waiting to accept on a shared socket, when a client connects, *every* listening process receives the connect.That would be horrible, but fortunately it's not true. If multiple processes waiting for a connection on the same socket, when client connects, *only one* listening process accepts connection. Here's a simple example that demonstrates it:
Try to connect to 7777 and you will see that only one process will accept connection. Hence there's no need to have any global mutexes.use 5.010; use strict; use warnings; use IO::Socket::INET; my $sock = IO::Socket::INET->new(LocalPort => 7777, Listen => 10); for (1..3) { my $pid = fork; unless($pid) { my $cli = $sock->accept; say "Process $$ accepted connection from " . $cli->peerport; print while <$cli>; exit 0; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Help designing a threaded service
by BrowserUk (Patriarch) on Jan 26, 2014 at 16:06 UTC | |
by tye (Sage) on Jan 26, 2014 at 18:51 UTC | |
by BrowserUk (Patriarch) on Jan 26, 2014 at 20:05 UTC | |
by zwon (Abbot) on Jan 27, 2014 at 15:14 UTC | |
by BrowserUk (Patriarch) on Jan 27, 2014 at 21:08 UTC | |
by Anonymous Monk on Jan 28, 2014 at 01:22 UTC | |
by BrowserUk (Patriarch) on Jan 28, 2014 at 05:39 UTC | |
|