Beispiel #1
0
static void on_net_thread_shutdown(nxe_subscriber* sub, nxe_publisher* pub, nxe_data data) {
  int i;
  nxweb_net_thread_data* tdata=(nxweb_net_thread_data*)((char*)sub-offsetof(nxweb_net_thread_data, shutdown_sub));
  //nxe_loop* loop=sub->super.loop;

  nxweb_log_error("shutting down net thread");

  nxe_unsubscribe(pub, sub);

  nxweb_server_listen_config* lconf;
  nxweb_http_server_listening_socket* lsock;
  for (i=0, lconf=nxweb_server_config.listen_config, lsock=tdata->listening_sock; i<NXWEB_MAX_LISTEN_SOCKETS; i++, lconf++, lsock++) {
    if (lconf->listen_fd) {
      nxe_unsubscribe(&lsock->listen_source.data_notify, &lsock->listen_sub);
      nxe_unregister_listenfd_source(&lsock->listen_source);
    }
  }

  nxe_unregister_eventfd_source(&tdata->shutdown_efs);
  nxe_finalize_eventfd_source(&tdata->shutdown_efs);
  nxe_unregister_eventfd_source(&tdata->diagnostics_efs);
  nxe_finalize_eventfd_source(&tdata->diagnostics_efs);

  nxw_finalize_factory(&tdata->workers_factory);

  // close keep-alive connections to backends
  for (i=0; i<NXWEB_MAX_PROXY_POOLS; i++) {
    nxd_http_proxy_pool_finalize(&tdata->proxy_pool[i]);
  }

  nxweb_access_log_thread_flush();
}
Beispiel #2
0
static void nxweb_http_server_connection_do_finalize(nxweb_http_server_connection* conn, int good) {
  //nxe_loop* loop=conn->sock.fs.data_is.super.loop;
  nxweb_http_server_connection_finalize_subrequests(conn, good);
  if (conn->worker_complete.pub) nxe_unsubscribe(conn->worker_complete.pub, &conn->worker_complete);
  conn->hsp.cls->finalize(&conn->hsp);
  if (conn->sock.cls) conn->sock.cls->finalize((nxd_socket*)&conn->sock, good);
  nxp_free(conn->tdata->free_conn_pool, conn);
  //if (!__sync_sub_and_fetch(&num_connections, 1)) nxweb_log_info("all connections closed");
}
Beispiel #3
0
void nxd_http_client_proto_finalize(nxd_http_client_proto* hcp) {
  nxe_loop* loop=hcp->data_in.super.loop;
  nxe_unset_timer(loop, NXWEB_TIMER_KEEP_ALIVE, &hcp->timer_keep_alive);
  nxe_unset_timer(loop, NXWEB_TIMER_READ, &hcp->timer_read);
  nxe_unset_timer(loop, NXWEB_TIMER_WRITE, &hcp->timer_write);
  nxe_unset_timer(loop, NXWEB_TIMER_100CONTINUE, &hcp->timer_100_continue);
  if (hcp->data_error.pub) nxe_unsubscribe(hcp->data_error.pub, &hcp->data_error);
  while (hcp->events_pub.sub) nxe_unsubscribe(&hcp->events_pub, hcp->events_pub.sub);
  if (hcp->data_in.pair) nxe_disconnect_streams(hcp->data_in.pair, &hcp->data_in);
  if (hcp->data_out.pair) nxe_disconnect_streams(&hcp->data_out, hcp->data_out.pair);
  if (hcp->req_body_in.pair) nxe_disconnect_streams(hcp->req_body_in.pair, &hcp->req_body_in);
  if (hcp->resp_body_out.pair) nxe_disconnect_streams(&hcp->resp_body_out, hcp->resp_body_out.pair);
  if (hcp->nxb) {
    nxb_empty(hcp->nxb);
    nxp_free(hcp->nxb_pool, hcp->nxb);
    hcp->nxb=0;
  }
}
Beispiel #4
0
static void nxweb_http_server_connection_worker_complete_on_message(nxe_subscriber* sub, nxe_publisher* pub, nxe_data data) {
  nxweb_http_server_connection* conn=OBJ_PTR_FROM_FLD_PTR(nxweb_http_server_connection, worker_complete, sub);
  nxe_unsubscribe(conn->worker_complete.pub, &conn->worker_complete);
  __sync_synchronize(); // full memory barrier
  conn->in_worker=0;
  long cnt=0;
  while (!conn->worker_job_done) cnt++;
  if (cnt) nxweb_log_warning("job not done in %ld steps", cnt);
  if (conn->connection_closing) {
    nxweb_http_server_connection_finalize(conn, 0);
  }
  else {
    nxweb_start_sending_response(conn, &conn->hsp._resp);
  }
}
Beispiel #5
0
void nxd_http_client_proto_rearm(nxd_http_client_proto* hcp) {
  assert(hcp->nxb);
  nxb_empty(hcp->nxb);
  nxp_free(hcp->nxb_pool, hcp->nxb);
  hcp->nxb=0;
  memset(&hcp->_req, 0, sizeof(hcp->_req));
  hcp->_req.nxb=hcp->nxb;
  hcp->_req.host=0;
  hcp->resp.nxb=hcp->nxb;
  while (hcp->events_pub.sub) nxe_unsubscribe(&hcp->events_pub, hcp->events_pub.sub);
  if (hcp->req_body_in.pair) nxe_disconnect_streams(hcp->req_body_in.pair, &hcp->req_body_in);
  if (hcp->resp_body_out.pair) nxe_disconnect_streams(&hcp->resp_body_out, hcp->resp_body_out.pair);
  nxe_ostream_unset_ready(&hcp->req_body_in);
  nxe_istream_unset_ready(&hcp->resp_body_out);
  nxe_ostream_unset_ready(&hcp->data_in);
  nxe_istream_unset_ready(&hcp->data_out);
}
Beispiel #6
0
static void retry_proxy_request(nxweb_http_proxy_request_data* rdata) {

  nxweb_log_debug("retry_proxy_request");

  nxd_http_proxy* hpx=rdata->hpx;
  nxweb_http_server_connection* conn=rdata->conn;

  enum nxd_http_server_proto_state state=conn->hsp.state;
  assert(state==HSP_RECEIVING_HEADERS || state==HSP_RECEIVING_BODY || state==HSP_HANDLING);

  nxd_http_proxy_pool_return(hpx, 1);
  if (rdata->rb_resp.data_in.pair) nxe_disconnect_streams(rdata->rb_resp.data_in.pair, &rdata->rb_resp.data_in);
  if (rdata->rb_resp.data_out.pair) nxe_disconnect_streams(&rdata->rb_resp.data_out, rdata->rb_resp.data_out.pair);
  if (rdata->rb_req.data_in.pair) nxe_disconnect_streams(rdata->rb_req.data_in.pair, &rdata->rb_req.data_in);
  if (rdata->rb_req.data_out.pair) nxe_disconnect_streams(&rdata->rb_req.data_out, rdata->rb_req.data_out.pair);
  if (rdata->proxy_events_sub.pub) nxe_unsubscribe(rdata->proxy_events_sub.pub, &rdata->proxy_events_sub);
  rdata->hpx=0;
  rdata->retry_count++;
  start_proxy_request(conn, &conn->hsp.req, rdata);
}
Beispiel #7
0
static void nxweb_http_proxy_request_finalize(nxd_http_server_proto* hsp, void* req_data) {

  nxweb_log_debug("nxweb_http_proxy_request_finalize");

  nxweb_http_proxy_request_data* rdata=req_data;
  nxweb_http_server_connection* conn=rdata->conn;
  nxe_loop* loop=conn->tdata->loop;
  nxe_unset_timer(loop, NXWEB_TIMER_BACKEND, &rdata->timer_backend);
  if (rdata->rb_resp.data_in.pair) nxe_disconnect_streams(rdata->rb_resp.data_in.pair, &rdata->rb_resp.data_in);
  if (rdata->rb_resp.data_out.pair) nxe_disconnect_streams(&rdata->rb_resp.data_out, rdata->rb_resp.data_out.pair);
  if (rdata->rb_req.data_in.pair) nxe_disconnect_streams(rdata->rb_req.data_in.pair, &rdata->rb_req.data_in);
  if (rdata->rb_req.data_out.pair) nxe_disconnect_streams(&rdata->rb_req.data_out, rdata->rb_req.data_out.pair);
  if (rdata->proxy_events_sub.pub) nxe_unsubscribe(rdata->proxy_events_sub.pub, &rdata->proxy_events_sub);
  if (rdata->hpx) {
    nxd_http_proxy_pool_return(rdata->hpx, rdata->proxy_request_error);
    rdata->hpx=0;
  }
  if (rdata->rbuf) {
    if (rdata->rbuf) nxp_free(conn->tdata->free_rbuf_pool, rdata->rbuf);
    rdata->rbuf=0;
  }
}