libdill: Structured Concurrency for C


tcp_connect_mem - create a connection to remote TCP endpoint


#include <libdill.h>

int tcp_connect_mem(const struct ipaddr *addr, void *mem, int64_t deadline);


TCP protocol is a bytestream protocol (i.e. data can be sent via bsend() and received via brecv()) for transporting data among machines.

Creates a connection to a peer specified by addr argument, in user-supplied memory. The memory is passed in mem argument. It must be at least TCP_SIZE bytes long and can be deallocated only after the socket is closed. Unless you are hyper-optimizing use tcp_connect() instead.

deadline is a point in time when the operation should time out. Use the now() function to get your current point in time. 0 means immediate timeout, i.e., perform the operation if possible or return without blocking if not. -1 means no deadline, i.e., the call will block forever if the operation cannot be performed.

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


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



char mem[TCP_SIZE];
int s = tcp_connect_mem(&addr, mem, -1);