|
发表于 2009-1-15 16:49:10
|
显示全部楼层
给你一个模板代码,基本上都是这么写的。在写调用期间,不进行无关的send操作。
-
- void SvcHandler::handle_write_stream (const ACE_Asynch_Write_Stream::Result &result)
- {
- //释放引用
- ACE_Message_Block & mblk = result.message_block();
- if(result.success())
- {
- //检查短写问题
- mblk.rd_ptr(mblk.rd_ptr() - result.bytes_transferred());
- // Partial write to socket
- size_t unsent_data = result.bytes_to_write () - result.bytes_transferred ();
- if (unsent_data != 0)
- {
- // Reset pointers
- result.message_block ().rd_ptr (result.bytes_transferred ());
- {
- // Duplicate the message block and retry remaining data
- if (m_writer.write (*mblk.duplicate(), unsent_data) == -1)
- {
- ACE_DEBUG((LM_DEBUG,"%D handle_write_stream error at line %l File %N,error code:%d, thread_id:%t\n",ACE_OS::last_error()));
- mblk.release();
- }
- ACE_DEBUG((LM_DEBUG,"%D handle_write_stream resend data at line %l File %N,error code:%d, thread_id:%t\n",ACE_OS::last_error()));
- }
- }else
- {
- ACE_DEBUG((LM_DEBUG,"%D handle_write_stream send complete data at line %l File %N,error code:%d, thread_id:%t\n",ACE_OS::last_error()));
- }
- }else
- {
- ACE_DEBUG((LM_DEBUG,"%D handle_write_stream error at line %l File %N,error code:%d, thread_id:%t\n",ACE_OS::last_error()));
- }
- //释放
- mblk.release();
- }
复制代码 |
|