예제 #1
0
herror_t
httpd_init(int argc, char **argv)
{
  herror_t status;

  _httpd_parse_arguments(argc, argv);

  if ((status = hsocket_module_init(argc, argv)) != H_OK)
  {
    log_error("hsocket_modeule_init failed (%s)", herror_message(status));
    return status;
  } 

  _httpd_connection_slots_init();

  if ((status = _httpd_register_builtin_services(argc, argv)) != H_OK)
  {
    log_error("_httpd_register_builtin_services failed (%s)", herror_message(status));
    return status;
  }

  if ((status = hsocket_init(&_httpd_socket)) != H_OK)
  {
    log_error("hsocket_init failed (%s)", herror_message(status));
    return status;
  }

  if ((status = hsocket_bind(&_httpd_socket, _httpd_port)) != H_OK)
  {
    log_error("hsocket_bind failed (%s)", herror_message(status));
    return status;
  }

  return H_OK;
}
/*--------------------------------------------------
FUNCTION: httpc_new
DESC: Creates a new http client connection object
You need to create at least 1 http client connection
to communicate via http.
----------------------------------------------------*/
httpc_conn_t *
httpc_new(void)
{
  static int counter = 10000;
  herror_t status;
  httpc_conn_t *res;
 
  if (!(res = (httpc_conn_t *) malloc(sizeof(httpc_conn_t))))
    return NULL;

  if ((status = hsocket_init(&res->sock)) != H_OK)
  {
    log_warn2("hsocket_init failed (%s)", herror_message(status));
    return NULL;
  }

  res->header = NULL;
  res->version = HTTP_1_1;
  res->out = NULL;
  res->_dime_package_nr = 0;
  res->_dime_sent_bytes = 0;
  res->id = counter++;

  return res;
}
예제 #3
0
static void
_httpd_connection_slots_init(void)
{
  int i;

#ifdef WIN32
  _httpd_connection_lock = CreateMutex( NULL, TRUE, _httpd_connection_lock_str );
#else
  pthread_mutex_init(&_httpd_connection_lock, NULL);
#endif

  _httpd_connection = calloc(_httpd_max_connections, sizeof(conndata_t));
  for (i = 0; i < _httpd_max_connections; i++)
    hsocket_init(&(_httpd_connection[i].sock));

  return;
}