日期:2014-05-16 浏览次数:20649 次
/*自定制的read函数*/
ssize_t Readline(int fd, void *buf, size_t num)
{
ssize_t res;
size_t n;
char *ptr;
n = num;
ptr = (char *)buf;
while (n > 0)
{
if ((res = read (fd, ptr, n)) == -1)
{
if (errno == EINTR) /*中断*/
res = 0;
else if (errno == ECONNRESET)
{
return 0;
}
else
{
ibslog(2, 5, __FILE__, __LINE__, "errno:[%d, %s]", errno, strerror(errno));
return -1;
}
}
else if (res == 0)
break;
ptr += res;
n -= res;
}
return (num - n);
}