PG client with tcp socket class or connection proxy passed

29 views
Skip to first unread message

Tiago Cardoso

unread,
Sep 3, 2015, 8:27:19 AM9/3/15
to ruby-pg
Coming from here: https://groups.google.com/forum/#!topic/sequel-talk/jdvvqcsH6Fg

Is there already the possibility of passing the tcp socket class to the constructor (or an open socket)? Something like: 

conn = PG.connect( dbname: 'sales', tcp_socket_class: Celluloid::IO::TCPSocket )

Other implementations could potentially benefit from this, as em-synchrony has its own tcp socket duck types. 

Lars Kanis

unread,
Sep 3, 2015, 2:07:29 PM9/3/15
to rub...@googlegroups.com
Hi Tiago,

> Is there already the possibility of passing the tcp socket class to
> the constructor (or an open socket)? Something like:
>
> conn = PG.connect( dbname: 'sales', tcp_socket_class: Celluloid::IO::TCPSocket )

Unfortunately not. The underlying library "libpq" does not support such
a use case. It always handles the communication socket by itself.

However ruby-pg (and libpq as well) fully supports non blocking
operations on all functions, that perform network communication. That
typically works like this:

1. send a query to the server per (asynchronous) PG method
2. get the connection socket IO object per PG::Connection#socket_io
3. Give this IO object a the actor, so that it can wait for activity on
the socket
4. retrieve data per (asynchronous) PG method

This all is implemented for eventmachine already in:
https://github.com/royaltm/ruby-em-pg-client

--
Regards,
Lars


Reply all
Reply to author
Forward
0 new messages