int JAWS_Pipeline_Accept_Task::handle_put (JAWS_Data_Block *data, ACE_Time_Value *) { int result = -1; // JAWS_Data_Block should contain an INET_Addr and an IO JAWS_IO_Handler *handler = data->io_handler (); JAWS_Dispatch_Policy *policy = this->policy (); if (policy == 0) policy = data->policy (); // data->policy ()->update (handler); JAWS_IO *io = policy->io (); io->accept (handler); // When accept returns, the resulting handle should be stored into // the JAWS_DATA_BLOCK somewhere. // Check the handler for status of the io call switch (handler->status ()) { case JAWS_IO_Handler::ACCEPT_OK: { ACE_DEBUG ((LM_DEBUG, "(%t) ACCEPT_OK\n")); result = 0; JAWS_TRACE ("JAWS_Pipeline_Accept_Task::handle_put ACCEPT_OK"); // Move on to next stage in pipeline break; } case JAWS_IO_Handler::ACCEPT_ERROR: { ACE_DEBUG ((LM_DEBUG, "(%t) ACCEPT_ERROR\n")); result = -1; JAWS_TRACE ("JAWS_Pipeline_Accept_Task::handle_put ACCEPT_ERROR"); // Should recycle the thread break; } default: { result = 1; JAWS_TRACE ("JAWS_Pipeline_Accept_Task::handle_put ACCEPT_IDLE"); // Should mean that the IO is asynchronous, and the word isn't out // yet. break; } } // In asynchronous and synchronous models, we can -- // have the io_handler set the new task in the data_block // In asynchronous model, we can -- // insert a wait task into the task queue ACE_DEBUG ((LM_DEBUG, "(%t) Returning %d\n", result)); return result; }
void JAWS_Asynch_Handler::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result) { JAWS_TRACE ("JAWS_Asynch_Handler::handle_read_stream"); this->dispatch_handler (); if (result.act () != 0) { // This callback is for io->receive_file() JAWS_TRACE ("JAWS_Asynch_Handler::handle_read_stream (recv_file)"); int code = 0; if (result.success () && result.bytes_transferred () != 0) { if (result.message_block ().length () == result.message_block ().size ()) code = ACE_Filecache_Handle::ACE_SUCCESS; else { ACE_Asynch_Read_Stream ar; if (ar.open (*this, this->handler ()->handle ()) == -1 || ar.read (result.message_block (), result.message_block ().size () - result.message_block ().length (), result.act ()) == -1) code = -1; else return; } } else code = -1; if (code == ACE_Filecache_Handle::ACE_SUCCESS) this->handler ()->receive_file_complete (); else this->handler ()->receive_file_error (code); result.message_block ().release (); delete (ACE_Filecache_Handle *) result.act (); } else { // This callback is for this->read() JAWS_TRACE ("JAWS_Asynch_Handler::handle_read_stream (read)"); if (result.success () && result.bytes_transferred () != 0) this->handler ()->read_complete (&result.message_block ()); else this->handler ()->read_error (); } }
void JAWS_Asynch_Handler::handle_accept (const ACE_Asynch_Accept::Result &result) { JAWS_TRACE ("JAWS_Asynch_Handler::handle_accept"); this->dispatch_handler (); if (result.success ()) { JAWS_TRACE ("JAWS_Asynch_Handler::handle_accept, success"); this->handler ()->accept_complete (result.accept_handle ()); } else this->handler ()->accept_error (); }
JAWS_IO_Handler * JAWS_Pipeline_Accept_Task::new_handler (JAWS_Data_Block *data) { // Create a new handler and message block JAWS_Data_Block *ndb = new JAWS_Data_Block (*data); if (ndb == 0) { JAWS_TRACE ("JAWS_Pipeline_Accept_Task::new_handler, failed DB"); return 0; } JAWS_Dispatch_Policy *policy = (this->policy () == 0) ? data->policy () : this->policy (); JAWS_IO_Handler_Factory *ioh_factory = policy->ioh_factory (); JAWS_IO_Handler *nioh = ioh_factory->create_io_handler (); if (nioh == 0) { delete ndb; return 0; } ndb->io_handler (nioh); nioh->task (data->task ()); nioh->message_block (ndb); return nioh; }
void JAWS_Asynch_Handler::open (ACE_HANDLE h, ACE_Message_Block &mb) { JAWS_TRACE ("JAWS_Asynch_Handler::open"); // This currently does nothing, but just in case. ACE_Service_Handler::open (h, mb); // ioh_ set from the ACT hopefully //this->dispatch_handler (); #if !defined (ACE_WIN32) // Assume at this point there is no data. mb.rd_ptr (mb.wr_ptr ()); mb.crunch (); #else // AcceptEx reads some initial data from the socket. this->handler ()->message_block ()->copy (mb.rd_ptr (), mb.length ()); #endif ACE_Asynch_Accept_Result_Impl *fake_result = ACE_Proactor::instance ()->create_asynch_accept_result (this->proxy (), JAWS_IO_Asynch_Acceptor_Singleton::instance ()->get_handle (), h, mb, JAWS_Data_Block::JAWS_DATA_BLOCK_SIZE, this->ioh_, ACE_INVALID_HANDLE, 0); this->handler ()->handler_ = this; fake_result->complete (0, 1, 0); }
void JAWS_IO_Handler::transmit_file_complete (void) { JAWS_TRACE ("JAWS_IO_Handler::transmit_file_complete"); // this->pipeline_->transmit_file_complete (); this->status_ |= TRANSMIT_OK; this->status_ &= (TRANSMIT_OK+1); }
void JAWS_Asynch_Handler::act (const void *act_ref) { JAWS_TRACE ("JAWS_Asynch_Handler::act"); // Set the ioh from the act this->ioh_ = (JAWS_Asynch_IO_Handler *) act_ref; }
void JAWS_IO_Handler::transmit_file_error (int result) { JAWS_TRACE ("JAWS_IO_Handler::transmit_file_error"); ACE_UNUSED_ARG (result); // this->pipeline_->transmit_file_complete (result); this->status_ |= TRANSMIT_ERROR; this->status_ &= (TRANSMIT_ERROR+1); }
void JAWS_IO_Handler_Factory::destroy_io_handler (JAWS_IO_Handler *handler) { JAWS_TRACE ("JAWS_IO_Handler_Factory::destroy"); if (handler != 0) { delete handler->message_block (); delete handler; } }
JAWS_IO_Handler * JAWS_Asynch_IO_Handler_Factory::create_io_handler (void) { JAWS_TRACE ("JAWS_Asynch_IO_Handler_Factory::create"); JAWS_Asynch_IO_Handler *handler = 0; handler = new JAWS_Asynch_IO_Handler (this); return handler; }
void JAWS_Asynch_IO::receive_file (JAWS_IO_Handler *ioh, const char *filename, void *initial_data, unsigned int initial_data_length, unsigned int entire_length) { JAWS_TRACE ("JAWS_Asynch_IO::receive_file"); ioh->idle (); JAWS_Asynch_IO_Handler *aioh = dynamic_cast<JAWS_Asynch_IO_Handler *> (ioh); ACE_Message_Block *mb = 0; ACE_Filecache_Handle *handle; ACE_NEW (handle, ACE_Filecache_Handle (filename, entire_length, ACE_NOMAP)); int result = handle->error (); if (result == ACE_Filecache_Handle::ACE_SUCCESS) { ACE_OS::memcpy (handle->address (), initial_data, initial_data_length); int bytes_to_read = entire_length - initial_data_length; ACE_NEW (mb, ACE_Message_Block ((char *)handle->address () + initial_data_length, bytes_to_read)); if (mb == 0) { errno = ENOMEM; result = -1; } else { ACE_Asynch_Read_Stream ar; if (ar.open (*(aioh->handler ()), aioh->handle ()) == -1 || ar.read (*mb, mb->size () - mb->length (), handle) == -1) result = -1; } } if (result != ACE_Filecache_Handle::ACE_SUCCESS) { this->handler_->receive_file_error (result); delete mb; delete handle; } }
void JAWS_Synch_IO::read (JAWS_IO_Handler *ioh, ACE_Message_Block *mb, unsigned int size) { JAWS_TRACE ("JAWS_Synch_IO::read"); ACE_SOCK_Stream stream; stream.set_handle (ioh->handle ()); int result = stream.recv (mb->wr_ptr (), size); if (result <= 0) ioh->read_error (); else { JAWS_TRACE ("JAWS_Synch_IO::read success"); mb->wr_ptr (result); ioh->read_complete (mb); } }
void JAWS_Asynch_IO::transmit_file (JAWS_IO_Handler *ioh, ACE_HANDLE handle, const char *header, unsigned int header_size, const char *trailer, unsigned int trailer_size) { JAWS_TRACE ("JAWS_Asynch_IO::transmit_file"); ioh->idle (); JAWS_Asynch_IO_Handler *aioh = dynamic_cast<JAWS_Asynch_IO_Handler *> (ioh); ACE_Asynch_Transmit_File::Header_And_Trailer *header_and_trailer = 0; int result = 0; if (handle != ACE_INVALID_HANDLE) { ACE_Message_Block hdr_mb (header, header_size); ACE_Message_Block trl_mb (trailer, trailer_size); header_and_trailer = new ACE_Asynch_Transmit_File::Header_And_Trailer (hdr_mb.duplicate (), header_size, trl_mb.duplicate (), trailer_size); ACE_Asynch_Transmit_File tf; if (tf.open (*(aioh->handler ()), aioh->handle ()) == -1 || tf.transmit_file (handle, // file handle header_and_trailer, // header and trailer data 0, // bytes_to_write 0, // offset 0, // offset_high 0, // bytes_per_send 0, // flags 0 // act ) == -1) result = -1; } if (result != 0) { ioh->transmit_file_error (result); delete header_and_trailer; } }
void JAWS_Asynch_IO_Handler_Factory::destroy_io_handler (JAWS_IO_Handler *handler) { JAWS_TRACE ("JAWS_IO_Handler_Factory::destroy"); if (handler != 0) { //cerr << "(" << thr_self () << ") locking for destruction: " << handler << endl; handler->lock (); delete handler->message_block (); handler->message_block (0); delete handler; } }
int JAWS_HTTP_10_Parse_Task::handle_put (JAWS_Data_Block *data, ACE_Time_Value *) { JAWS_TRACE ("JAWS_HTTP_10_Parse_Task::handle_put"); JAWS_IO_Handler *handler = data->io_handler (); JAWS_Dispatch_Policy *policy = this->policy (); if (policy == 0) policy = data->policy (); JAWS_IO *io = policy->io (); JAWS_HTTP_10_Request *info; if (data->payload ()) info = ACE_reinterpret_cast (JAWS_HTTP_10_Request *, data->payload ()); else {
void JAWS_Asynch_IO::read (JAWS_IO_Handler *ioh, ACE_Message_Block* mb, unsigned int size) { JAWS_TRACE ("JAWS_Asynch_IO::read"); ioh->idle (); JAWS_Asynch_IO_Handler *aioh = dynamic_cast<JAWS_Asynch_IO_Handler *> (ioh); ACE_Asynch_Read_Stream ar; if (ar.open (*(aioh->handler ()), aioh->handle ()) == -1 || ar.read (*mb, size) == -1) aioh->read_error (); }
void JAWS_Asynch_IO::accept (JAWS_IO_Handler *ioh, ACE_Message_Block *, unsigned int) { JAWS_TRACE ("JAWS_Asynch_IO::accept"); ioh->idle (); JAWS_Data_Block *db = ioh->message_block (); //ACE_HANDLE listen_handle = db->policy ()->acceptor ()->get_handle (); //JAWS_Asynch_IO_Handler *aioh = // dynamic_cast<JAWS_Asynch_IO_Handler *> (ioh); size_t bytes_to_read = JAWS_Data_Block::JAWS_DATA_BLOCK_SIZE; if (db->policy ()->acceptor ()->accept (bytes_to_read, ioh) == -1) ioh->accept_error (); }
int JAWS_Pipeline_Done_Task::put (ACE_Message_Block *mb, ACE_Time_Value *) { JAWS_TRACE ("JAWS_Pipeline_Done_Task::put"); JAWS_Data_Block *data = dynamic_cast<JAWS_Data_Block *> (mb); JAWS_IO_Handler *handler = data->io_handler (); JAWS_Dispatch_Policy *policy = this->policy (); if (policy == 0) policy = data->policy (); // JAWS_IO *io = policy->io (); data->task (0); data->io_handler (0); if (handler) handler->done (); // hack, let Concurrency know we are done. return -2; }
int JAWS_HTTP_10_Write_Task::handle_put (JAWS_Data_Block *data, ACE_Time_Value *) { JAWS_TRACE ("JAWS_HTTP_10_Write_Task::handle_put"); JAWS_IO_Handler *handler = data->io_handler (); JAWS_Dispatch_Policy *policy = this->policy (); if (policy == 0) policy = data->policy (); JAWS_IO *io = policy->io (); JAWS_HTTP_10_Request *info = static_cast<JAWS_HTTP_10_Request *> (data->payload ()); if (info->status () == (int) JAWS_HTTP_10_Request::STATUS_QUIT) { data->payload (0); delete info; return -3; } #if 0 ACE_DEBUG ((LM_DEBUG, " (%t) request %s::%s::%s parsed\n", (info->method () ? info->method () : "-"), (info->uri () ? info->uri () : "="), (info->version () ? info->version () : "HTTP/0.9"))); #endif if (info->type () != (int) JAWS_HTTP_10_Request::GET) info->set_status (JAWS_HTTP_10_Request::STATUS_NOT_IMPLEMENTED); if (info->type () == (int) JAWS_HTTP_10_Request::QUIT) info->set_status (JAWS_HTTP_10_Request::STATUS_QUIT); if (info->status () != (int) JAWS_HTTP_10_Request::STATUS_OK) { JAWS_TRACE ("JAWS_HTTP_10_Write_Task::handle_put, ! STATUS OK"); char msg[] = "<html><head><title>HTTP/1.0 500 Internal Server Error</title>" "<body><h1>Server Error</h1>HTTP/1.0 500 Internal Server Error" "</body></html>"; io->send_error_message (handler, msg, sizeof (msg)); switch (handler->status ()) { case JAWS_IO_Handler::WRITE_OK: case JAWS_IO_Handler::WRITE_OK_A: if (info->status () == (int) JAWS_HTTP_10_Request::STATUS_QUIT) { data->payload (0); delete info; return -3; } data->payload (0); delete info; return 0; case JAWS_IO_Handler::WRITE_ERROR: case JAWS_IO_Handler::WRITE_ERROR_A: data->payload (0); delete info; return -1; default: return 2; } return 2; } else { if (ACE_OS::strcmp (info->version (), "HTTP/0.9") == 0) io->transmit_file (handler, info->path (), "", 0, "", 0); else io->transmit_file (handler, info->path (), "HTTP/1.0 200 Ok\r\n\r\n", 19, "", 0); switch (handler->status ()) { case JAWS_IO_Handler::TRANSMIT_OK_A: { JAWS_TRACE ("JAWS_HTTP_10_Write_Task::handle_put, OK_A"); data->payload (0); delete info; return 1; } case JAWS_IO_Handler::TRANSMIT_OK: { JAWS_TRACE ("JAWS_HTTP_10_Write_Task::handle_put, OK"); data->payload (0); delete info; return 0; } case JAWS_IO_Handler::TRANSMIT_ERROR: { JAWS_TRACE ("JAWS_HTTP_10_Write_Task::handle_put, ERROR"); data->payload (0); delete info; return 0; } case JAWS_IO_Handler::TRANSMIT_ERROR_A: { JAWS_TRACE ("JAWS_HTTP_10_Write_Task::handle_put, ERROR_A"); data->payload (0); delete info; return 1; } default: { JAWS_TRACE ("JAWS_HTTP_10_Write_Task::handle_put, DEFAULT"); data->payload (0); delete info; return 1; } } } data->payload (0); delete info; return -1; }