End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
UNIXSocket.socketpair
UNIXSocket.pair([type [, protocol]]) => [unixsocket1, unixsocket2]
UNIXSocket.socketpair([type [, protocol]]) => [unixsocket1, unixsocket2]
ext/socket/unixsocket.c
View on GitHub ↗
static VALUE
unix_s_socketpair(int argc, VALUE *argv, VALUE klass)
{
VALUE domain, type, protocol;
VALUE args[3];
domain = INT2FIX(PF_UNIX);
rb_scan_args(argc, argv, "02", &type, &protocol);
if (argc == 0)
type = INT2FIX(SOCK_STREAM);
if (argc <= 1)
protocol = INT2FIX(0);
args[0] = domain;
args[1] = type;
args[2] = protocol;
return rsock_sock_s_socketpair(3, args, klass);
}
Creates a pair of sockets connected to 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.
Example
s1, s2 = UNIXSocket.pair s1.send "a", 0 s1.send "b", 0 p s2.recv(10) #=> "ab"