CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 25

Threaded View

  1. #1
    Join Date
    Sep 2008
    Posts
    22

    socket receive a chunk at a time

    On linux the same call to fwrite works correctly (errno==0),
    on windows i get ERRNO==22 if the "size" parameter is somewhat big (e.g. "103429"). :-/

    see the code:
    Code:
    // first i open the file
    FILE* request_file = fopen( pathname, "wb" );
    if(request_file == NULL)
    {
       // error
       return;
    }
    
    // second, try to write my buffer (already filled)
    size_t written_bytes = 0;
    if( parsed_request->body != NULL )
    {
       errno=0;
       written_bytes = fwrite((parsed_request->body), 1, (size_t)(parsed_request->content_length), request_file);
       perror("fwrite");
    }
    
    // third, check fwrite return value
    if( written_bytes < 0 )
    {
    	// write error
    	return;
    }
    else if( written_bytes != (parsed_request->content_length) )
    {
    	// error - partial body received
    	return;
    }
    // else fwrite succeed
    NOTE:
    if i replace "(size_t)(parsed_request->content_length)" with a small constant (e.g. "50"), fwrite succeed!

    NOTE2:
    I get the same behavior with "_write"...

    P.S.
    To give you more context details, i'm using the Mingw compiler.
    I've defined the macro "_MT" to enable multi-threaded stdlib.
    Maybe this has some side-effect on fwrite?
    Since the call is not atomic with a big buffer, maybe fwrite fails to preserve thread-safeness?
    I've tried to remove "_MT" in the makefile but fwrite still fails. :-(
    Last edited by hi1; February 6th, 2010 at 10:55 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured