Inheritance diagram for ACE_POSIX_Asynch_Transmit_Handler:


Public Methods | |
| ACE_POSIX_Asynch_Transmit_Handler (ACE_POSIX_Proactor *posix_proactor, ACE_POSIX_Asynch_Transmit_File_Result *result) | |
| Constructor. Result pointer will have all the information to do the file transmission (socket, file, application handler, bytes to write). More... | |
| virtual | ~ACE_POSIX_Asynch_Transmit_Handler (void) |
| Destructor. More... | |
| int | transmit (void) |
| Do the transmission. All the info to do the transmission is in the <result> member. More... | |
Protected Types | |
| enum | ACT { HEADER_ACT = 1, DATA_ACT = 2, TRAILER_ACT = 3 } |
Protected Methods | |
| virtual void | handle_write_stream (const ACE_Asynch_Write_Stream::Result &result) |
| This is called when asynchronous writes from the socket complete. More... | |
| virtual void | handle_read_file (const ACE_Asynch_Read_File::Result &result) |
| This is called when asynchronous reads from the file complete. More... | |
| int | initiate_read_file (void) |
| Issue asynch read from the file. More... | |
Protected Attributes | |
| ACE_POSIX_Asynch_Transmit_File_Result * | result_ |
| The asynch result pointer made from the initial transmit file request. More... | |
| ACE_Message_Block * | mb_ |
| Message bloack used to do the transmission. More... | |
| ACT | header_act_ |
| ACT to transmit header. More... | |
| ACT | data_act_ |
| ACT to transmit data. More... | |
| ACT | trailer_act_ |
| ACT to transmit trailer. More... | |
| size_t | file_offset_ |
| Current offset of the file being transmitted. More... | |
| size_t | file_size_ |
| Total size of the file. More... | |
| size_t | bytes_transferred_ |
| Number of bytes transferred on the stream. More... | |
| ACE_POSIX_Asynch_Read_File | rf_ |
| To read from the file to be transmitted. More... | |
| ACE_POSIX_Asynch_Write_Stream | ws_ |
| Write stream to write the header, trailer and the data. More... | |
This is a helper class for implementing <ACE_POSIX_Asynch_Transmit_File> in Unix systems.
Definition at line 1904 of file POSIX_Asynch_IO.cpp.
|
|
Definition at line 1929 of file POSIX_Asynch_IO.cpp. Referenced by handle_write_stream.
01930 {
01931 HEADER_ACT = 1,
01932 DATA_ACT = 2,
01933 TRAILER_ACT = 3
01934 };
|
|
||||||||||||
|
Constructor. Result pointer will have all the information to do the file transmission (socket, file, application handler, bytes to write).
Definition at line 1974 of file POSIX_Asynch_IO.cpp. References ACE_NEW, and ACE_OS::filesize.
01976 : result_ (result), 01977 mb_ (0), 01978 header_act_ (this->HEADER_ACT), 01979 data_act_ (this->DATA_ACT), 01980 trailer_act_ (this->TRAILER_ACT), 01981 file_offset_ (result->offset ()), 01982 file_size_ (0), 01983 bytes_transferred_ (0), 01984 rf_ (posix_proactor), 01985 ws_ (posix_proactor) 01986 { 01987 // Allocate memory for the message block. 01988 ACE_NEW (this->mb_, 01989 ACE_Message_Block (this->result_->bytes_per_send () 01990 + 1)); 01991 // Init the file size. 01992 file_size_ = ACE_OS::filesize (this->result_->file ()); 01993 } |
|
|
Destructor.
Definition at line 1996 of file POSIX_Asynch_IO.cpp. References mb_, ACE_Message_Block::release, and result_.
|
|
|
This is called when asynchronous reads from the file complete.
Reimplemented from ACE_Handler. Definition at line 2143 of file POSIX_Asynch_IO.cpp. References ACE_ERROR, ACE_SEH_FINALLY, ACE_SEH_TRY, ACE_Asynch_Result::bytes_transferred, ACE_POSIX_Asynch_Transmit_File_Result::complete, data_act_, file_offset_, LM_ERROR, ACE_Asynch_Read_Stream::Result::message_block, ACE_POSIX_Asynch_Result::priority, result_, ACE_POSIX_Asynch_Result::signal_number, ACE_Asynch_Result::success, ACE_POSIX_Asynch_Write_Stream::write, and ws_.
02144 {
02145 // Failure.
02146 if (result.success () == 0)
02147 {
02148 //
02149 ACE_SEH_TRY
02150 {
02151 this->result_->complete (this->bytes_transferred_,
02152 0, // Failure.
02153 0, // @@ Completion key.
02154 errno); // Error no.
02155 }
02156 ACE_SEH_FINALLY
02157 {
02158 delete this;
02159 }
02160 return;
02161 }
02162
02163 // Read successful.
02164 if (result.bytes_transferred () == 0)
02165 return;
02166
02167 // Increment offset.
02168 this->file_offset_ += result.bytes_transferred ();
02169
02170 // Write data to network.
02171 if (this->ws_.write (result.message_block (),
02172 result.bytes_transferred (),
02173 (void *)&this->data_act_,
02174 this->result_->priority (),
02175 this->result_->signal_number ()) == -1)
02176 {
02177 // @@ Handle this error.
02178 ACE_ERROR ((LM_ERROR,
02179 "Error:ACE_Asynch_Transmit_File : write to the stream failed\n"));
02180 return;
02181 }
02182 }
|
|
|
This is called when asynchronous writes from the socket complete.
Reimplemented from ACE_Handler. Definition at line 2044 of file POSIX_Asynch_IO.cpp. References ACE_DEBUG, ACE_ERROR, ACE_SEH_FINALLY, ACE_SEH_TRY, ACT, ACE_Asynch_Result::act, ACE_Asynch_Write_Stream::Result::bytes_to_write, ACE_Asynch_Result::bytes_transferred, bytes_transferred_, ACE_POSIX_Asynch_Transmit_File_Result::complete, DATA_ACT, ACE_Message_Block::duplicate, HEADER_ACT, initiate_read_file, LM_DEBUG, LM_ERROR, ACE_Asynch_Write_Stream::Result::message_block, ACE_POSIX_Asynch_Result::priority, result_, ACE_POSIX_Asynch_Result::signal_number, ACE_Asynch_Result::success, TRAILER_ACT, ACE_POSIX_Asynch_Write_Stream::write, and ws_.
02045 {
02046 // Update bytes transferred so far.
02047 this->bytes_transferred_ += result.bytes_transferred ();
02048
02049 // Check the success parameter.
02050 if (result.success () == 0)
02051 {
02052 // Failure.
02053
02054 ACE_ERROR ((LM_ERROR,
02055 "Asynch_Transmit_File failed.\n"));
02056
02057 ACE_SEH_TRY
02058 {
02059 this->result_->complete (this->bytes_transferred_,
02060 0, // Failure.
02061 0, // @@ Completion key.
02062 0); // @@ Error no.
02063 }
02064 ACE_SEH_FINALLY
02065 {
02066 // This is crucial to prevent memory leaks. This deletes
02067 // the result pointer also.
02068 delete this;
02069 }
02070 }
02071
02072 // Write stream successful.
02073
02074 // Partial write to socket.
02075 int unsent_data = result.bytes_to_write () - result.bytes_transferred ();
02076 if (unsent_data != 0)
02077 {
02078 ACE_DEBUG ((LM_DEBUG,
02079 "%N:%l:Partial write to socket: Asynch_write called again\n"));
02080
02081 // Duplicate the message block and retry remaining data
02082 if (this->ws_.write (*result.message_block ().duplicate (),
02083 unsent_data,
02084 result.act (),
02085 this->result_->priority (),
02086 this->result_->signal_number ()) == -1)
02087 {
02088 // @@ Handle this error.
02089 ACE_ERROR ((LM_ERROR,
02090 "Asynch_Transmit_Handler:write_stream failed\n"));
02091 return;
02092 }
02093
02094 // @@ Handling *partial write* to a socket. Let us not continue
02095 // further before this write finishes. Because proceeding with
02096 // another read and then write might change the order of the
02097 // file transmission, because partial write to the stream is
02098 // always possible.
02099 return;
02100 }
02101
02102 // Not a partial write. A full write.
02103
02104 // Check ACT to see what was sent.
02105 ACT act = * (ACT *) result.act ();
02106
02107 switch (act)
02108 {
02109 case TRAILER_ACT:
02110 // If it is the "trailer" that is just sent, then transmit file
02111 // is complete.
02112 // Call the application handler.
02113 ACE_SEH_TRY
02114 {
02115 this->result_->complete (this->bytes_transferred_,
02116 1, // @@ Success.
02117 0, // @@ Completion key.
02118 0); // @@ Errno.
02119 }
02120 ACE_SEH_FINALLY
02121 {
02122 delete this;
02123 }
02124 break;
02125
02126 case HEADER_ACT:
02127 case DATA_ACT:
02128 // If header/data was sent, initiate the file data transmission.
02129 if (this->initiate_read_file () == -1)
02130 // @@ Handle this error.
02131 ACE_ERROR ((LM_ERROR,
02132 "Error:Asynch_Transmit_Handler:read_file couldnt be initiated\n"));
02133 break;
02134
02135 default:
02136 // @@ Handle this error.
02137 ACE_ERROR ((LM_ERROR,
02138 "Error:ACE_Asynch_Transmit_Handler::handle_write_stream::Unexpected act\n"));
02139 }
02140 }
|
|
|
Issue asynch read from the file.
Definition at line 2185 of file POSIX_Asynch_IO.cpp. References ACE_ERROR_RETURN, file_offset_, file_size_, ACE_POSIX_Asynch_Transmit_File_Result::header_and_trailer, LM_ERROR, mb_, ACE_POSIX_Asynch_Result::priority, ACE_Message_Block::rd_ptr, ACE_POSIX_Asynch_Read_File::read, result_, rf_, ACE_POSIX_Asynch_Result::signal_number, trailer_act_, ACE_Asynch_Transmit_File::Header_And_Trailer::trailer_bytes, ACE_Message_Block::wr_ptr, ACE_POSIX_Asynch_Write_Stream::write, and ws_. Referenced by handle_write_stream.
02186 {
02187 // Is there something to read.
02188 if (this->file_offset_ >= this->file_size_)
02189 {
02190 // File is sent. Send the trailer.
02191 if (this->ws_.write (*this->result_->header_and_trailer ()->trailer (),
02192 this->result_->header_and_trailer ()->trailer_bytes (),
02193 (void *)&this->trailer_act_,
02194 this->result_->priority (),
02195 this->result_->signal_number ()) == -1)
02196 ACE_ERROR_RETURN ((LM_ERROR,
02197 "Error:Asynch_Transmit_Handler:write_stream writing trailer failed\n"),
02198 -1);
02199 return 0;
02200 }
02201 else
02202 {
02203 // @@ Is this right??
02204 // Previous reads and writes are over. For the new read, adjust
02205 // the wr_ptr and the rd_ptr to the beginning.
02206 this->mb_->rd_ptr (this->mb_->base ());
02207 this->mb_->wr_ptr (this->mb_->base ());
02208
02209 // Inititiate an asynchronous read from the file.
02210 if (this->rf_.read (*this->mb_,
02211 this->mb_->size () - 1,
02212 this->file_offset_,
02213 0, // @@ offset_high !!! if aiocb64 is used.
02214 0, // Act
02215 this->result_->priority (),
02216 this->result_->signal_number ()) == -1)
02217 ACE_ERROR_RETURN ((LM_ERROR,
02218 "Error:Asynch_Transmit_Handler::read from file failed\n"),
02219 -1);
02220 return 0;
02221 }
02222 }
|
|
|
Do the transmission. All the info to do the transmission is in the <result> member.
Definition at line 2007 of file POSIX_Asynch_IO.cpp. References ACE_ERROR_RETURN, ACE_POSIX_Asynch_Transmit_File_Result::header_and_trailer, ACE_Asynch_Transmit_File::Header_And_Trailer::header_bytes, LM_ERROR, ACE_POSIX_Asynch_Operation::open, result_, rf_, ACE_POSIX_Asynch_Write_Stream::write, and ws_. Referenced by ACE_POSIX_Asynch_Transmit_File::transmit_file.
02008 {
02009 // No proactor is given for the <open>'s. Because we are using the
02010 // concrete implementations of the Asynch_Operations, and we have
02011 // already given them the specific proactor, so they wont need the
02012 // general <proactor> interface pointer.
02013
02014 // Open Asynch_Read_File.
02015 if (this->rf_.open (*this,
02016 this->result_->file (),
02017 0,
02018 0) == -1)
02019 ACE_ERROR_RETURN ((LM_ERROR,
02020 "ACE_Asynch_Transmit_Handler:read_file open failed\n"),
02021 -1);
02022
02023 // Open Asynch_Write_Stream.
02024 if (this->ws_.open (*this,
02025 this->result_->socket (),
02026 0,
02027 0) == -1)
02028 ACE_ERROR_RETURN ((LM_ERROR,
02029 "ACE_Asynch_Transmit_Handler:write_stream open failed\n"),
02030 -1);
02031
02032 // Transmit the header.
02033 if (this->ws_.write (*this->result_->header_and_trailer ()->header (),
02034 this->result_->header_and_trailer ()->header_bytes (),
02035 ACE_reinterpret_cast (void *, &this->header_act_),
02036 0) == -1)
02037 ACE_ERROR_RETURN ((LM_ERROR,
02038 "Asynch_Transmit_Handler:transmitting header:write_stream failed\n"),
02039 -1);
02040 return 0;
02041 }
|
|
|
Number of bytes transferred on the stream.
Definition at line 1952 of file POSIX_Asynch_IO.cpp. Referenced by handle_write_stream. |
|
|
ACT to transmit data.
Definition at line 1940 of file POSIX_Asynch_IO.cpp. Referenced by handle_read_file. |
|
|
Current offset of the file being transmitted.
Definition at line 1946 of file POSIX_Asynch_IO.cpp. Referenced by handle_read_file, and initiate_read_file. |
|
|
Total size of the file.
Definition at line 1949 of file POSIX_Asynch_IO.cpp. Referenced by initiate_read_file. |
|
|
ACT to transmit header.
Definition at line 1937 of file POSIX_Asynch_IO.cpp. |
|
|
Message bloack used to do the transmission.
Definition at line 1927 of file POSIX_Asynch_IO.cpp. Referenced by initiate_read_file, and ~ACE_POSIX_Asynch_Transmit_Handler. |
|
|
The asynch result pointer made from the initial transmit file request.
Definition at line 1924 of file POSIX_Asynch_IO.cpp. Referenced by handle_read_file, handle_write_stream, initiate_read_file, transmit, and ~ACE_POSIX_Asynch_Transmit_Handler. |
|
|
To read from the file to be transmitted.
Definition at line 1964 of file POSIX_Asynch_IO.cpp. Referenced by initiate_read_file, and transmit. |
|
|
ACT to transmit trailer.
Definition at line 1943 of file POSIX_Asynch_IO.cpp. Referenced by initiate_read_file. |
|
|
Write stream to write the header, trailer and the data.
Definition at line 1967 of file POSIX_Asynch_IO.cpp. Referenced by handle_read_file, handle_write_stream, initiate_read_file, and transmit. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002