Пример #1
0
static msg_t httpd_loop(void *data)
{
	struct netconn *nc, *ncnew;
	int ret;

        chRegSetThreadName("net/httpd");

	nc = netconn_new(NETCONN_TCP);
	if (!nc)
		return 1;

	netconn_bind(nc, NULL, HTTPD_PORT);
	netconn_listen(nc);

	for (;;) {
		ret = netconn_accept(nc, &ncnew);
		if (ret)
			continue;

		httpd_process(ncnew);

		netconn_delete(ncnew);
	}

	return 0;
}
Пример #2
0
int main (int argc, const char * argv[])
{
#ifdef WIN32
  WSADATA data;
  WSAStartup(MAKEWORD(2,2),&data);
#endif

  printf("server runs on http://localhost:8080/\n(default port 80 requires admin rights)\n");
  
  Httpd* srv = httpd_create(8080, http_handler, 0);
  if (srv)
  {
    while (1)
    {
      // httpd_process can be used in polling or waiting mode
      httpd_process(srv, true);
    }
    httpd_destroy(srv);
  }

  return 0;
}