119 while(remainLength > 0){
120 if(remainLength >= MAX_LENGTH){
121 log("WorkHandler::workLoop, remain %d > max %d \n", remainLength, MAX_LENGTH);
122 currentSentLength = send(client->getFd(), sBuffer, MAX_LENGTH, MSG_NOSIGNAL);
123 log("currentSentLength %d \n", currentSentLength);
124 }
125 else{
126 log("WorkHandler::workLoop, remain %d < max %d \n", remainLength, MAX_LENGTH);
127 currentSentLength = send(client->getFd(), sBuffer, remainLength, MSG_NOSIGNAL);
128 log("currentSentLength %d \n", currentSentLength);
129 }
130
131
132 if(currentSentLength == -1){
133 log("WorkHandler::workLoop, connection has been lost \n");
134 break;
135 }
136 sBuffer += currentSentLength;
137 log("sBuffer %d\n", sBuffer);
138
139 remainLength -= currentSentLength;
140 log("remainLength %d \n", remainLength);
141
142 }
我有这段代码,发送功能有时会卡住。有人指出使用非阻塞 I/O。我正在使用 epoll,所以我认为将整个设计更改为非阻塞模式有点困难。有什么办法可以防止阻塞发送功能?
提前致谢..