ACE_POSIX_Asynch_Transmit_Handler Class Reference

Auxillary handler for doing in Unix. internally uses this. More...

Inheritance diagram for ACE_POSIX_Asynch_Transmit_Handler:

Inheritance graph
[legend]
Collaboration diagram for ACE_POSIX_Asynch_Transmit_Handler:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ACE_POSIX_Asynch_Transmit_Handler (ACE_POSIX_Proactor *posix_proactor, ACE_POSIX_Asynch_Transmit_File_Result *result)
virtual ~ACE_POSIX_Asynch_Transmit_Handler (void)
 Destructor.

int transmit (void)

Protected Types

enum  ACT { HEADER_ACT = 1, DATA_ACT = 2, TRAILER_ACT = 3 }

Protected Member Functions

virtual void handle_write_stream (const ACE_Asynch_Write_Stream::Result &result)
 This is called when asynchronous writes from the socket complete.

virtual void handle_read_file (const ACE_Asynch_Read_File::Result &result)
 This is called when asynchronous reads from the file complete.

int initiate_read_file (void)
 Issue asynch read from the file.


Protected Attributes

ACE_POSIX_Asynch_Transmit_File_Resultresult_
ACE_Message_Blockmb_
 Message bloack used to do the transmission.

ACT header_act_
 ACT to transmit header.

ACT data_act_
 ACT to transmit data.

ACT trailer_act_
 ACT to transmit trailer.

size_t file_offset_
 Current offset of the file being transmitted.

size_t file_size_
 Total size of the file.

size_t bytes_transferred_
 Number of bytes transferred on the stream.

ACE_POSIX_Asynch_Read_File rf_
 To read from the file to be transmitted.

ACE_POSIX_Asynch_Write_Stream ws_
 Write stream to write the header, trailer and the data.


Detailed Description

Auxillary handler for doing in Unix. internally uses this.

This is a helper class for implementing in Unix systems.

Definition at line 1734 of file POSIX_Asynch_IO.cpp.


Member Enumeration Documentation

enum ACE_POSIX_Asynch_Transmit_Handler::ACT [protected]
 

Enumeration values:
HEADER_ACT 
DATA_ACT 
TRAILER_ACT 

Definition at line 1759 of file POSIX_Asynch_IO.cpp.

Referenced by handle_write_stream().

01760   {
01761     HEADER_ACT  = 1,
01762     DATA_ACT    = 2,
01763     TRAILER_ACT = 3
01764   };


Constructor & Destructor Documentation

ACE_POSIX_Asynch_Transmit_Handler::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).

Definition at line 1804 of file POSIX_Asynch_IO.cpp.

References ACE_NEW, and ACE_OS::filesize().

01806   : result_ (result),
01807     mb_ (0),
01808     header_act_ (this->HEADER_ACT),
01809     data_act_ (this->DATA_ACT),
01810     trailer_act_ (this->TRAILER_ACT),
01811     file_offset_ (result->offset ()),
01812     file_size_ (0),
01813     bytes_transferred_ (0),
01814     rf_ (posix_proactor),
01815     ws_ (posix_proactor)
01816 {
01817   // Allocate memory for the message block.
01818   ACE_NEW (this->mb_,
01819            ACE_Message_Block (this->result_->bytes_per_send ()
01820                               + 1));
01821   // Init the file size.
01822   file_size_ = ACE_OS::filesize (this->result_->file ());
01823 }

ACE_POSIX_Asynch_Transmit_Handler::~ACE_POSIX_Asynch_Transmit_Handler void   )  [virtual]
 

Destructor.

Definition at line 1826 of file POSIX_Asynch_IO.cpp.

References mb_, ACE_Message_Block::release(), result_, and ~ACE_POSIX_Asynch_Transmit_Handler().

Referenced by ~ACE_POSIX_Asynch_Transmit_Handler().

01827 {
01828   delete result_;
01829   mb_->release ();
01830 }


Member Function Documentation

void ACE_POSIX_Asynch_Transmit_Handler::handle_read_file const ACE_Asynch_Read_File::Result result  )  [protected, virtual]
 

This is called when asynchronous reads from the file complete.

Reimplemented from ACE_Handler.

Definition at line 1973 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_, handle_read_file(), 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_.

Referenced by handle_read_file().

01974 {
01975   // Failure.
01976   if (result.success () == 0)
01977     {
01978       //
01979       ACE_SEH_TRY
01980         {
01981           this->result_->complete (this->bytes_transferred_,
01982                                    0,      // Failure.
01983                                    0,      // @@ Completion key.
01984                                    errno); // Error no.
01985         }
01986       ACE_SEH_FINALLY
01987         {
01988           delete this;
01989         }
01990       return;
01991     }
01992 
01993   // Read successful.
01994   if (result.bytes_transferred () == 0)
01995     return;
01996 
01997   // Increment offset.
01998   this->file_offset_ += result.bytes_transferred ();
01999 
02000   // Write data to network.
02001   if (this->ws_.write (result.message_block (),
02002                        result.bytes_transferred (),
02003                        (void *)&this->data_act_,
02004                        this->result_->priority (),
02005                        this->result_->signal_number ()) == -1)
02006     {
02007       // @@ Handle this error.
02008       ACE_ERROR ((LM_ERROR,
02009                   "Error:ACE_Asynch_Transmit_File : write to the stream failed\n"));
02010       return;
02011     }
02012 }

void ACE_POSIX_Asynch_Transmit_Handler::handle_write_stream const ACE_Asynch_Write_Stream::Result result  )  [protected, virtual]
 

This is called when asynchronous writes from the socket complete.

Reimplemented from ACE_Handler.

Definition at line 1874 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(), handle_write_stream(), 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_.

Referenced by handle_write_stream().

01875 {
01876   // Update bytes transferred so far.
01877   this->bytes_transferred_ += result.bytes_transferred ();
01878 
01879   // Check the success parameter.
01880   if (result.success () == 0)
01881     {
01882       // Failure.
01883 
01884       ACE_ERROR ((LM_ERROR,
01885                   "Asynch_Transmit_File failed.\n"));
01886 
01887       ACE_SEH_TRY
01888         {
01889           this->result_->complete (this->bytes_transferred_,
01890                                    0,      // Failure.
01891                                    0,      // @@ Completion key.
01892                                    0);     // @@ Error no.
01893         }
01894       ACE_SEH_FINALLY
01895         {
01896           // This is crucial to prevent memory leaks. This deletes
01897           // the result pointer also.
01898           delete this;
01899         }
01900     }
01901 
01902   // Write stream successful.
01903 
01904   // Partial write to socket.
01905   size_t unsent_data = result.bytes_to_write () - result.bytes_transferred ();
01906   if (unsent_data != 0)
01907     {
01908       ACE_DEBUG ((LM_DEBUG,
01909                   "%N:%l:Partial write to socket: Asynch_write called again\n"));
01910 
01911       // Duplicate the message block and retry remaining data
01912       if (this->ws_.write (*result.message_block ().duplicate (),
01913                            unsent_data,
01914                            result.act (),
01915                            this->result_->priority (),
01916                            this->result_->signal_number ()) == -1)
01917         {
01918           // @@ Handle this error.
01919           ACE_ERROR ((LM_ERROR,
01920                       "Asynch_Transmit_Handler:write_stream failed\n"));
01921           return;
01922         }
01923 
01924       // @@ Handling *partial write* to a socket.  Let us not continue
01925       // further before this write finishes. Because proceeding with
01926       // another read and then write might change the order of the
01927       // file transmission, because partial write to the stream is
01928       // always possible.
01929       return;
01930     }
01931 
01932   // Not a partial write. A full write.
01933 
01934   // Check ACT to see what was sent.
01935   ACT act = * (ACT *) result.act ();
01936 
01937   switch (act)
01938     {
01939     case TRAILER_ACT:
01940       // If it is the "trailer" that is just sent, then transmit file
01941       // is complete.
01942       // Call the application handler.
01943       ACE_SEH_TRY
01944         {
01945           this->result_->complete (this->bytes_transferred_,
01946                                    1,      // @@ Success.
01947                                    0,      // @@ Completion key.
01948                                    0);     // @@ Errno.
01949         }
01950       ACE_SEH_FINALLY
01951         {
01952           delete this;
01953         }
01954       break;
01955 
01956     case HEADER_ACT:
01957     case DATA_ACT:
01958       // If header/data was sent, initiate the file data transmission.
01959       if (this->initiate_read_file () == -1)
01960         // @@ Handle this error.
01961         ACE_ERROR ((LM_ERROR,
01962                     "Error:Asynch_Transmit_Handler:read_file couldnt be initiated\n"));
01963       break;
01964 
01965     default:
01966       // @@ Handle this error.
01967       ACE_ERROR ((LM_ERROR,
01968                   "Error:ACE_Asynch_Transmit_Handler::handle_write_stream::Unexpected act\n"));
01969     }
01970 }

int ACE_POSIX_Asynch_Transmit_Handler::initiate_read_file void   )  [protected]
 

Issue asynch read from the file.

Definition at line 2015 of file POSIX_Asynch_IO.cpp.

References ACE_ERROR_RETURN, file_offset_, file_size_, ACE_POSIX_Asynch_Transmit_File_Result::header_and_trailer(), initiate_read_file(), 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(), and initiate_read_file().

02016 {
02017   // Is there something to read.
02018   if (this->file_offset_ >= this->file_size_)
02019     {
02020       // File is sent. Send the trailer.
02021       if (this->ws_.write (*this->result_->header_and_trailer ()->trailer (),
02022                            this->result_->header_and_trailer ()->trailer_bytes (),
02023                            (void *)&this->trailer_act_,
02024                            this->result_->priority (),
02025                            this->result_->signal_number ()) == -1)
02026         ACE_ERROR_RETURN ((LM_ERROR,
02027                            "Error:Asynch_Transmit_Handler:write_stream writing trailer failed\n"),
02028                           -1);
02029       return 0;
02030     }
02031   else
02032     {
02033       // @@ Is this right??
02034       // Previous reads and writes are over. For the new read, adjust
02035       // the wr_ptr and the rd_ptr to the beginning.
02036       this->mb_->rd_ptr (this->mb_->base ());
02037       this->mb_->wr_ptr (this->mb_->base ());
02038 
02039       // Inititiate an asynchronous read from the file.
02040       if (this->rf_.read (*this->mb_,
02041                           this->mb_->size () - 1,
02042                           this->file_offset_,
02043                           0, // @@ offset_high !!! if aiocb64 is used.
02044                           0, // Act
02045                           this->result_->priority (),
02046                           this->result_->signal_number ()) == -1)
02047         ACE_ERROR_RETURN ((LM_ERROR,
02048                            "Error:Asynch_Transmit_Handler::read from file failed\n"),
02049                           -1);
02050       return 0;
02051     }
02052 }

int ACE_POSIX_Asynch_Transmit_Handler::transmit void   ) 
 

Do the transmission. All the info to do the transmission is in the member.

Definition at line 1837 of file POSIX_Asynch_IO.cpp.

References ACE_ERROR_RETURN, ACE_POSIX_Asynch_Transmit_File_Result::file(), header_act_, 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_Transmit_File_Result::socket(), transmit(), ACE_POSIX_Asynch_Write_Stream::write(), and ws_.

Referenced by transmit().

01838 {
01839   // No proactor is given for the <open>'s. Because we are using the
01840   // concrete implementations of the  Asynch_Operations, and we have
01841   // already given them the specific proactor, so they wont need the
01842   // general <proactor> interface pointer.
01843 
01844   // Open Asynch_Read_File.
01845   if (this->rf_.open (this->proxy (),
01846                       this->result_->file (),
01847                       0,
01848                       0) == -1)
01849     ACE_ERROR_RETURN ((LM_ERROR,
01850                        "ACE_Asynch_Transmit_Handler:read_file open failed\n"),
01851                       -1);
01852 
01853   // Open Asynch_Write_Stream.
01854   if (this->ws_.open (this->proxy (),
01855                       this->result_->socket (),
01856                       0,
01857                       0) == -1)
01858     ACE_ERROR_RETURN ((LM_ERROR,
01859                        "ACE_Asynch_Transmit_Handler:write_stream open failed\n"),
01860                       -1);
01861 
01862   // Transmit the header.
01863   if (this->ws_.write (*this->result_->header_and_trailer ()->header (),
01864                        this->result_->header_and_trailer ()->header_bytes (),
01865                        reinterpret_cast<void *> (&this->header_act_),
01866                        0) == -1)
01867     ACE_ERROR_RETURN ((LM_ERROR,
01868                        "Asynch_Transmit_Handler:transmitting header:write_stream failed\n"),
01869                       -1);
01870   return 0;
01871 }


Member Data Documentation

size_t ACE_POSIX_Asynch_Transmit_Handler::bytes_transferred_ [protected]
 

Number of bytes transferred on the stream.

Definition at line 1782 of file POSIX_Asynch_IO.cpp.

Referenced by handle_write_stream().

ACT ACE_POSIX_Asynch_Transmit_Handler::data_act_ [protected]
 

ACT to transmit data.

Definition at line 1770 of file POSIX_Asynch_IO.cpp.

Referenced by handle_read_file().

size_t ACE_POSIX_Asynch_Transmit_Handler::file_offset_ [protected]
 

Current offset of the file being transmitted.

Definition at line 1776 of file POSIX_Asynch_IO.cpp.

Referenced by handle_read_file(), and initiate_read_file().

size_t ACE_POSIX_Asynch_Transmit_Handler::file_size_ [protected]
 

Total size of the file.

Definition at line 1779 of file POSIX_Asynch_IO.cpp.

Referenced by initiate_read_file().

ACT ACE_POSIX_Asynch_Transmit_Handler::header_act_ [protected]
 

ACT to transmit header.

Definition at line 1767 of file POSIX_Asynch_IO.cpp.

Referenced by transmit().

ACE_Message_Block* ACE_POSIX_Asynch_Transmit_Handler::mb_ [protected]
 

Message bloack used to do the transmission.

Definition at line 1757 of file POSIX_Asynch_IO.cpp.

Referenced by initiate_read_file(), and ~ACE_POSIX_Asynch_Transmit_Handler().

ACE_POSIX_Asynch_Transmit_File_Result* ACE_POSIX_Asynch_Transmit_Handler::result_ [protected]
 

The asynch result pointer made from the initial transmit file request.

Definition at line 1754 of file POSIX_Asynch_IO.cpp.

Referenced by handle_read_file(), handle_write_stream(), initiate_read_file(), transmit(), and ~ACE_POSIX_Asynch_Transmit_Handler().

ACE_POSIX_Asynch_Read_File ACE_POSIX_Asynch_Transmit_Handler::rf_ [protected]
 

To read from the file to be transmitted.

Definition at line 1794 of file POSIX_Asynch_IO.cpp.

Referenced by initiate_read_file(), and transmit().

ACT ACE_POSIX_Asynch_Transmit_Handler::trailer_act_ [protected]
 

ACT to transmit trailer.

Definition at line 1773 of file POSIX_Asynch_IO.cpp.

Referenced by initiate_read_file().

ACE_POSIX_Asynch_Write_Stream ACE_POSIX_Asynch_Transmit_Handler::ws_ [protected]
 

Write stream to write the header, trailer and the data.

Definition at line 1797 of file POSIX_Asynch_IO.cpp.

Referenced by handle_read_file(), handle_write_stream(), initiate_read_file(), and transmit().


The documentation for this class was generated from the following file:
Generated on Thu Nov 9 11:26:53 2006 for ACE by doxygen 1.3.6