Esempio n. 1
0
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;
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
void
JAWS_IO_Handler::accept_complete (ACE_HANDLE handle)
{
  // callback into pipeline task, notify that the accept has completed
  this->handle_ = handle;
  this->status_ |= ACCEPT_OK;
  this->status_ &= (ACCEPT_OK+1);

  JAWS_Dispatch_Policy *policy = this->mb_->policy ();

  // Do this so that Thread Per Request can spawn a new thread
  policy->concurrency ()->activate_hook ();
}
Esempio n. 4
0
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
    {
Esempio n. 5
0
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;
}