简体   繁体   中英

block data flow from a TCP socket

I'm using libsoccr, which allows to checkpoint/restore TCP connection. Here is how I'm trying to use it:

/* some code to initialize and connect the socket */

#define max 10000000
struct libsoccr_sk *so;
struct libsoccr_sk_data data;
int sockfd, dsize, size;
char *buff = (char *)malloc(MAX * sizeof(char));

/* some code to fill the buffer */

write(sockfd, buff, MAX);
so = libsoccr_pause(sockfd);
dsize = libsoccr_save(so, &data, sizeof(data));

/* some code */

The function libsoccr_save(so, &data, sizeof(data)) returns me -6.

I re read libsoccr's documentation, and found out "any data flow for this socket must be blocked by the caller before this call" talking about libsoccr_pause(sockfd) . I looked into the source code and found out that the queue length is got with ioctl(sockfd, SIOCOUTQ, &size) and later, the content of the queue itself is got with ret = recv(sockfd, buf, size+1, MSG_PEEK | MSG_DONTWAIT) . Using gdb, it appears that I always get ret = 0 even if the queue is not empty, surely because I don't block the data flow of the socket, but I have no clue on how to do it. So the question is, how can I block the data flow of a socket?

A good way to block the data flow of a socket is to use "plug qdisc". All the documentation can be found here: https://www.infradead.org/~tgr/libnl/doc/api/group__qdisc__plug.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM