Perl Diver 2.31
Main Environment Variables Perl Default Values Perl Config - Summary Perl Config - Full Installed Modules List Directory uptime Docs

Module Documentation
Details and documentation about a specific module, including version and documentation (if available). Note that while links to perldoc.com and search.cpan.org are provided, the module may be part of a larger distribution. If you reach a File Not Found page on either site, please try the parent module.

Coro::Socket

Name Coro::Socket
Version 6.57
Located at /usr/lib64/perl5
File /usr/lib64/perl5/Coro/Socket.pm
Is Core Yes
Search CPAN for this module Coro::Socket
Documentation Coro::Socket
Module Details Coro::Socket

NAME

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


SYNOPSIS

 use Coro::Socket;
 # listen on an ipv4 socket
 my $socket = new Coro::Socket PeerHost => "localhost",
                               PeerPort => 'finger';
 # listen on any other type of socket
 my $socket = Coro::Socket->new_from_fh
                 (IO::Socket::UNIX->new
                     Local  => "/tmp/socket",
                     Type   => SOCK_STREAM,
                 );


DESCRIPTION

This module is an AnyEvent user, you need to make sure that you use and run a supported event loop.

This module implements socket-handles in a coroutine-compatible way, that is, other coroutines can run while reads or writes block on the handle. See the Coro::Handle manpage, especially the note about prefering method calls.


IPV6 WARNING

This module was written to imitate the the IO::Socket::INET manpage API, and derive from it. Since IO::Socket::INET does not support IPv6, this module does neither.

Therefore it is not recommended to use Coro::Socket in new code. Instead, use the AnyEvent::Socket manpage and the Coro::Handle manpage, e.g.:

   use Coro;
   use Coro::Handle;
   use AnyEvent::Socket;
   # use tcp_connect from AnyEvent::Socket
   # and call Coro::Handle::unblock on it.
   tcp_connect "www.google.com", 80, Coro::rouse_cb;
   my $fh = unblock +(Coro::rouse_wait)[0];
   # now we have a perfectly thread-safe socket handle in $fh
   print $fh "GET / HTTP/1.0\015\012\015\012";
   local $/;
   print <$fh>;

Using AnyEvent::Socket::tcp_connect gives you transparent IPv6, multi-homing, SRV-record etc. support.

For listening sockets, use AnyEvent::Socket::tcp_server.

$fh = new Coro::Socket param => value, ...
Create a new non-blocking tcp handle and connect to the given host and port. The parameter names and values are mostly the same as for IO::Socket::INET (as ugly as I think they are).

The parameters officially supported currently are: ReuseAddr, LocalPort, LocalHost, PeerPort, PeerHost, Listen, Timeout, SO_RCVBUF, SO_SNDBUF.

   $fh = new Coro::Socket PeerHost => "localhost", PeerPort => 'finger';


AUTHOR/SUPPORT/CONTACT

   Marc A. Lehmann <schmorp@schmorp.de>
   http://software.schmorp.de/pkg/Coro.html

Perl Diver brought to you by ScriptSolutions.com © 1997- 2025