Thread IO::Socket::UNIX - Prüfen ob Client mit Socket verbinden (15 answers)
Opened by mark05 at 2012-04-12 16:27

murphy
 2012-04-12 23:50
#157452 #157452
User since
2004-07-19
1776 Artikel
HausmeisterIn
[Homepage]
user image
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.

View full thread IO::Socket::UNIX - Prüfen ob Client mit Socket verbinden