Line 1: |
Line 1: |
− | [[Category: Empty articles]] | + | Libsoccr is the library that does [[TCP connection]] checkpoint and restore. It sits in criu sources and includes an API header and a static library. |
| + | |
| + | == Overview == |
| + | |
| + | To checkpoint a TCP connection one should |
| + | |
| + | # ''pause'' a socket (referenced by descriptor) |
| + | # get socket data |
| + | # get contents of two queues |
| + | # (optionally) resume the socket |
| + | # close it |
| + | |
| + | To restore a connection one should |
| + | |
| + | # create a socket |
| + | # ''pause'' one |
| + | # restore ''unbound'' data |
| + | # bind() and/or connect() socket to whatever addresses is appropriate using standard calls |
| + | # restore ''noq'' data |
| + | # put contents of two queues |
| + | # restore remaining data |
| + | |
| + | == Data types == |
| + | |
| + | In soccr/soccr.h there are two types declares |
| + | |
| + | ; <code>struct libsoccr_sk</code> |
| + | : It's an abstract handler returned by ''pausing'' routine that is used as an opaque identifier by the rest of the libsoccr calls |
| + | |
| + | ; <code>struct libsoccr_sk_data</code> |
| + | : A structure containing a set of 32-bit values that are returned by ''getter'' and that are to be passed '''as is''' to the ''setter'' call |
| + | |
| + | === Data internals === |
| + | |
| + | Inside the data structure there's a special field called <code>flags</code> that gives information about the meaning of some other fields. Though it's not bad just to pass this structure as-is between libsoccr calls, doing some optimization based on flags is OK. |
| + | |
| + | So here are the flags that make sense |
| + | |
| + | ; <code>SOCCR_FLAGS_WINDOW == 0x1</code> |
| + | : When set indicates, that fields <code>snd_wl1</code>, <code>snd_wnd</code>, <code>max_window</code>, <code>rcv_wnd</code> and <code>rcv_wup</code> contain some valuable data (0 is valid value for any) |
| + | |
| + | == Calls == |
| + | |
| + | === Generic === |
| + | |
| + | ; <code>struct libsoccr_sk *libsoccr_pause(int sk)</code> |
| + | : Pauses the socket and returns a handler for further operations. Any data flow for this socket ''must be blocked by the caller'' before this call. |
| + | |
| + | ; <code>void libsoccr_resume(struct libsoccr_sk *)</code> |
| + | : Resumes the socket. Data flow unlock may happen before this. |
| + | |
| + | ; <code>void libsoccr_set_log(unsigned int level, void (*fn)(unsigned int level, const char *fmt, ...))</code> |
| + | : Sets a function that will be called when libsoccr will want to print something on the screen. |
| + | |
| + | === Dump === |
| + | |
| + | ; <code>int libsoccr_get_sk_data(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size)</code> |
| + | : Fills in the <code>data</code> structure with the info get from paused socket. The <code>data_size</code> should be the size of the structure passed. The return code is the size of the structure really filled with data. |
| + | |
| + | ; <code>char *libsoccr_get_queue_bytes(struct libsoccr_sk *sk, int queue_id, int steal)</code> |
| + | : Returns a malloc()-ed array with the contents of the queue. The queue can be TCP_RECV_QUEUE or TCP_SEND_QUEUE. The amount of bytes in each is <code>data.inq_len</code> and <code>data.outq_len</code> respectively. The <code>steal</code> is a boolean value specifying whether the caller would free() the buffers himself (1) or expects the <code>_resume()</code> to do it (0). |
| + | |
| + | === Restore === |
| + | |
| + | ; <code>int libsoccr_set_sk_data_unbound(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size)</code> |
| + | : Restores data on a socket from the <code>data</code> structure. Should be called before bind()-ing or connect()-ing the socket. |
| + | |
| + | ; <code>int libsoccr_set_sk_data_noq(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size)</code> |
| + | : Continues restoration after bind() and/or connect(), but before the queue data restore (see below) |
| + | |
| + | ; <code>int libsoccr_set_sk_data(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size)</code> |
| + | : Completes the restoration after queues, but doesn't resume the socket. |
| + | |
| + | ; <code>int libsoccr_set_queue_bytes(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size, int queue, char *buf)</code> |
| + | : Puts back the contents of the respective queue. |
| + | |
| + | |
| [[Category: Sub-projects]] | | [[Category: Sub-projects]] |
| [[Category: Sockets]] | | [[Category: Sockets]] |