void Sender::handle_read_file (const ACE_Asynch_Read_File::Result &result) { ACE_DEBUG ((LM_DEBUG, "handle_read_file called\n")); 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", (uintptr_t) result.act ())); ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "success", result.success ())); ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "completion_key", (uintptr_t) result.completion_key ())); ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "error", result.error ())); ACE_DEBUG ((LM_DEBUG, "********************\n")); //ACE_DEBUG ((LM_DEBUG, "%s = %s\n", "message_block", result.message_block ().rd_ptr ())); if (result.success ()) { // Read successful: increment offset and write data to network. // Note how we reuse the <ACE_Message_Block> for the writing. // Therefore, we do not delete this buffer because it is handled // in <handle_write_stream>. this->file_offset_ += ACE_Utils::truncate_cast<u_long> (result.bytes_transferred ()); if (this->ws_.write (result.message_block (), result.bytes_transferred ()) == -1) { ACE_ERROR ((LM_ERROR, "%p\n", "ACE_Asynch_Write_Stream::write")); return; } if (this->file_size_ > this->file_offset_) { // Start an asynchronous read file. if (initiate_read_file () == -1) return; } } }
//*************************************************************************** // // Method: handle_read_file // // Description: Callback used when a read completes // // Inputs: read file result structure containing message block // // Returns: none // //*************************************************************************** void FileIOHandler::handle_read_file(const ACE_Asynch_Read_File::Result &result) { ACE_Message_Block &mb = result.message_block(); // If the read failed, queue up another one using the same message block if (!result.success() || result.bytes_transferred() == 0) { //ACE_DEBUG((LM_INFO, ACE_TEXT("FileIOHandler receive timeout.\n"))); reader_.read(mb, mb.space(), result.offset () + result.bytes_transferred ()); } else { // We have a message block with some read data in it. Send it onward ACE_DEBUG((LM_INFO, ACE_TEXT("FileIOHandler received %d bytes of data at offset %d\n"), result.bytes_transferred(), result.offset ())); // TODO: Process this data in some meaningful way if (result.offset () != (unsigned long)*reinterpret_cast<unsigned char*> (mb.rd_ptr ())) { ACE_DEBUG((LM_ERROR, ACE_TEXT("FileIOHandler received incorrect data: got [%u] expected [%u]\n"), *reinterpret_cast<unsigned char*> (mb.rd_ptr ()), result.offset ())); } // Release the message block when we're done with it mb.release(); if ((result.offset () + result.bytes_transferred ()) < 256) { // Our processing is done; prime the read process again ACE_Message_Block *new_mb; ACE_NEW_NORETURN(new_mb, ACE_Message_Block(FILE_FRAME_SIZE)); if (reader_.read(*new_mb, new_mb->space(), result.offset () + result.bytes_transferred ()) != 0) { int errnr = ACE_OS::last_error (); ACE_DEBUG( (LM_INFO, ACE_TEXT("%p [%d]\n"), ACE_TEXT("FileIOHandler continuing read failed"), errnr)); new_mb->release(); #if defined (ACE_WIN32) this->read_pending_ = false; } else { this->read_pending_ = true; #endif } } else { // we have it all; stop the proactor ACE_Proactor::instance ()->proactor_end_event_loop (); } } }
void Simple_Tester::handle_read_file (const ACE_Asynch_Read_File::Result &result) { ACE_DEBUG ((LM_DEBUG, "handle_read_file called\n")); 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")); // Watch out if you need to enable this... the ACE_Log_Record::MAXLOGMSGLEN // value controls to max length of a log record, and a large output // buffer may smash it. #if 0 ACE_DEBUG ((LM_DEBUG, "%s = %s\n", "message_block", result.message_block ().rd_ptr ())); #endif /* 0 */ if (result.success ()) { // Read successful: write this to the file. if (this->wf_.write (result.message_block (), result.bytes_transferred ()) == -1) { ACE_ERROR ((LM_ERROR, "%p\n", "ACE_Asynch_Write_File::write")); return; } } }