On Thu, 31 Jan 2019 17:43:42 +0100 Catonano <caton...@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.