예제 #1
0
파일: main.c 프로젝트: sanjay900/AdAway
/**
 * @brief Function for application main entry.
 */
int main(void)
{

  cs_log_set_file(stdout);

  bleconfig_init();

  {
    struct mg_mgr mgr;

    mg_mgr_init(&mgr, NULL);  // Initialize event manager object

    // Note that many connections can be added to a single event manager
    // Connections can be created at any point, e.g. in event handler function
    const char *err;
    struct mg_bind_opts opts;
    struct mg_connection *nc = NULL;
    memset(&opts, 0x00, sizeof(opts));
    opts.error_string = &err;
    nc = mg_bind_opt(&mgr, "80", ev_handler, opts);  // Create listening connection and add it to the event manager
    if (nc == NULL) {
      printf("Failed to create listener: %s\n", err);
      return 1;
    }
    mg_set_protocol_http_websocket(nc);

    for (;;) {  // Start infinite event loop
      bleconfig_poll();
      mg_mgr_poll(&mgr, 0);
    }
  }

}
예제 #2
0
파일: app.c 프로젝트: cesanta/mongoose
void APP_Initialize ( void )
{
    /* Place the App state machine in its initial state. */
    appData.state = APP_STATE_INIT;

    mg_mgr_init(&mgr, NULL);
}
예제 #3
0
int main(int argc, char *argv[]) {
  struct mg_mgr mgr;
  char *addr = argv[1];

  if (argc < 2) {
    fprintf(stderr, "Usage: %s <server_address>\n", argv[0]);
    exit(EXIT_FAILURE);
  }

  /* Start separate thread that generates MJPG data */
  mg_start_thread(generate_mjpg_data_thread_func, NULL);

  printf("Streaming [%s] to [%s]\n", s_mjpg_file, addr);

  mg_mgr_init(&mgr, NULL);

  for (;;) {
    mg_mgr_poll(&mgr, s_poll_interval_ms);

    /* Reconnect if disconnected */
    if (!client) {
      sleep(1); /* limit reconnections frequency */
      printf("Reconnecting to %s...\n", addr);
      client = mg_connect(&mgr, addr, ev_handler);
      if (client) mg_set_protocol_http_websocket(client);
    }
  }

  return EXIT_SUCCESS;
}
예제 #4
0
파일: server.cpp 프로젝트: e-sensing/tws
void tws::mongoose::server::start()
{
    pimpl_->stop_ = false;

    struct mg_mgr server_;
    struct mg_connection* conn_;

    tws_mongoose_http_config conf = tws_mongoose_read_config_file();

    mg_mgr_init(&server_, NULL);

    conn_ = mg_bind(&server_,
                    boost::lexical_cast<std::string>(conf.listening_port).c_str(),
                    tws_mongoose_event_handler);

    mg_set_protocol_http_websocket(conn_);

    if(conf.max_threads > 1)
        mg_enable_multithreading(conn_);
    \

    while(pimpl_->stop_ == false)
    {
        mg_mgr_poll(&server_, 1000);
    }
    mg_mgr_free(&server_);
}
예제 #5
0
int main(int argc, char *argv[])
{
	struct ev_loop *loop = EV_DEFAULT;
	ev_signal sig_watcher;
	struct mg_mgr mgr;

	ev_signal_init(&sig_watcher, signal_cb, SIGINT);
	ev_signal_start(loop, &sig_watcher);
	
	mg_mgr_init(&mgr, NULL, loop);

	/* Process command line arguments */
	if (argc != 2) {
		fprintf(stderr, "Usage: %s <domain>\n", argv[0]);
		exit(0);
	}

	mg_resolve_async(&mgr, argv[1], MG_DNS_A_RECORD, dns_resolve_cb, argv[1]);

	ev_run(loop, 0);

	printf("exit...\n");
	
	mg_mgr_free(&mgr);

	return 0;
}
bool ccMongooseWebServer::Start()
{
    if (_mgr != NULL)
        return false;

    _mgr = new struct mg_mgr;

    mg_mgr_init(_mgr, NULL);

    _mgr->user_data = this;
    _nc = mg_bind(_mgr, _strHttpPorts.c_str(), ev_handler);

    // Set up HTTP server parameters
    mg_set_protocol_http_websocket(_nc);

    s_http_server_opts.document_root = ".";  // Serve current directory
    s_http_server_opts.enable_directory_listing = "yes";

    printf("Starting web server on port %s\n", _strHttpPorts.c_str());

    _bIsStopThread = false;

    _pPollThread = new std::thread(std::bind(&ccMongooseWebServer::DoRunThread, this));

    return true;
}
예제 #7
0
int main(void) {
  struct mg_mgr mgr;
  struct mg_connection *nc;
  struct mg_bind_opts bind_opts;
  const char *err;

  mg_mgr_init(&mgr, NULL);
  memset(&bind_opts, 0, sizeof(bind_opts));
  bind_opts.ssl_cert = s_ssl_cert;
  bind_opts.ssl_key = s_ssl_key;
  bind_opts.error_string = &err;

  printf("Starting SSL server on port %s, cert from %s, key from %s\n",
         s_http_port, bind_opts.ssl_cert, bind_opts.ssl_key);
  nc = mg_bind_opt(&mgr, s_http_port, ev_handler, bind_opts);
  if (nc == NULL) {
    printf("Failed to create listener: %s\n", err);
    return 1;
  }

  // Set up HTTP server parameters
  mg_set_protocol_http_websocket(nc);
  s_http_server_opts.document_root = ".";  // Serve current directory
  s_http_server_opts.enable_directory_listing = "yes";

  for (;;) {
    mg_mgr_poll(&mgr, 1000);
  }
  mg_mgr_free(&mgr);

  return 0;
}
예제 #8
0
/**
 * @brief Run the web server listening at the given port.
 *
 * This function does not return.
 *
 * @param [in] port The port number of which to listen.
 * @return N/A.
 */
