【发布时间】:2011-10-13 01:09:19
【问题描述】:
我正在 linux 机器上使用 epoll 开发一个网络程序,我从 gdb 收到错误消息。
Program received signal SIGPIPE, Broken pipe.
[Switching to Thread 0x7ffff609a700 (LWP 19788)]
0x00007ffff7bcdb2d in write () from /lib/libpthread.so.0
(gdb)
(gdb) backtrace
#0 0x00007ffff7bcdb2d in write () from /lib/libpthread.so.0
#1 0x0000000000416bc8 in WorkHandler::workLoop() ()
#2 0x0000000000416920 in WorkHandler::runWorkThread(void*) ()
#3 0x00007ffff7bc6971 in start_thread () from /lib/libpthread.so.0
#4 0x00007ffff718392d in clone () from /lib/libc.so.6
#5 0x0000000000000000 in ?? ()
我的服务器进行 n^2 次计算,我尝试运行有 500 个连接用户的服务器。什么可能导致此错误?我该如何解决这个问题?
while(1){
if(remainLength >= MAX_LENGTH)
currentSentLength = write(client->getFd(), sBuffer, MAX_LENGTH);
else
currentSentLength = write(client->getFd(), sBuffer, remainLength);
if(currentSentLength == -1){
log("WorkHandler::workLoop, connection has been lost \n");
break;
}
sBuffer += currentSentLength;
remainLength -= currentSentLength;
if(remainLength == 0)
break;
}
【问题讨论】:
-
SIGPIPE 在您尝试写入已关闭的管道时发生,请确保您正在写入的管道未关闭。
-
将其发布为答案,以便我们对其进行投票。鉴于问题中的信息很少,这是尽可能多的答案。 @LCYSoft:如果没有调用函数的代码,GDB 跟踪将毫无用处。
-
没有。发布一个测试用例。我们现在将得到数百条无用的行。
标签: c++ c linux networking