Method: PG::Connection#socket
- Defined in:
- ext/pg_connection.c
#socket ⇒ Integer
This method is deprecated. Please use the more portable method #socket_io .
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 usable, since it can not be used to build a Ruby IO object.
930 931 932 933 934 935 936 937 938 939 940 |
# File 'ext/pg_connection.c', line 930 static VALUE pgconn_socket(VALUE self) { int sd; pg_deprecated(4, ("conn.socket is deprecated and should be replaced by conn.socket_io")); if( (sd = PQsocket(pg_get_pgconn(self))) < 0) pg_raise_conn_error( rb_eConnectionBad, self, "PQsocket() can't get socket descriptor"); return INT2NUM(sd); } |