void WebServer::start(uint16_t port) {
	ESP_LOGD(tag, "WebServer task starting");
	struct mg_mgr mgr;
	mg_mgr_init(&mgr, NULL);

	std::stringstream stringStream;
	stringStream << ':' << port;
	struct mg_connection *mgConnection = mg_bind(&mgr, stringStream.str().c_str(), mongoose_event_handler_web_server);

	if (mgConnection == NULL) {
		ESP_LOGE(tag, "No connection from the mg_bind()");
		vTaskDelete(NULL);
		return;
	}

	struct WebServerUserData *pWebServerUserData = new WebServerUserData();
	pWebServerUserData->pWebServer = this;
	pWebServerUserData->pMultiPart = nullptr;
	mgConnection->user_data        = pWebServerUserData; // Save the WebServer instance reference in user_data.
	ESP_LOGD(tag, "start: User_data address 0x%d", (uint32_t)pWebServerUserData);
	mg_set_protocol_http_websocket(mgConnection);

	ESP_LOGD(tag, "WebServer listening on port %d", port);
	while (1) {
		mg_mgr_poll(&mgr, 2000);
	}
} // run
예제 #9
0
int main(void)
{
  struct mg_mgr mgr;
  struct mg_connection *nc;

  signal(SIGTERM, signal_handler);
  signal(SIGINT, signal_handler);
  setvbuf(stdout, NULL, _IOLBF, 0);
  setvbuf(stderr, NULL, _IOLBF, 0);

  load_source_data();
  mg_mgr_init(&mgr, NULL);

  nc = mg_bind(&mgr, s_http_port, ev_handler);
  s_http_server_opts.document_root = ".";
  s_http_server_opts.enable_directory_listing = "yes";
  mg_set_protocol_http_websocket(nc);

  printf("Started on port %s\n", s_http_port);
  while (s_signal_received == 0)
  {
    mg_mgr_poll(&mgr, 200);
  }

  mg_mgr_free(&mgr);
  save_source_data( s_source_path );

  return 0;
}
예제 #10
0
int main(void) {
  struct mg_mgr mgr;
  struct mg_connection *nc;

  signal(SIGTERM, signal_handler);
  signal(SIGINT, signal_handler);

  mg_mgr_init(&mgr, 0);

  nc = mg_bind(&mgr, s_default_address, coap_handler);
  if (nc == NULL) {
    printf("Unable to start listener at %s\n", s_default_address);
    return -1;
  }

  printf("Listening for CoAP messages at %s\n", s_default_address);

  mg_set_protocol_coap(nc);

  while (!s_sig_received) {
    mg_mgr_poll(&mgr, 1000000);
  }

  printf("Exiting on signal %d\n", s_sig_received);

  mg_mgr_free(&mgr);
  return 0;
}
예제 #11
0
int main(int argc, char *argv[]) {
  struct mg_mgr mgr;
  struct mg_connection *nc;
  char *address = s_default_address;

  if (argc > 1) {
    address = argv[1];
  }

  printf("Using %s as CoAP server\n", address);

  mg_mgr_init(&mgr, 0);

  nc = mg_connect(&mgr, address, coap_handler);
  if (nc == NULL) {
    printf("Unable to connect to %s\n", address);
    return -1;
  }

  mg_set_protocol_coap(nc);

  while (!s_time_to_exit) {
    mg_mgr_poll(&mgr, 1000000);
  }

  mg_mgr_free(&mgr);

  return 0;
}
예제 #12
0
int main(int argc, char *argv[]) {
  struct mg_mgr mgr;
  struct mg_connection *nc;

  if (argc != 2) {
    fprintf(stderr, "Usage: %s <listening_addr>\n", argv[0]);
    exit(EXIT_FAILURE);
  }

  printf("Listening on: [%s]\n", argv[1]);
  mg_mgr_init(&mgr, NULL);

  /*
   * mg_bind() creates a listening connection on a given ip:port and
   * with an attached event handler.
   * The event handler will only trigger TCP events until the http
   * protocol handler is installed.
   */
  if ((nc = mg_bind(&mgr, argv[1], ev_handler)) == NULL) {
    fprintf(stderr, "Error binding to %s\n", argv[1]);
    exit(EXIT_FAILURE);
  }
  mg_set_protocol_http_websocket(nc);
  web_root_opts.document_root = "./web_root";

  /*
   * We explicitly hand over control to the Mongoose manager
   * in this event loop and we can easily multiplex other activities.
   */
  for (;;) {
    mg_mgr_poll(&mgr, 1000);
  }

  return EXIT_SUCCESS;
}
예제 #13
0
int main(int argc, char **argv) {
  struct mg_mgr mgr;
  int i;

  mg_mgr_init(&mgr, NULL);

  /* Parse command line arguments */
  for (i = 1; i < argc; i++) {
    if (strcmp(argv[i], "-h") == 0) {
      s_address = argv[++i];
    } else if (strcmp(argv[i], "-u") == 0) {
      s_user_name = argv[++i];
    } else if (strcmp(argv[i], "-t") == 0) {
      s_topic = argv[++i];
    } else if (strcmp(argv[i], "-p") == 0) {
      s_password = argv[++i];
    }
  }

  if (mg_connect(&mgr, s_address, ev_handler) == NULL) {
    fprintf(stderr, "mg_connect(%s) failed\n", s_address);
    exit(EXIT_FAILURE);
  }

  for (;;) {
    mg_mgr_poll(&mgr, 1000);
  }
}
예제 #14
0
파일: http_client.cpp 프로젝트: ghilbut/ygg
TestHttpClient::TestHttpClient() 
  : stop_(false) {

  std::atomic_bool is_run(false);

  on_text_ = [](struct mg_connection*, const std::string & text) {};
  on_binary_ = [](struct mg_connection*, const std::vector<uint8_t> & bytes) {};
  on_closed_ = [](struct mg_connection*) {};

  mg_mgr_init(&mgr_, this);

  boost::mutex mutex;
  boost::condition_variable cond;

  boost::thread t([&]() {

      mutex.lock();
      is_run = true;
      cond.notify_one();
      mutex.unlock();

      while(!stop_) {
        mg_mgr_poll(&mgr_, 1000);
      }

      mg_mgr_free(&mgr_);
    });
  thread_.swap(t);

  while (!is_run) {
    const boost::chrono::seconds d(1);
    boost::mutex::scoped_lock lock(mutex);
    cond.wait_for(lock, d);
  }
}
예제 #15
0
int main(int argc, char *argv[]) {
  struct mg_mgr mgr;
  int i;

  mg_mgr_init(&mgr, NULL);

  /* Process command line arguments */
  for (i = 1; i < argc; i++) {
    if (strcmp(argv[i], s_show_headers_opt) == 0) {
      s_show_headers = 1;
    } else if (strcmp(argv[i], "--hexdump") == 0 && i + 1 < argc) {
      mgr.hexdump_file = argv[++i];
    } else {
      break;
    }
  }

  if (i + 1 != argc) {
    fprintf(stderr, "Usage: %s [%s] [--hexdump <file>] <URL>\n",
            argv[0], s_show_headers_opt);
    exit(EXIT_FAILURE);
  }

  mg_connect_http(&mgr, ev_handler, argv[i], NULL, NULL);

  while (s_exit_flag == 0) {
    mg_mgr_poll(&mgr, 1000);
  }
  mg_mgr_free(&mgr);

  return 0;
}
예제 #16
0
int main(void) {
  struct mg_mgr mgr;
  struct mg_connection *nc;

  mkfifo(DSP_FIFO_IN, S_IRUSR | S_IWUSR);
  if (NULL == (dsp_in = fopen(DSP_FIFO_IN, "w"))) {
    perror("[Server] fopen("DSP_FIFO_IN")");
    return 2;
  }

  mkfifo(DSP_FIFO_OUT, S_IRUSR | S_IWUSR);
  if (NULL == (dsp_out = fopen(DSP_FIFO_OUT, "r"))) {
    perror("[Server] fopen("DSP_FIFO_OUT")");
    return 2;
  }

  signal(SIGTERM, signal_handler);
  signal(SIGINT, signal_handler);

  mg_mgr_init(&mgr, NULL);

  nc = mg_bind(&mgr, s_http_port, ev_handler);
  s_http_server_opts.document_root = "htdocs";
  mg_set_protocol_http_websocket(nc);

  printf("[Server] Started on port %s\n", s_http_port);
  while (0 == s_signal_received) {
    mg_mgr_poll(&mgr, 200);
  }
  mg_mgr_free(&mgr);

  fclose(dsp_in);
  fclose(dsp_out);
  return 0;
}
예제 #17
0
파일: server.c 프로젝트: 2bright/mongoose
int main(void) {
  struct mg_mgr mgr;
  struct mg_connection *nc;
  cs_stat_t st;

  mg_mgr_init(&mgr, NULL);
  nc = mg_bind(&mgr, s_http_port, ev_handler);
  if (nc == NULL) {
    fprintf(stderr, "Cannot bind to %s\n", s_http_port);
    exit(1);
  }

  // Set up HTTP server parameters
  mg_set_protocol_http_websocket(nc);
  s_http_server_opts.document_root = "web_root";  // Set up web root directory

  if (mg_stat(s_http_server_opts.document_root, &st) != 0) {
    fprintf(stderr, "%s", "Cannot find web_root directory, exiting\n");
    exit(1);
  }

  printf("Starting web server on port %s\n", s_http_port);
  for (;;) {
    static time_t last_time;
    time_t now = time(NULL);
    mg_mgr_poll(&mgr, 1000);
    if (now - last_time > 0) {
      push_data_to_all_websocket_connections(&mgr);
      last_time = now;
    }
  }
  mg_mgr_free(&mgr);

  return 0;
}
예제 #18
0
int main(void) {
  struct mg_mgr mgr;
  struct mg_connection *nc1;
  struct mg_connection *nc2;
  const char *port1 = "127.0.0.1:80", *port2 = "[::1]:80";

  oom_adjust_setup();

  mg_mgr_init(&mgr, NULL);
  nc1 = mg_bind(&mgr, port1, ev_handler);
  nc2 = mg_bind(&mgr, port2, ev_handler);

  mg_set_protocol_http_websocket(nc1);
  mg_set_protocol_http_websocket(nc2);

  signal(SIGINT, signal_handler);
  signal(SIGTERM, signal_handler);

  __android_log_print(ANDROID_LOG_INFO, THIS_FILE, "AdAway Native Webserver: starting");
  while (s_sig_num == 0) {
    mg_mgr_poll(&mgr, 1000);
  }

  mg_mgr_free(&mgr);
  __android_log_print(ANDROID_LOG_INFO, THIS_FILE, "AdAway Native Webserver: exited on signal %d", s_sig_num);
  return EXIT_SUCCESS;
}
예제 #19
0
int main(int argc, char *argv[]) {
  struct mg_mgr mgr;
  struct mg_connection *nc;
  int i;

  mg_mgr_init(&mgr, NULL);
  s_our_ip_addr = inet_addr("127.0.0.1");

  /* Parse command line arguments */
  for (i = 1; i < argc; i++) {
    if (strcmp(argv[i], "-D") == 0) {
      mgr.hexdump_file = argv[++i];
    } else if (strcmp(argv[i], "-l") == 0 && i + 1 < argc) {
      s_listening_addr = argv[++i];
    } else {
      s_our_ip_addr = inet_addr(argv[i]);
    }
  }

  fprintf(stderr, "Listening on '%s'\n", s_listening_addr);
  if ((nc = mg_bind(&mgr, s_listening_addr, ev_handler)) == NULL) {
    fprintf(stderr, "cannot bind to socket\n");
    exit(1);
  }
  mg_set_protocol_dns(nc);

  while (s_exit_flag == 0) {
    mg_mgr_poll(&mgr, 1000);
  }
  mg_mgr_free(&mgr);

  return 0;
}
예제 #20
0
wxThread::ExitCode SendStatsThread::Entry()
{
	std::cout << m_url << std::endl;

	struct mg_mgr mgr;
	struct mg_connection *nc;

	mg_mgr_init(&mgr, this);

	std::string user_agent = "User-Agent: " + wxGetOsDescription().ToStdString() + "\r\n";
	std::cout << user_agent << std::endl;
	nc = mg_connect_http(&mgr, SendStatsThread::ev_handler, m_url.c_str(), user_agent.c_str(), NULL); // GET

    if (nc != nullptr)
    {
	    mg_set_protocol_http_websocket(nc);

	    time_t ts_start = time(NULL);
	    time_t ts_end = ts_start;
	    this->m_end = false;

	    while (!this->m_end)
	    {
		    if ((ts_end - ts_start) >= 1) // 1 sec
		    {
			    std::cout << "timeout" << std::endl;
			    break;
		    }
		    ts_end = mg_mgr_poll(&mgr, 1000);
	    }
    }
	mg_mgr_free(&mgr);

	return nullptr;
}
예제 #21
0
void *VSCPMQTTBrokerThread::Entry()
{
    struct mg_mgr mgr;
    struct mg_connection *nc;
    struct mg_mqtt_broker brk;
    const char *address = "0.0.0.0:1883";

    // Check pointers
    if ( NULL == m_pCtrlObject ) return NULL;

    // We need to create a clientobject and add this object to the list
    m_pClientItem = new CClientItem;
    if ( NULL == m_pClientItem ) {
        m_pCtrlObject->logMsg( _( "[VSCP MQTT Broker] Unable to allocate memory for client.\n" )  );
        return NULL;
    }

    // This is now an active Client
    m_pClientItem->m_bOpen = true;
    m_pClientItem->m_type =  CLIENT_ITEM_INTERFACE_TYPE_CLIENT_UDP;
    m_pClientItem->m_strDeviceName = _("VSCP MQTT Broker: Started at ");
    wxDateTime now = wxDateTime::Now();
    m_pClientItem->m_strDeviceName += now.FormatISODate();
    m_pClientItem->m_strDeviceName += _(" ");
    m_pClientItem->m_strDeviceName += now.FormatISOTime();

    // Add the client to the Client List
    m_pCtrlObject->m_wxClientMutex.Lock();
    m_pCtrlObject->addClient( m_pClientItem );
    m_pCtrlObject->m_wxClientMutex.Unlock();

    // Clear the filter (Allow everything )
    vscp_clearVSCPFilter( &m_pClientItem->m_filterVSCP );
    mg_mgr_init( &mgr, this );
    mg_mqtt_broker_init( &brk, NULL );

    if ( ( nc = mg_bind( &mgr,
                            m_pCtrlObject->m_strMQTTBrokerInterfaceAddress.mbc_str(),
                            mg_mqtt_broker ) ) == NULL) {
        m_pCtrlObject->logMsg( _("VSCP MQTT Broker: Faild to bind to requested address.\n")  );
        return NULL;
    }

    nc->user_data = &brk;

    m_pCtrlObject->logMsg( _("VSCP MQTT Broker: Thread started.\n")  );

    while ( !TestDestroy() && !m_bQuit ) {
        mg_mgr_poll( &mgr, 1000 );
    }

    // release the server
    //ns_mgr_free( &m_pCtrlObject->m_mgrTcpIpServer );
    mg_mgr_free( &mgr );

    m_pCtrlObject->logMsg( _( "VSCP MQTT Broker: Quit.\n" )  );

    return NULL;
}
예제 #22
0
Server::Server() {
	/**Creo el server**/
	this->configuration=Configuration::getConfiguration();
	mg_mgr_init(&mgr, NULL);  //Inicializo el Mongoose manager
	string http_port=this->configuration->getStringAttribute("http_port");
	nc = mg_bind(&mgr, http_port.c_str(), Server::staticEvHandler); //Creo la conexion que escucha.
	mg_set_protocol_http_websocket(nc); //Conecta al event handler de http con la conexion.
}
예제 #23
0
int main(int argc, char* argv[])
{
    if (VIPS_INIT(argv[0])) {
        vips_error_exit("Unable to start VIPS");
    }

    int ret = 0;

    // Initialize and open database
    ret = init_dbfile(argc, argv[1]);

    if (ret == 0) {
        print_header(&db_file->header);

        // Initialize signal handler and kill previous one
        signal(SIGTERM, signal_handler);
        signal(SIGINT, signal_handler);

        struct mg_mgr mgr;
        struct mg_connection* nc;

        // Create listening connection
        mg_mgr_init(&mgr, NULL);
        nc = mg_bind(&mgr, s_http_port, db_event_handler);

        if (nc != NULL) {
            // Set up HTTP server parameters
            mg_set_protocol_http_websocket(nc);
            s_http_server_opts.document_root = "."; // Serve current directory
            s_http_server_opts.enable_directory_listing = "yes";

            // Listening loop
            printf("Starting web server on port %s,\nserving %s\n", s_http_port,
                   s_http_server_opts.document_root);
            while (!s_sig_received) {
                mg_mgr_poll(&mgr, 1000);
            }
            printf("Exiting on signal %d\n", s_sig_received);
        } else {
            fprintf(stderr, "Unable to create web server on port %s\n", s_http_port);
        }

        mg_mgr_free(&mgr);
    }

    // Close database and free the pointer
    do_close(db_file);
    free(db_file);

    // Print error message if there was an error
    if (ret) {
        fprintf(stderr, "ERROR: %s\n", ERROR_MESSAGES[ret]);
    }

    vips_shutdown();

    return ret;
}
예제 #24
0
	int init_server(struct mg_mgr& mgr, struct mg_connection*& nc, struct mg_serve_http_opts& s_http_server_opts)
	{		
		/* Open listening socket */
		mg_mgr_init(&mgr, NULL);
		nc = mg_bind(&mgr, s_http_port, ev_handler);
		mg_set_protocol_http_websocket(nc); //not sure if it needed
		s_http_server_opts.document_root = "web/web_root";
		
		return 0;
	}
