Method: UNIXSocket.pair

Defined in:
unixsocket.c

.pair([type [, protocol]]) ⇒ Array .socketpair([type [, protocol]]) ⇒ Array

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.

s1, s2 = UNIXSocket.pair
s1.send "a", 0
s1.send "b", 0
p s2.recv(10) #=> "ab"

Overloads:

  • .pair([type [, protocol]]) ⇒ Array

    Returns:

    • (Array)
  • .socketpair([type [, protocol]]) ⇒ Array

    Returns:

    • (Array)


550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
# File 'unixsocket.c', line 550

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);
}