예제 #1
0
파일: status.c 프로젝트: AmesianX/restund
static int module_init(void)
{
	struct sa laddr_udp, laddr_http;
	struct pl addr;
	uint32_t port;
	int err;

	/* UDP bind address */
	if (conf_get(restund_conf(), "status_udp_addr", &addr))
		pl_set_str(&addr, "127.0.0.1");

	if (conf_get_u32(restund_conf(), "status_udp_port", &port))
		port = 33000;

	err = sa_set(&laddr_udp, &addr, port);
	if (err) {
		restund_error("status: bad udp bind address: %r:%u",
			      &addr, port);
		goto out;
	}

	/* HTTP bind address */
	if (conf_get(restund_conf(), "status_http_addr", &addr))
		pl_set_str(&addr, "127.0.0.1");

	if (conf_get_u32(restund_conf(), "status_http_port", &port))
		port = 8080;

	err = sa_set(&laddr_http, &addr, port);
	if (err) {
		restund_error("status: bad http bind address: %r:%u",
			      &addr, port);
		goto out;
	}

	err = udp_listen(&stg.us, &laddr_udp, udp_recv, NULL);
	if (err) {
		restund_warning("status: udp_listen: %m\n", err);
		goto out;
	}

	err = httpd_alloc(&stg.httpd, &laddr_http, httpd_handler);
	if (err) {
		restund_warning("status: httpd: %m\n", err);
		goto out;
	}

	stg.start = time(NULL);

	restund_debug("status: module loaded (udp=%J http=%J)\n",
		      &laddr_udp, &laddr_http);

 out:
	if (err) {
		stg.us = mem_deref(stg.us);
		stg.httpd = mem_deref(stg.httpd);
	}

	return err;
}
예제 #2
0
int webserver_start(void)
{
	struct httpd * httpd;

	httpd = httpd_alloc();

	httpd_init(httpd, 80, 4, httpd_dir, NULL);

	return thinkos_thread_create_inf((void *)http_server_task,
			(void *)httpd, &httpd_inf);
}