unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* fibers on a unix socket
@ 2019-01-31 16:43 Catonano
  2019-01-31 19:34 ` Chris Vine
  2019-01-31 22:20 ` tomas
  0 siblings, 2 replies; 3+ messages in thread
From: Catonano @ 2019-01-31 16:43 UTC (permalink / raw)
  To: Guile User

Hello

in Fibers there's an example of a client connecting to a server

I'd like to do the same thing BUT in my case the server provides a unix
socket.

It's a unix socket provided by Postgresql. On Ubuntu it's here
/var/run/postgresql/.s.PGSQL.5432

I'm wondering about these 3 lines the fibers client uses

    ;; Disable Nagle's algorithm.  We buffer ourselves.
    (setsockopt port IPPROTO_TCP TCP_NODELAY 1)
    (fcntl port F_SETFL (logior O_NONBLOCK (fcntl port F_GETFL)))
    (setvbuf port 'block 1024)

Can a unix socket be non blocking ?

Does it make any sense if I set the block size to 1024 ?

Thanks


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: fibers on a unix socket
  2019-01-31 16:43 fibers on a unix socket Catonano
@ 2019-01-31 19:34 ` Chris Vine
  2019-01-31 22:20 ` tomas
  1 sibling, 0 replies; 3+ messages in thread
From: Chris Vine @ 2019-01-31 19:34 UTC (permalink / raw)
  To: guile-user

On Thu, 31 Jan 2019 17:43:42 +0100
Catonano <catonano@gmail.com> wrote:
> Hello
> 
> in Fibers there's an example of a client connecting to a server
> 
> I'd like to do the same thing BUT in my case the server provides a unix
> socket.
> 
> It's a unix socket provided by Postgresql. On Ubuntu it's here
> /var/run/postgresql/.s.PGSQL.5432
> 
> I'm wondering about these 3 lines the fibers client uses
> 
>     ;; Disable Nagle's algorithm.  We buffer ourselves.
>     (setsockopt port IPPROTO_TCP TCP_NODELAY 1)
>     (fcntl port F_SETFL (logior O_NONBLOCK (fcntl port F_GETFL)))
>     (setvbuf port 'block 1024)
> 
> Can a unix socket be non blocking ?

Yes.  If you are using it with fibers it must be made non-blocking
with the aforementioned application of fcntl.

> Does it make any sense if I set the block size to 1024 ?

Yes.  Sockets are unbuffered by default and the call to setvbuf
substitutes block buffering, which means that (if the port is not
explicitly flushed) output will flush when the buffer becomes full or
when the port is closed, and input will do look-ahead buffering.  The
other options are the default of no buffering (which is OK for output
ports if you are sending largish chunks of data, but not a good idea
for input) or line buffering, whereby a newline flushes the output
buffer and which you might want if you are sending text.

The buffering status of the port has nothing to do with whether the
port's descriptor is set blocking or not.  As I said, for asynchronous
i/o it must be.  The word "block" here is being used in two unconnected
senses.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: fibers on a unix socket
  2019-01-31 16:43 fibers on a unix socket Catonano
  2019-01-31 19:34 ` Chris Vine
@ 2019-01-31 22:20 ` tomas
  1 sibling, 0 replies; 3+ messages in thread
From: tomas @ 2019-01-31 22:20 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 1139 bytes --]

On Thu, Jan 31, 2019 at 05:43:42PM +0100, Catonano wrote:
> Hello
> 
> in Fibers there's an example of a client connecting to a server
> 
> I'd like to do the same thing BUT in my case the server provides a unix
> socket.
> 
> It's a unix socket provided by Postgresql. On Ubuntu it's here
> /var/run/postgresql/.s.PGSQL.5432
> 
> I'm wondering about these 3 lines the fibers client uses
> 
>     ;; Disable Nagle's algorithm.  We buffer ourselves.
>     (setsockopt port IPPROTO_TCP TCP_NODELAY 1)

The one above probably doesn't make sense for Unix domain sockets
(it is specific to IP sockets and it is meant to delay sending
a small packet in the hope that more stuff arrives, to avoid lots
of tiny packets)

>     (fcntl port F_SETFL (logior O_NONBLOCK (fcntl port F_GETFL)))

while this one does make sense (as Chris notes): you want your other
fibres to do their happy dancing instead of blocking the whole process
in the read.

>     (setvbuf port 'block 1024)
> 
> Can a unix socket be non blocking ?

Yes, they can be both. In this respect they are not different from
IP sockets.

Cheers
-- t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-01-31 22:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-31 16:43 fibers on a unix socket Catonano
2019-01-31 19:34 ` Chris Vine
2019-01-31 22:20 ` tomas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).