recv_io

unixsocket.recv_io([klass [, mode]]) => io Instance Public methods IO.open(â/tmp/sockâ) {|serv| UNIXSocket.open("/tmp/sock") {|c| s = serv.accept c.send_io STDOUT stdout = s.recv_io p STDOUT.fileno #=> 1 p stdout.fileno #=> 7 stdout.puts "hello" # outputs "hello\n" to standard output. } }

peeraddr

unixsocket.peeraddr => [address_family, unix_path] Instance Public methods Returns the remote address as an array which contains address_family and unix_path. Example serv = UNIXServer.new("/tmp/sock") c = UNIXSocket.new("/tmp/sock") p c.peeraddr #=> ["AF_UNIX", "/tmp/sock"]

path

unixsocket.path => path Instance Public methods Returns the path of the local address of unixsocket. s = UNIXServer.new("/tmp/sock") p s.path #=> "/tmp/sock"

addr

unixsocket.addr => [address_family, unix_path] Instance Public methods Returns the local address as an array which contains address_family and unix_path. Example serv = UNIXServer.new("/tmp/sock") p serv.addr #=> ["AF_UNIX", "/tmp/sock"]

socketpair

UNIXSocket.socketpair([type [, protocol]]) => [unixsocket1, unixsocket2] Class Public methods Creates a pair of sockets connected each other. socktype should be a socket type such as: :STREAM, :DGRAM, :RAW, etc. protocol should be a protocol defined in the domain. 0 is default protocol for the domain. s1, s2 = UNIXSocket.pair s1.send "a", 0 s1.send "b", 0 p s2.recv(10) #=> "ab"

pair

UNIXSocket.pair([type [, protocol]]) => [unixsocket1, unixsocket2] Class Public methods Creates a pair of sockets connected each other. socktype should be a socket type such as: :STREAM, :DGRAM, :RAW, etc. protocol should be a protocol defined in the domain. 0 is default protocol for the domain. s1, s2 = UNIXSocket.pair s1.send "a", 0 s1.send "b", 0 p s2.recv(10) #=> "ab"

new

UNIXSocket.new(path) => unixsocket Class Public methods Creates a new UNIX client socket connected to path. s = UNIXSocket.new("/tmp/sock") s.send "hello", 0

sysaccept

unixserver.sysaccept => file_descriptor Instance Public methods Accepts a new connection. It returns the new file descriptor which is an integer. UNIXServer.open("/tmp/sock") {|serv| UNIXSocket.open("/tmp/sock") {|c| fd = serv.sysaccept s = IO.new(fd) s.puts "hi" s.close p c.read #=> "hi\n" } }

listen

socket.listen( int ) => 0 Instance Public methods Listens for connections, using the specified int as the backlog. A call to listen only applies if the socket is of type SOCK_STREAM or SOCK_SEQPACKET. Parameter backlog - the maximum length of the queue for pending connections. Example 1 require 'socket' include Socket::Constants socket = Socket.new( AF_INET, SOCK_STREAM, 0 ) sockaddr = Socket.pack_sockaddr_in( 2200, 'localhost' ) socket.bind( sockaddr ) socket.listen( 5 ) E

accept_nonblock

unixserver.accept_nonblock => unixsocket Instance Public methods Accepts an incoming connection using accept(2) after O_NONBLOCK is set for the underlying file descriptor. It returns an accepted UNIXSocket for the incoming connection. Example require 'socket' serv = UNIXServer.new("/tmp/sock") begin # emulate blocking accept sock = serv.accept_nonblock rescue IO::WaitReadable, Errno::EINTR IO.select([serv]) retry end # sock is an accepted socket. Refer to Socket#accept f