Method: UNIXSocket.socketpair
- Defined in:
- unixsocket.c
.pair([type [, protocol]]) ⇒ Array .socketpair([type [, protocol]]) ⇒ Array
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"
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
# File 'unixsocket.c', line 484 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); } |