简体   繁体   English

阻止来自 TCP 套接字的数据流

[英]block data flow from a TCP socket

I'm using libsoccr, which allows to checkpoint/restore TCP connection.我正在使用 libsoccr,它允许检查点/恢复 TCP 连接。 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. function libsoccr_save(so, &data, sizeof(data))返回 -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) .我重新阅读了 libsoccr 的文档,发现“在调用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) .我查看了源代码,发现队列长度是用ioctl(sockfd, SIOCOUTQ, &size)得到的,后来,队列本身的内容是用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.使用 gdb,即使队列不为空,我似乎总是得到ret = 0 ,这肯定是因为我没有阻塞套接字的数据流,但我不知道该怎么做。 So the question is, how can I block the data flow of a socket?那么问题来了,如何才能阻塞一个socket的数据流呢?

A good way to block the data flow of a socket is to use "plug qdisc".阻止套接字数据流的一个好方法是使用“plug qdisc”。 All the documentation can be found here: https://www.infradead.org/~tgr/libnl/doc/api/group__qdisc__plug.html所有文档都可以在这里找到: https://www.infradead.org/~tgr/libnl/doc/api/group__qdisc__plug.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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