示例#1
0
    ws_server scheduler::get_ws_server(int port, std::function<void(int, char*, size_t)> f)
    {
        auto sch_impl = std::dynamic_pointer_cast<scheduler_impl>(m_impl);
        auto& impl = sch_impl->m_util_impls[WS_SVR];
        if (!impl) {
            auto http_svr_back = std::move(sch_impl->m_util_impls[HTTP_SVR]);
            std::function<void(int, const std::string&, const std::string&, std::map<std::string, std::string>&, char*, size_t)> http_stub;
            auto http_server = get_http_server(port, http_stub);
            auto http_impl = std::dynamic_pointer_cast<http_impl_t<tcp_server_impl>>(http_server.m_impl);
            http_impl->m_ws_cb = std::move(f);
            http_impl->m_util.m_f = [this](int fd, const std::string& ip_addr, uint16_t port, char *data, size_t len) {
                auto this_sch_impl = std::dynamic_pointer_cast<scheduler_impl>(m_impl);
                auto& this_ws_svr = this_sch_impl->m_util_impls[WS_SVR];
                auto this_ws_impl = std::dynamic_pointer_cast<http_impl_t<tcp_server_impl>>(this_ws_svr);
                tcp_callback_for_http<std::shared_ptr<http_impl_t<tcp_server_impl>>, tcp_server_conn>(
                        false, this_ws_impl, fd, data, len);
            };
            impl = std::move(http_server.m_impl);
            sch_impl->m_util_impls[HTTP_SVR] = std::move(http_svr_back);
        }

        ws_server obj;
        obj.m_impl = impl;
        return obj;
    }
static void
gss_server_set_http_port (GssServer * server, int port)
{
  if (port == 0) {
    GST_DEBUG_OBJECT (server, "trying port 80");
    server->server = get_http_server (80);
    port = 80;
    if (server->server == NULL) {
      GST_DEBUG_OBJECT (server, "trying port 8080");
      server->server = get_http_server (8080);
      port = 8080;
    }
  } else {
    GST_DEBUG_OBJECT (server, "trying port %d", port);
    server->server = get_http_server (port);
  }

  if (server->server == NULL) {
    return;
  }

  server->http_port = port;

  g_free (server->base_url);
  if (server->http_port == 80) {
    server->base_url = g_strdup_printf ("http://%s", server->server_hostname);
  } else {
    server->base_url = g_strdup_printf ("http://%s:%d", server->server_hostname,
        server->http_port);
  }



  if (server->server) {
    soup_server_add_handler (server->server, "/", gss_server_resource_callback,
        server, NULL);
    soup_server_run_async (server->server);
  }
}