Changes

Jump to navigation Jump to search
1,133 bytes added ,  02:28, 26 January 2017
→‎Example: use source tag
Line 1: Line 1: −
Libsoccr is the library that does [[TCP connection]] checkpoint and restore. Currently it resides in criu source code (<code>soccr</code> subdirectory) and consists of an API header and a static library. Available since [[Download/criu/2.10|Waxwing release]].
+
Libsoccr is a library that does [[TCP connection]] checkpoint and restore.
 +
 
 +
Libsoccr resides in criu source code (<code>soccr</code> subdirectory) and consists of an API header and a static library.
 +
 
 +
Libsoccr is available since CRIU {{criu|2.10}} release.
    
== Overview ==
 
== Overview ==
Line 89: Line 93:  
[[Category: Sub-projects]]
 
[[Category: Sub-projects]]
 
[[Category: Sockets]]
 
[[Category: Sockets]]
 +
== Example ==
 +
 +
<source lang="c">
 +
/* Dump a tcp socket */
 +
 +
dst_let = sizeof(addr);
 +
if (getsockname(sock, (struct sockaddr *) &addr, &dst_let)) {
 +
        pr_perror("connect");
 +
        return -1;
 +
}
 +
dst_let = sizeof(addr);
 +
if (getpeername(sock, (struct sockaddr *) &dst, &dst_let)) {
 +
        pr_perror("connect");
 +
        return -1;
 +
}
 +
 +
so = libsoccr_pause(sock);
 +
 +
dsize = libsoccr_save(so, &data, sizeof(data));
 +
if (dsize < 0) {
 +
        pr_perror("libsoccr_save");
 +
        return -1;
 +
}
 +
close(sock);
 +
 +
 +
/* Restore a tcp socket */
 +
rst = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
 +
if (rst == -1)
 +
        return -1;
 +
 +
 +
so_rst = libsoccr_pause(rst);
 +
libsoccr_set_addr(so_rst, 1, &addr, 0);
 +
libsoccr_set_addr(so_rst, 0, &dst, 0);
 +
 +
queue = libsoccr_get_queue_bytes(so, TCP_RECV_QUEUE, SOCCR_MEM_EXCL);
 +
libsoccr_set_queue_bytes(so_rst, TCP_RECV_QUEUE, queue, SOCCR_MEM_EXCL);
 +
queue = libsoccr_get_queue_bytes(so, TCP_SEND_QUEUE, SOCCR_MEM_EXCL);
 +
libsoccr_set_queue_bytes(so_rst, TCP_SEND_QUEUE, queue, SOCCR_MEM_EXCL);
 +
 +
ret = libsoccr_restore(so_rst, &data, dsize);
 +
if (ret)
 +
        return -1;
 +
 +
libsoccr_resume(so_rst);
 +
libsoccr_resume(so);
 +
</source>

Navigation menu