Changeset 28776
- Timestamp:
- 2013-12-18T12:53:06+13:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gs2-extensions/tdb-edit/trunk/src/perllib/SocketsSwimmingThreadPoolServer.pm
r28775 r28776 2 2 # @url https://github.com/macnod/DcServer 3 3 # @readme http://donnieknows.com/blog/perl-sockets-swimming-thread-pool 4 5 # One lurking issue with the ThreadPoolServer is that several threads don't get 6 # a chance to return before the server shuts down. In a perfect world they'd 7 # all get a chance to notice the 'stop' flag has been set and thusly 8 # stop. However, it is only by chance this happens as most will spend most of 9 # their lives either blocked listening to a socket (accept_requests) or blocked 10 # waiting to dequeue a message (request_handlers). Possible solutions, such as 11 # interupts, have problems of their own - interrupting mid-read of a socket 12 # could be bad. Since this is non-fatal, and non-trivial to fix, I'm just 13 # leaving it for now. 4 14 5 15 package SocketsSwimmingThreadPoolServer; … … 28 38 LocalPort => $param{port} || 8191}, 29 39 thread_count => $param{thread_count} || 10, 30 main_yield => $param{main_yield} || 5,40 main_yield => $param{main_yield} || 1, 31 41 main_cb => $param{main_cb} || sub {}, 32 42 done_cb => $param{done_cb} || sub {}, … … 68 78 sub stop 69 79 { 70 my $self = shift;80 my $self = shift; 71 81 $stop= 1; 72 82 } … … 94 104 if (!defined $lsocket || !$lsocket) 95 105 { 96 print STDERR "Error! Can't create listerner socket so server can't start (trying again in 1 second). Error message: \"" . $! . "\"\n"; 106 print STDERR "Warning! Can't create listener socket so server can't start (trying again in 1 second).\n"; 107 print STDERR "Error message: \"" . $! . "\"\n\n"; 97 108 sleep(1); 98 109 } … … 162 173 $closed_queue->enqueue($n); 163 174 } 164 165 # Shouldn't join() detached threads?166 # Properly rejoin thread167 # Newer versions of module thread168 #if (defined $self->can('is_joinable'))169 #{170 # print "[debug] using newer thread->is_joinable... ";171 # if ($self->is_joinable())172 # {173 # $self->join();174 # print "joined\n";175 # }176 # else177 # {178 # print "not joinable\n";179 # }180 #}181 #else182 #{183 # print "[debug] using newer thread->is_detached... ";184 # my $thread = threads->self();185 # if (!$thread->is_detached())186 # {187 # $thread->join();188 # print "joined\n";189 # }190 # else191 # {192 # print "not detached\n";193 # }194 #}195 175 } 196 176
Note:
See TracChangeset
for help on using the changeset viewer.