|
-
February 3rd, 2010, 02:19 PM
#20
Re: fwrite ERRNO 22 with big (?) size
 Originally Posted by VladimirF
Right. But it WILL cause access violation trying to copy the stuff that is not there, and will catch the exceprion.
You were right, i get access violation trying to do "puts(parsed_request->body+100000);".
So now i have to recheck all the program logic that fills the buffer...
Code:
#define _READ_CHUNK 512
static void _receive_request( void** buffer, int client_connected_socket )
{
int buffer_current_size = 512;
int buffer_current_offset = 0;
int r = recv( client_connected_socket, (*buffer)+buffer_current_offset, _READ_CHUNK, 0 ); // read first chunk
buffer_current_offset += _READ_CHUNK;
while( r==_READ_CHUNK && r!=0 && r!=-1 )
{
// increase buffer size of a chunk and realloc
buffer_current_size += _READ_CHUNK;
*buffer = realloc(*buffer, buffer_current_size);
// read next chunk
r = recv( client_connected_socket, (*buffer)+buffer_current_offset, _READ_CHUNK, 0 );
// increase offset for next read
buffer_current_offset += _READ_CHUNK;
}
}
static void _handle_http_request( int client_connected_socket )
{
void* http_request_buf = calloc( 512, 1 );
_receive_request( &http_request_buf, client_connected_socket );
// ...
}
On Windows, the buffer fills up to 29184 bytes (much smaller than the data i send).
Last edited by hi1; February 4th, 2010 at 12:31 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|