Method: PG::Connection#socket
- Defined in:
- ext/pg_connection.c
#socket ⇒ Fixnum
Returns the socket’s file descriptor for this connection. IO.for_fd() can be used to build a proper IO object to the socket. If you do so, you will likely also want to set autoclose=false on it to prevent Ruby from closing the socket to PostgreSQL if it goes out of scope. Alternatively, you can use #socket_io, which creates an IO that’s associated with the connection object itself, and so won’t go out of scope until the connection does.
Note: On Windows the file descriptor is not really usable, since it can not be used to build a Ruby IO object.
724 725 726 727 728 729 730 731 |
# File 'ext/pg_connection.c', line 724 static VALUE pgconn_socket(VALUE self) { int sd; if( (sd = PQsocket(pg_get_pgconn(self))) < 0) rb_raise(rb_eConnectionBad, "PQsocket() can't get socket descriptor"); return INT2NUM(sd); } |