我从套接字 A 接收并即时将其写入套接字 B(就像代理服务器可能一样)。我想检查并可能修改通过的数据。我的问题是如何处理边界情况,即我正在搜索的正则表达式将在两个连续的套接字 A 读取和套接字 B 写入迭代之间匹配。
char buffer[4096]
int socket_A, socket_B
/* Setting up the connection goes here */
for(;;) {
recv(socket_A, buffer, 4096, 0);
/* Inspect, and possibly modify buffer */
send(socket_B, buffer, 4096, 0);
/* Oops, the matches I was looking for were at the end of buffer,
* and will be at the beginning of buffer next iteration :( */
}