New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SW_BUFFER_SIZE=8192 #4
Comments
查看了作者的代码,找到了问题所在 Base.c SWINLINE int swRead(int fd, char *buf, int len)
{
int n = 0, nread;
while (1)
{
nread = read(fd, buf + n, len - n);
//遇到错误
if (nread < 0)
{
//中断
if (errno == EINTR)
{
continue;
}
//出错了
else
{
if (errno != EAGAIN)
{
sw_errno = -1; //异常
}
break;
}
}
//连接已关闭
else if (nread == 0)
{
sw_errno = ECONNRESET;
return 0;
}
else
{
n += nread;
//内存读满了,还可能有数据
if (n == len)
{
sw_errno = EAGAIN;
break;
}
//已读完
else
{
sw_errno = 0;
continue;
}
}
}
return n;
} Server.c static int swServer_poll_onReceive_no_buffer(swReactor *reactor, swEvent *event)
{
int ret, n;
swServer *serv = reactor->ptr;
swFactory *factory = &(serv->factory);
swEventData buf;
n = swRead(event->fd, buf.data, SW_BUFFER_SIZE);
if (n < 0)
{
swTrace("swRead error: %d\n", errno);
return SW_ERR;
}
else if (n == 0)
{
swTrace("Close Event.FD=%d|From=%d\n", event->fd, event->from_id);
return swServer_close(serv, event);
}
else
{
swTrace("recv: %s|fd=%d|len=%d\n", buf.data, event->fd, n);
buf.info.fd = event->fd;
buf.info.len = n;
buf.info.from_id = event->from_id;
ret = factory->dispatch(factory, &buf);
//处理数据失败,数据将丢失
if (ret < 0)
{
swWarn("factory->dispatch fail\n");
}
if (sw_errno == SW_OK)
{
return ret;
}
//缓存区还有数据没读完,继续读,EPOLL的ET模式
else if (sw_errno == EAGAIN)
{
ret = swServer_poll_onReceive_no_buffer(reactor, event);
}
return ret;
}
return SW_OK;
} |
嗯, 连接关闭这块的逻辑需要做个EAGAIN判断了。 |
此bug已修复。接收的数据长度恰好等于BUFER_SIZE时会触发Close. |
好的,我看看,谢谢 2013/8/2 Tianfeng notifications@github.com
|
server.php
client.php
client端结果($client->recv(8192, 1)也是同样的结果):
The text was updated successfully, but these errors were encountered: