instance method
BasicSocket#shutdown
(::interned | ::Integer flags) -> void
basicsocket.shutdown([how]) => 0
ext/socket/basicsocket.c
View on GitHub ↗
static VALUE
bsock_shutdown(int argc, VALUE *argv, VALUE sock)
{
VALUE howto;
int how;
rb_io_t *fptr;
rb_scan_args(argc, argv, "01", &howto);
if (howto == Qnil)
how = SHUT_RDWR;
else {
how = rsock_shutdown_how_arg(howto);
if (how != SHUT_WR && how != SHUT_RD && how != SHUT_RDWR) {
rb_raise(rb_eArgError, "`how' should be either :SHUT_RD, :SHUT_WR, :SHUT_RDWR");
}
}
GetOpenFile(sock, fptr);
if (shutdown(fptr->fd, how) == -1)
rb_sys_fail("shutdown(2)");
return INT2FIX(0);
}
Calls shutdown(2) system call.
s.shutdown(Socket::SHUT_RD) disallows further read.
s.shutdown(Socket::SHUT_WR) disallows further write.
s.shutdown(Socket::SHUT_RDWR) disallows further read and write.
how can be symbol or string:
-
:RD, :SHUT_RD, “RD” and “SHUT_RD” are accepted as
Socket::SHUT_RD. -
:WR, :SHUT_WR, “WR” and “SHUT_WR” are accepted as
Socket::SHUT_WR. -
:RDWR, :SHUT_RDWR, “RDWR” and “SHUT_RDWR” are accepted as
Socket::SHUT_RDWR.UNIXSocket.pair{|s1, s2|Examples1.puts "ping" s1.shutdown(:WR) p s2.read #=> "ping\n" s2.puts "pong" s2.close p s1.read #=> "pong\n"
}