First, it's necessary to understand the data flow.
The purpose is to take information it learns as a client and in turn repeat it to as a server to its clients.
So the flow is unidirectional?
sub run { for (;;) { my $msg = $connection_to_server->get(); $_->send($msg) for @connections_to_clients; } }
To get parallelism, send simply needs to hand off the work to a thread of some sort (including a separate process).
# Client class sub send { my ($self, $msg) = @_; $self->{work_queue}->enqueue($msg); } sub worker { my ($self) = @_; my $q = $self->{work_queue}; for (;;) { my $msg = $q->dequeue(); ... send $msg ... } }
Whether you use Coro, threads, forks or something else seems very incidental.
You could also use polling, but select loops tend to be complicated. The first I'd want to do is give the select loop the above enqueue/dequeue interface shown above. Might as well just use Coro to save the work.
In reply to Re: A server that has a fool as its client: itself
by ikegami
in thread A server that has a fool as its client: itself
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |