Move buffer to the heap due to its size

This commit is contained in:
Mukund Sivaraman 2008-08-24 12:07:24 +05:30
parent b6bd791e24
commit fc815b12c1

View File

@ -212,7 +212,7 @@ ssize_t
read_buffer(int fd, struct buffer_s * buffptr) read_buffer(int fd, struct buffer_s * buffptr)
{ {
ssize_t bytesin; ssize_t bytesin;
unsigned char buffer[READ_BUFFER_SIZE]; unsigned char *buffer;
assert(fd >= 0); assert(fd >= 0);
assert(buffptr != NULL); assert(buffptr != NULL);
@ -223,20 +223,23 @@ read_buffer(int fd, struct buffer_s * buffptr)
if (buffptr->size >= MAXBUFFSIZE) if (buffptr->size >= MAXBUFFSIZE)
return 0; return 0;
buffer = safemalloc(READ_BUFFER_SIZE);
if (!buffer) {
return -ENOMEM;
}
bytesin = read(fd, buffer, READ_BUFFER_SIZE); bytesin = read(fd, buffer, READ_BUFFER_SIZE);
if (bytesin > 0) { if (bytesin > 0) {
if (add_to_buffer(buffptr, buffer, bytesin) < 0) { if (add_to_buffer(buffptr, buffer, bytesin) < 0) {
log_message(LOG_ERR, log_message(LOG_ERR,
"readbuff: add_to_buffer() error."); "readbuff: add_to_buffer() error.");
return -1; bytesin = -1;
} }
return bytesin;
} else { } else {
if (bytesin == 0) { if (bytesin == 0) {
/* connection was closed by client */ /* connection was closed by client */
return -1; bytesin = -1;
} else { } else {
switch (errno) { switch (errno) {
#ifdef EWOULDBLOCK #ifdef EWOULDBLOCK
@ -247,15 +250,20 @@ read_buffer(int fd, struct buffer_s * buffptr)
# endif # endif
#endif #endif
case EINTR: case EINTR:
return 0; bytesin = 0;
break;
default: default:
log_message(LOG_ERR, log_message(LOG_ERR,
"readbuff: recv() error \"%s\" on file descriptor %d", "readbuff: recv() error \"%s\" on file descriptor %d",
strerror(errno), fd); strerror(errno), fd);
return -1; bytesin = -1;
break;
} }
} }
} }
safefree(buffer);
return bytesin;
} }
/* /*