mouse0518 发表于 2009-10-26 20:01:54

ACE_Asynch_Write_File出错

void
Receiver::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result)
{
ACE_DEBUG ((LM_DEBUG,
            "handle_read_stream called\n"));
size_t actualBytes=result.bytes_transferred();
result.message_block ().rd_ptr ()[ result.bytes_transferred ()] = '\0';

ACE_DEBUG ((LM_DEBUG, "********************\n"));
ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "bytes_to_read", result.bytes_to_read ()));
ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "handle", result.handle ()));
ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "bytes_transfered", result.bytes_transferred ()));
ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "act", (u_long) result.act ()));
ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "success", result.success ()));
ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "completion_key", (u_long) result.completion_key ()));
ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "error", result.error ()));
ACE_DEBUG ((LM_DEBUG, "********************\n"));
#if 0
// This can overrun the ACE_Log_Msg buffer and do bad things.
// Re-enable it at your risk.
ACE_DEBUG ((LM_DEBUG, "%s = %s\n", "message_block", result.message_block ().rd_ptr ()));
#endif /* 0 */

if (result.success () && result.bytes_transferred () != 0)
    {
   
      if (this->wf_.write (result.message_block (),
                           result.bytes_transferred (),
                           this->file_offset_) == -1)   //这个函数总出错,wf_是怎么设置的?
      {
          ACE_ERROR ((LM_ERROR,
                      "%p\n",
                      "ACE_Asynch_Write_File::write"));
          return;
      }

      if(actualBytes<needDataLength_) //needDataLength_声明为全局变量为65535
      {
          ACE_DEBUG ((LM_DEBUG,"readed bytes(%d) is less than needed bytes(%d)\n",actualBytes,needDataLength_));
          size_t dataLength = needDataLength_-actualBytes;
          ACE_Message_Block* pMessageBlock;
          ACE_NEW_NORETURN(pMessageBlock,ACE_Message_Block(dataLength+1));
         if(this->rs_.read(*pMessageBlock,pMessageBlock->space()-1)!=0)
             {
         pMessageBlock->release();
      // needDataLength_=dataLength;
      
               }
         needDataLength_=dataLength;

            return;
         }
   needDataLength_=65535;
      // Initiate new read from the stream.
    }
else
    {
      ACE_DEBUG ((LM_DEBUG,
                  "Receiver completed\n"));
      result.message_block ().release ();
      delete this;
    }
   if (this->initiate_read_stream () == -1)
      return;
}




问:
      if (this->wf_.write (result.message_block (),
                           result.bytes_transferred (),
                           this->file_offset_) == -1)

      //这个函数总出错,wf_是怎么设置的?

mouse0518 发表于 2009-10-26 20:07:35

请教proactor例子无法写文件问题

1.ace文件写入硬盘那个函数不能正常调用,就是asynch_IO里的write返回出错,一调用就返回-1,同时log信息里说handle is not a socket,可是这个handle明明存在

怎么解决?

rotar 发表于 2009-11-2 15:18:55

我也遇到同样的问题,
Receiver::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result)
中的
                if (this->wf_.write (result.message_block (),
                        result.bytes_transferred (),
                        this->file_offset_) == -1)
                {
                        ACE_ERROR ((LM_ERROR,
                                "%p\n",
                                "ACE_Asynch_Write_File::write"));
                        return;
                }
会出错,同样说handle is not a socket
不知道为什么,楼主这个问题解决了么
XP+VS2005+ACE5.6.6

chinablueker 发表于 2009-12-16 21:11:42

:lol :hug: ......

GilBert1987 发表于 2010-1-22 13:03:47

我也遇到了这个问题,按照http://stdsoft.blogbus.com/logs/52793984.html上面说的解决了,LZ可以试一下,呵呵
页: 1 2 [3]
查看完整版本: 请教proactor例子的速度问题和无法写文件问题