Пример #1
0
static gearmand_error_t _thread_packet_read(gearman_server_con_st *con)
{
  while (1)
  {
    if (con->packet == NULL)
    {
      if (! (con->packet= gearman_server_packet_create(con->thread, true)))
      {
        return GEARMAN_MEMORY_ALLOCATION_FAILURE;
      }
    }

    gearmand_error_t ret;
    if (gearmand_failed(ret= gearman_io_recv(con, true)))
    {
      if (ret == GEARMAN_IO_WAIT)
      {
        break;
      }

      gearman_server_packet_free(con->packet, con->thread, true);
      con->packet= NULL;
      return ret;
    }

    gearmand_log_debug(GEARMAN_DEFAULT_LOG_PARAM,
                       "Received %s %s:%u",
                       gearman_command_info(con->packet->packet.command)->name,
                       con->_host == NULL ? "-" : con->_host,
                       con->_port == NULL ? "-" : con->_port);

    /* We read a complete packet. */
    if (Server->flags.threaded)
    {
      /* Multi-threaded, queue for the processing thread to run. */
      gearman_server_proc_packet_add(con, con->packet);
      con->packet= NULL;
    }
    else
    {
      /* Single threaded, run the command here. */
      gearmand_error_t rc= gearman_server_run_command(con, &(con->packet->packet));
      gearmand_packet_free(&(con->packet->packet));
      gearman_server_packet_free(con->packet, con->thread, true);
      con->packet= NULL;
      if (gearmand_failed(rc))
      {
        return rc;
      }
    }
  }

  return GEARMAN_SUCCESS;
}
Пример #2
0
gearman_return_t _thread_packet_read(gearman_server_con_st *con)
{
  gearman_return_t ret;

  while (1)
  {
    if (con->packet == NULL)
    {
      con->packet= gearman_server_packet_create(con->thread, true);
      if (con->packet == NULL)
        return GEARMAN_MEMORY_ALLOCATION_FAILURE;
    }

    (void)gearman_connection_recv(&(con->con), &(con->packet->packet), &ret, true);
    if (ret != GEARMAN_SUCCESS)
    {
      if (ret == GEARMAN_IO_WAIT)
        break;

      gearman_server_packet_free(con->packet, con->thread, true);
      con->packet= NULL;
      return ret;
    }

    gearman_log_debug(con->thread->gearman, "%15s:%5s Received  %s",
                      con->host == NULL ? "-" : con->host,
                      con->port == NULL ? "-" : con->port,
                      gearman_command_info_list[con->packet->packet.command].name);

    /* We read a complete packet. */
    if (con->thread->server->flags.threaded)
    {
      /* Multi-threaded, queue for the processing thread to run. */
      gearman_server_proc_packet_add(con, con->packet);
      con->packet= NULL;
    }
    else
    {
      /* Single threaded, run the command here. */
      ret= gearman_server_run_command(con, &(con->packet->packet));
      gearman_packet_free(&(con->packet->packet));
      gearman_server_packet_free(con->packet, con->thread, true);
      con->packet= NULL;
      if (ret != GEARMAN_SUCCESS)
        return ret;
    }
  }

  return GEARMAN_SUCCESS;
}