I'm receiving from socket A and writing that to socket B on the fly (like a proxy server might). I would like to inspect and possibly modify data passing through. My question is how to handle border cases, ie where the regular expression I'm searching for would match between two successive socket A read and socket B write iterations.

我从套接字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 :( */

}

6 个解决方案

#1


My suggestion: have two buffers, and rotate between them:

我的建议:有两个缓冲区,并在它们之间旋转:

  1. Recv buffer 1
  2. Recv缓冲区1

  3. Recv buffer 2
  4. Recv缓冲区2

  5. Process.
  6. Send buffer 1
  7. 发送缓冲区1

  8. Recv buffer 1
  9. Recv缓冲区1

  10. Process, but with buffer 2 before buffer 1.
  11. 处理,但在缓冲区1之前使用缓冲区2。

  12. Send buffer 2
  13. 发送缓冲区2

  14. Goto 2.

Or something like that?

或类似的东西?

更多相关文章

  1. 图片在页面内随意飘动,遇到边界还会反弹
  2. 基于缓冲区数据创建文件
  3. Python:Sympy定义与包含变量的边界的积分
  4. Java nio 学习笔记(一) Buffer(缓冲区)与Channel(通道)的相关知识
  5. Java IO流系列(四)—— 从字节流及其缓冲区到转换流
  6. Java的Grizzly为缓冲区占用了大量内存?

随机推荐

  1. android ndk 开发
  2. Android消息推送MQTT
  3. Android(安卓)工程的创建
  4. android bug fix
  5. Android basic1
  6. Android--动态添加控件
  7. android设备信息获取
  8. android手机QQ尾巴修改(QQ for Pad)
  9. Android 开发 官方 论坛
  10. Android-sharedUserId