예제 #25
0
파일: basic_http.cpp 프로젝트: leoxk/lsf
bool BasicHttp::Start(){
    mg_mgr_init(&_mgr, NULL);
    auto nc = mg_bind(&_mgr, _port, EvHandler);

    if(nullptr == nc)
        return false;

    mg_set_protocol_http_websocket(nc);
    return true;
}
예제 #26
0
int main(int argc, char *argv[]) {
  struct mg_mgr mgr;

  if (argc != 3) {
    fprintf(stderr, "Usage: %s <port> <client|server>\n", argv[0]);
    exit(EXIT_FAILURE);
  } else if (strcmp(argv[2], "client") == 0) {
    sock_t fds[2];
    struct mg_connection *ioconn, *server_conn;

    mg_mgr_init(&mgr, NULL);

    // Connect to the pubsub server
    server_conn = mg_connect(&mgr, argv[1], client_handler);
    if (server_conn == NULL) {
      fprintf(stderr, "Cannot connect to port %s\n", argv[1]);
      exit(EXIT_FAILURE);
    }
    server_conn->flags |= MG_F_USER_2;  // Mark this as a client connection

    // Create a socketpair and give one end to the thread that reads stdin
    mg_socketpair(fds, SOCK_STREAM);
    mg_start_thread(stdin_thread, &fds[1]);

    // The other end of a pair goes inside the server
    ioconn = mg_add_sock(&mgr, fds[0], client_handler);
    ioconn->flags |= MG_F_USER_1;  // Mark this so we know this is a stdin
    ioconn->user_data = server_conn;

  } else {
    // Server code path
    mg_mgr_init(&mgr, NULL);
    mg_bind(&mgr, argv[1], server_handler);
    printf("Starting pubsub server on port %s\n", argv[1]);
  }

  for (;;) {
    mg_mgr_poll(&mgr, 1000);
  }
  mg_mgr_free(&mgr);

  return EXIT_SUCCESS;
}
예제 #27
0
void do_stuff() {
#if !defined(ESP_ENABLE_HW_WATCHDOG) && !defined(RTOS_TODO)
  ets_wdt_disable();
#endif
  pp_soft_wdt_stop();

  last_ts = system_get_time();

  wifi_set_event_handler_cb(x_wifi_changed_cb);
  sj_wifi_setup_sta("TehCloud", "");

  mg_mgr_init(&s_mgr, NULL);
}
예제 #28
0
void server::warmup() {
    for (int i = 0; i < 4; ++i) {
        struct mg_mgr* mgMgr = new mg_mgr;
        vectorMgr.push_back(mgMgr);
        mg_mgr_init(mgMgr, this);
        mg_bind(mgMgr, s_http_port, ev_handler);
    }
    for(mg_mgr*mgMgr: vectorMgr){ mg_start_thread(run,mgMgr); }
    while(true){
        sleep(1);
    }
    std::cout<< "this is a test" << std::endl;
}
예제 #29
0
JNIEXPORT void JNICALL Java_com_zcwfeng_fastdev_ndk_NdkJniUtils_openServer(void) {


    // TODO
    struct mg_mgr mgr;
    struct mg_connection *nc;





    /* Open listening socket */
    mg_mgr_init(&mgr, NULL);
    nc = mg_bind(&mgr, s_http_port, ev_handler);
    mg_set_protocol_http_websocket(nc);
//    s_http_server_opts.document_root = "web_root";

    /* Parse command line arguments */
//    for (i = 1; i < argc; i++) {
//        if (strcmp(argv[i], "-D") == 0) {
//            mgr.hexdump_file = argv[++i];
//        } else if (strcmp(argv[i], "-f") == 0) {
//            s_db_path = argv[++i];
//        } else if (strcmp(argv[i], "-r") == 0) {
//            s_http_server_opts.document_root = argv[++i];
//        }
//    }

    signal(SIGINT, signal_handler);
    signal(SIGTERM, signal_handler);

    /* Open database */
    if ((s_db_handle = db_open(s_db_path)) == NULL) {
        fprintf(stderr, "Cannot open DB [%s]\n", s_db_path);
        exit(EXIT_FAILURE);
    }

    /* Run event loop until signal is received */
    printf("Starting RESTful server on port %s\n", s_http_port);
    while (s_sig_num == 0) {
        mg_mgr_poll(&mgr, 1000);
    }

    /* Cleanup */
    mg_mgr_free(&mgr);
    db_close(&s_db_handle);

    printf("Exiting on signal %d\n", s_sig_num);

}
예제 #30
0
/**	WebServer constructor
 *	Wraps the mongoose server
 *	Protects the resources using the RAII pattern.
 *
 *	\param port Is the port of listener socket, as string.
 */
WebServer::WebServer(const std::string &port) : httpPort(port),
		suggestionsGenerator(users),
		requestManager(users, suggestionsGenerator) {
	keepAlive = true;
	mg_mgr_init(&eventManager, NULL);
	networkConnection = mg_bind(&eventManager, httpPort.c_str(), eventHandler);
	networkConnection->user_data = this;

	serverOptions.document_root = ".";
	serverOptions.dav_document_root = ".";
	serverOptions.enable_directory_listing = "yes";
	mg_set_protocol_http_websocket(networkConnection);
	Log::instance()->append("Starting web server on port " + httpPort, Log::INFO);
}