1Socket(3)             User Contributed Perl Documentation            Socket(3)
2
3
4

NAME

6       Coro::Socket - non-blocking socket-I/O
7

SYNOPSIS

9        use Coro::Socket;
10
11        # listen on an ipv4 socket
12        my $socket = new Coro::Socket PeerHost => "localhost",
13                                      PeerPort => 'finger';
14
15        # listen on any other type of socket
16        my $socket = Coro::Socket->new_from_fh
17                        (IO::Socket::UNIX->new
18                            Local  => "/tmp/socket",
19                            Type   => SOCK_STREAM,
20                        );
21

DESCRIPTION

23       This module is an AnyEvent user, you need to make sure that you use and
24       run a supported event loop.
25
26       This module implements socket-handles in a coroutine-compatible way,
27       that is, other coroutines can run while reads or writes block on the
28       handle. See Coro::Handle, especially the note about prefering method
29       calls.
30

IPV6 WARNING

32       This module was written to imitate the IO::Socket::INET API, and derive
33       from it. Since IO::Socket::INET does not support IPv6, this module does
34       neither.
35
36       Therefore it is not recommended to use Coro::Socket in new code.
37       Instead, use AnyEvent::Socket and Coro::Handle, e.g.:
38
39          use Coro;
40          use Coro::Handle;
41          use AnyEvent::Socket;
42
43          # use tcp_connect from AnyEvent::Socket
44          # and call Coro::Handle::unblock on it.
45
46          tcp_connect "www.google.com", 80, Coro::rouse_cb;
47          my $fh = unblock +(Coro::rouse_wait)[0];
48
49          # now we have a perfectly thread-safe socket handle in $fh
50          print $fh "GET / HTTP/1.0\015\012\015\012";
51          local $/;
52          print <$fh>;
53
54       Using "AnyEvent::Socket::tcp_connect" gives you transparent IPv6,
55       multi-homing, SRV-record etc. support.
56
57       For listening sockets, use "AnyEvent::Socket::tcp_server".
58
59       $fh = new Coro::Socket param => value, ...
60           Create a new non-blocking tcp handle and connect to the given host
61           and port. The parameter names and values are mostly the same as for
62           IO::Socket::INET (as ugly as I think they are).
63
64           The parameters officially supported currently are: "ReuseAddr",
65           "LocalPort", "LocalHost", "PeerPort", "PeerHost", "Listen",
66           "Timeout", "SO_RCVBUF", "SO_SNDBUF".
67
68              $fh = new Coro::Socket PeerHost => "localhost", PeerPort => 'finger';
69

AUTHOR/SUPPORT/CONTACT

71          Marc A. Lehmann <schmorp@schmorp.de>
72          http://software.schmorp.de/pkg/Coro.html
73
74
75
76perl v5.28.1                      2018-12-16                         Socket(3)
Impressum