Thread IO::Socket::UNIX - Prüfen ob Client mit Socket verbinden
(15 answers)
Opened by mark05 at 2012-04-12 16:27
Das geht mit select genauso wie bei jedem anderen Socket- oder Dateihandle auch. Kleines gekürztes Beispiel:
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 # Create Socket my $socket = IO::Socket:UNIX->new([...]); [...] # Prepare bitvector of filedescriptors to poll my $readable = ''; vec($readable, $socket->fileno, 1) = 1; # Wait up to one second for incoming data given (select($readable, undef, undef, 1.0)) { when (1) { # There is incoming data, so read it $socket->recv([...]); } when (0) { # The call timed out [...] } when (-1) { # There was an error warn "Error waiting for incoming packets: $!"; } } When C++ is your hammer, every problem looks like your thumb.
|