[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFE] function to read a file descriptor
From: |
Debarshi Ray |
Subject: |
Re: [RFE] function to read a file descriptor |
Date: |
Thu, 21 Aug 2008 01:10:13 +0530 |
Oops sorry! This one is hopefully better.
size_t
recvbuf (int sockfd, void **buffer, size_t *size)
{
size_t block = BUFSIZ;
size_t count = 0;
ssize_t nread;
if (*buffer == NULL)
*size = block;
for (;;)
{
*buffer = xrealloc (*buffer, *size);
nread = recv (sockfd, *buffer + count, block, 0);
if (nread == -1)
error (EXIT_FAILURE, errno, "recv");
count += nread;
if (nread < block)
break;
else
{
block = (*size / 2 > BUFSIZ) ? *size / 2 : BUFSIZ;
*size += block;
}
}
return count;
}
Comments?
Happy hacking,
Debarshi
- [RFE] function to read a file descriptor, Debarshi Ray, 2008/08/18
- Re: [RFE] function to read a file descriptor, Bruno Haible, 2008/08/18
- Re: [RFE] function to read a file descriptor, Debarshi Ray, 2008/08/18
- Re: [RFE] function to read a file descriptor, Ralf Wildenhues, 2008/08/19
- Re: [RFE] function to read a file descriptor, Debarshi Ray, 2008/08/19
- Re: [RFE] function to read a file descriptor, Ralf Wildenhues, 2008/08/20
- Re: [RFE] function to read a file descriptor,
Debarshi Ray <=
- Re: [RFE] function to read a file descriptor, Bruno Haible, 2008/08/20
- Re: [RFE] function to read a file descriptor, Debarshi Ray, 2008/08/21
- Re: [RFE] function to read a file descriptor, Bruno Haible, 2008/08/21
- Re: [RFE] function to read a file descriptor, Ralf Wildenhues, 2008/08/21