我有一个非常简单的客户端服务器,其中一个阻塞套接字进行全双工通信.我已经为应用程序启用了SSL/TLS.该模型是典型的生产者 - 消费者的模型.客户端生成数据,将其发送到服务器,服务器处理它们.唯一的问题是,服务器偶尔会将数据发送回客户端,客户端会相应地处理这些数据.下面是一个非常简单的应用程序伪代码:
Run Code Online (Sandbox Code Playgroud)1 Client: 2 ------- 3 while (true) 4 { 5 if (poll(pollin, timeout=0) || 0 < SSL_pending(ssl)) 6 { 7 SSL_read(); 8 // Handle WANT_READ or WANT_WRITE appropriately. 9 // If no error, handle the received control message. 10 } 11 // produce data. 12 while (!poll(pollout)) 13 ; // Wait until the pipe is ready for a send(). 14 SSL_write(); 15 // Handle WANT_READ or WANT_WRITE appropriately. 16 if (time to renegotiate) 17 SSL_renegotiate(ssl); 18 } …