[Ace-users] AIO handle_write_stream generated "Cannot allocate memeory" error during partial write.

Fan fanyang32 at gmail.com
Tue Aug 28 09:52:13 CDT 2007


Hi all,

ACE VERSION: 5.5.10

HOST MACHINE and OPERATING SYSTEM: x86, FreeBSD 6

TARGET MACHINE and OPERATING SYSTEM, if different from HOST:

THE $ACE_ROOT/ace/config.h FILE:
#include "ace/config-freebsd.h"

THE $ACE_ROOT/include/makeinclude/platform_macros.GNU FILE:
include $(ACE_ROOT)/include/makeinclude/platform_freebsd.GNU

AREA/CLASS/EXAMPLE AFFECTED:

DOES THE PROBLEM AFFECT:
        COMPILATION? NO
        LINKING? NO
        On Unix systems, did you run make realclean first? YES
        EXECUTION? YES

SYNOPSIS:  AIO handle_write_stream generated "Cannot allocate memeory"
error during partial write on FreeBSD 6

DESCRIPTION: I write a test programs - client.cpp based on /examples/C+
+NPv2/
AIO_Client_Logging_Daemon.cpp using POSIX_CB_Proactor, it connects a
server and echoes server's messages to the server. The server program
repeatly sends data to the client. Everything is fine if there is no
partial write. But if there is a partial write, it will try to write
uncomplete message, ends up with failing in handle_write_stream most
time, the error message is "Cannot llocate memory" as the following
shown. Handle_write_stream code is followed.

/***********************
error
**************************************************/
Output: towrite: 131072, trans: 5584Output: Partial write:
Asynch_write called again 125488
Output::handle_write_stream() ...
Output: towrite: 125488, trans: 16384Output: Partial write:
Asynch_write called again 109104
Output::handle_write_stream() ...
Output: towrite: 109104, trans: 2920Output: Partial write:
Asynch_write called again 106184
Output::partial writer_.write() error:0
Output::handle_write_stream() ...
Output: towrite: 106184, trans: 2920Output: Partial write:
Asynch_write called again 103264
Output::partial writer_.write() error:0

Output::handle_write_stream() ...
(134582272) Output::handle_write_stream fail: Cannot allocate memory
Input::handle_write_stream() error: -1, errno: 12

/***********************             code snippet
********************************************/
void Output_Handler::handle_write_stream(const
ACE_Asynch_Write_Stream::Result &result)
{
  if (!result.success()) {
    ACE_ERROR ((LM_DEBUG, "(%t) %p\n", "Output::handle_write_stream
fail"));
    delete this;
    return;
  }

  // Write stream successful.
  // Partial write to socket.
  size_t unsent_data = result.bytes_to_write () -
result.bytes_transferred ();
  if (unsent_data != 0){
    int iReturn = 0;
    if (iReturn = this-
>writer_.write(*result.message_block().duplicate(), unsent_data) == -1)
{
      ACE_ERROR ((LM_ERROR, "Output::handle_write_stream failed\n"));
      return;
    }

    return;
  }

  // read data again
  initiate_read();
}



Would you please tell me how to deal with this problem? thank you in
advance.

Fan



More information about the Ace-users mailing list