Initialize global state in the server examples
This commit is contained in:
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
http_global_init();
|
||||||
|
|
||||||
// Choose the interface to listen on and the port.
|
// Choose the interface to listen on and the port.
|
||||||
// Currently, servers can only bind to IPv4 addresses.
|
// Currently, servers can only bind to IPv4 addresses.
|
||||||
HTTP_String addr = HTTP_STR("127.0.0.1");
|
HTTP_String addr = HTTP_STR("127.0.0.1");
|
||||||
@@ -90,6 +92,7 @@ int main(void)
|
|||||||
// your server in a way to exit gracefully, this is
|
// your server in a way to exit gracefully, this is
|
||||||
// you the server object is freed:
|
// you the server object is freed:
|
||||||
http_server_free(server);
|
http_server_free(server);
|
||||||
|
http_global_free();
|
||||||
|
|
||||||
// Have fun. Bye!
|
// Have fun. Bye!
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
http_global_init();
|
||||||
|
|
||||||
// All the setup is identical to the previous example.
|
// All the setup is identical to the previous example.
|
||||||
// The only thing that changes where "http_response_body"
|
// The only thing that changes where "http_response_body"
|
||||||
// is called.
|
// is called.
|
||||||
@@ -90,5 +92,6 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
http_server_free(server);
|
http_server_free(server);
|
||||||
|
http_global_free();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
http_global_init();
|
||||||
|
|
||||||
HTTP_Server *server = http_server_init(HTTP_STR("127.0.0.1"), 8080);
|
HTTP_Server *server = http_server_init(HTTP_STR("127.0.0.1"), 8080);
|
||||||
if (server == NULL)
|
if (server == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
@@ -52,5 +54,6 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
http_server_free(server);
|
http_server_free(server);
|
||||||
|
http_global_free();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ ThreadReturn worker(void*)
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
http_global_free();
|
||||||
init_job_queue();
|
init_job_queue();
|
||||||
|
|
||||||
HTTP_Server *server = http_server_init(HTTP_STR("127.0.0.1"), 8080);
|
HTTP_Server *server = http_server_init(HTTP_STR("127.0.0.1"), 8080);
|
||||||
@@ -177,6 +178,7 @@ int main(void)
|
|||||||
|
|
||||||
http_server_free(server);
|
http_server_free(server);
|
||||||
free_job_queue();
|
free_job_queue();
|
||||||
|
http_global_free();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
http_global_init();
|
||||||
|
|
||||||
// To setup an HTTPS server, we need to use the *_ex variant
|
// To setup an HTTPS server, we need to use the *_ex variant
|
||||||
// of the server initialization function as it offers more
|
// of the server initialization function as it offers more
|
||||||
// control. Server objects can serve HTTP traffic, HTTPS
|
// control. Server objects can serve HTTP traffic, HTTPS
|
||||||
@@ -71,5 +73,6 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
http_server_free(server);
|
http_server_free(server);
|
||||||
|
http_global_free();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,8 @@ int setup_test_certificates(void);
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
http_global_init();
|
||||||
|
|
||||||
// First, create three certificates for the domains:
|
// First, create three certificates for the domains:
|
||||||
//
|
//
|
||||||
// websiteA.com
|
// websiteA.com
|
||||||
@@ -118,6 +120,7 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
http_server_free(server);
|
http_server_free(server);
|
||||||
|
http_global_free();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user