libdill: Structured Concurrency for C


pfx_attach_mem - creates PFX protocol on top of underlying socket


#include <libdill.h>

int pfx_attach_mem(int s, void *mem);


PFX is a message-based protocol to send binary messages prefixed by 8-byte size in network byte order. The protocol has no initial handshake. Terminal handshake is accomplished by each peer sending eight 0xFF bytes.

This function instantiates PFX protocol on top of underlying bytestream protocol s, in a user-supplied memory. Unless you are hyper-optimizing use pfx_attach() instead.

The memory passed in mem argument must be at least PFX_SIZE bytes long and can be deallocated only after the socket is closed.

The socket can be cleanly shut down using pfx_detach() function.


Newly created socket handle. On error, it returns -1 and sets errno to one of the values below.



int u = tcp_connect(&addr, -1);
char mem[PFX_SIZE];
int s = pfx_attach_mem(u, mem);