Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

coro::socket(3pm) [debian man page]

Socket(3pm)						User Contributed Perl Documentation					       Socket(3pm)

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 Coro::Handle, especially the note about prefering method calls. IPV6 WARNING This module was written to imitate the IO::Socket::INET 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 AnyEvent::Socket and Coro::Handle, 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.015121512"; 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
Marc Lehmann <schmorp@schmorp.de> http://home.schmorp.de/ perl v5.14.2 2012-04-13 Socket(3pm)

Check Out this Related Man Page

SemaphoreSet(3pm)					User Contributed Perl Documentation					 SemaphoreSet(3pm)

NAME
Coro::SemaphoreSet - efficient set of counting semaphores SYNOPSIS
use Coro; $sig = new Coro::SemaphoreSet [initial value]; $sig->down ("semaphoreid"); # wait for signal # ... some other "thread" $sig->up ("semaphoreid"); DESCRIPTION
This module implements sets of counting semaphores (see Coro::Semaphore). It is nothing more than a hash with normal semaphores as members, but is more efficiently managed. This is useful if you want to allow parallel tasks to run in parallel but not on the same problem. Just use a SemaphoreSet and lock on the problem identifier. You don't have to load "Coro::SemaphoreSet" manually, it will be loaded automatically when you "use Coro" and call the "new" constructor. new [inital count] Creates a new semaphore set with the given initial lock count for each individual semaphore. See Coro::Semaphore. $semset->down ($id) Decrement the counter, therefore "locking" the named semaphore. This method waits until the semaphore is available if the counter is zero. $semset->up ($id) Unlock the semaphore again. If the semaphore reaches the default count for this set and has no waiters, the space allocated for it will be freed. $semset->try ($id) Try to "down" the semaphore. Returns true when this was possible, otherwise return false and leave the semaphore unchanged. $semset->count ($id) Return the current semaphore count for the specified semaphore. $semset->waiters ($id) Returns the number (in scalar context) or list (in list context) of waiters waiting on the specified semaphore. $semset->wait ($id) Same as Coro::Semaphore::wait on the specified semaphore. $guard = $semset->guard ($id) This method calls "down" and then creates a guard object. When the guard object is destroyed it automatically calls "up". $semaphore = $semset->sem ($id) This SemaphoreSet version is based on Coro::Semaphore's. This function creates (if necessary) the underlying Coro::Semaphore object and returns it. You may legally call any Coro::Semaphore method on it, but note that calling "$semset->up" can invalidate the returned semaphore. AUTHOR
Marc Lehmann <schmorp@schmorp.de> http://home.schmorp.de/ perl v5.14.2 2012-04-13 SemaphoreSet(3pm)
Man Page