diff options
Diffstat (limited to 'src/testcurl/test_termination.c')
-rw-r--r-- | src/testcurl/test_termination.c | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/src/testcurl/test_termination.c b/src/testcurl/test_termination.c index 5be74303..cd99e0af 100644 --- a/src/testcurl/test_termination.c +++ b/src/testcurl/test_termination.c | |||
@@ -53,29 +53,29 @@ connection_handler (void *cls, | |||
53 | const char *url, | 53 | const char *url, |
54 | const char *method, | 54 | const char *method, |
55 | const char *version, | 55 | const char *version, |
56 | const char *upload_data, size_t * upload_data_size, | 56 | const char *upload_data, size_t *upload_data_size, |
57 | void **ptr) | 57 | void **ptr) |
58 | { | 58 | { |
59 | static int i; | 59 | static int i; |
60 | (void)cls;(void)url; /* Unused. Silent compiler warning. */ | 60 | (void) cls; (void) url; /* Unused. Silent compiler warning. */ |
61 | (void)method;(void)version;(void)upload_data; /* Unused. Silent compiler warning. */ | 61 | (void) method; (void) version; (void) upload_data; /* Unused. Silent compiler warning. */ |
62 | (void)upload_data_size; /* Unused. Silent compiler warning. */ | 62 | (void) upload_data_size; /* Unused. Silent compiler warning. */ |
63 | 63 | ||
64 | if (*ptr == NULL) | 64 | if (*ptr == NULL) |
65 | { | 65 | { |
66 | *ptr = &i; | 66 | *ptr = &i; |
67 | return MHD_YES; | 67 | return MHD_YES; |
68 | } | 68 | } |
69 | 69 | ||
70 | if (*upload_data_size != 0) | 70 | if (*upload_data_size != 0) |
71 | { | 71 | { |
72 | (*upload_data_size) = 0; | 72 | (*upload_data_size) = 0; |
73 | return MHD_YES; | 73 | return MHD_YES; |
74 | } | 74 | } |
75 | 75 | ||
76 | struct MHD_Response *response = | 76 | struct MHD_Response *response = |
77 | MHD_create_response_from_buffer (strlen ("Response"), "Response", | 77 | MHD_create_response_from_buffer (strlen ("Response"), "Response", |
78 | MHD_RESPMEM_PERSISTENT); | 78 | MHD_RESPMEM_PERSISTENT); |
79 | int ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 79 | int ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
80 | MHD_destroy_response (response); | 80 | MHD_destroy_response (response); |
81 | 81 | ||
@@ -85,7 +85,7 @@ connection_handler (void *cls, | |||
85 | static size_t | 85 | static size_t |
86 | write_data (void *ptr, size_t size, size_t nmemb, void *stream) | 86 | write_data (void *ptr, size_t size, size_t nmemb, void *stream) |
87 | { | 87 | { |
88 | (void)ptr;(void)stream; /* Unused. Silent compiler warning. */ | 88 | (void) ptr; (void) stream; /* Unused. Silent compiler warning. */ |
89 | return size * nmemb; | 89 | return size * nmemb; |
90 | } | 90 | } |
91 | 91 | ||
@@ -103,24 +103,28 @@ main (void) | |||
103 | port = 1490; | 103 | port = 1490; |
104 | 104 | ||
105 | 105 | ||
106 | daemon = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 106 | daemon = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
107 | | MHD_USE_INTERNAL_POLLING_THREAD | ||
108 | | MHD_USE_ERROR_LOG, | ||
107 | port, | 109 | port, |
108 | NULL, | 110 | NULL, |
109 | NULL, connection_handler, NULL, MHD_OPTION_END); | 111 | NULL, connection_handler, NULL, MHD_OPTION_END); |
110 | 112 | ||
111 | if (daemon == NULL) | 113 | if (daemon == NULL) |
112 | { | 114 | { |
113 | fprintf (stderr, "Daemon cannot be started!"); | 115 | fprintf (stderr, "Daemon cannot be started!"); |
114 | exit (1); | 116 | exit (1); |
115 | } | 117 | } |
116 | if (0 == port) | 118 | if (0 == port) |
119 | { | ||
120 | const union MHD_DaemonInfo *dinfo; | ||
121 | dinfo = MHD_get_daemon_info (daemon, MHD_DAEMON_INFO_BIND_PORT); | ||
122 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
117 | { | 123 | { |
118 | const union MHD_DaemonInfo *dinfo; | 124 | MHD_stop_daemon (daemon); return 32; |
119 | dinfo = MHD_get_daemon_info (daemon, MHD_DAEMON_INFO_BIND_PORT); | ||
120 | if (NULL == dinfo || 0 == dinfo->port) | ||
121 | { MHD_stop_daemon (daemon); return 32; } | ||
122 | port = (int)dinfo->port; | ||
123 | } | 125 | } |
126 | port = (int) dinfo->port; | ||
127 | } | ||
124 | 128 | ||
125 | curl = curl_easy_init (); | 129 | curl = curl_easy_init (); |
126 | /* curl_easy_setopt(curl, CURLOPT_POST, 1L); */ | 130 | /* curl_easy_setopt(curl, CURLOPT_POST, 1L); */ |
@@ -133,12 +137,12 @@ main (void) | |||
133 | 137 | ||
134 | CURLcode success = curl_easy_perform (curl); | 138 | CURLcode success = curl_easy_perform (curl); |
135 | if (success != 0) | 139 | if (success != 0) |
136 | { | 140 | { |
137 | fprintf (stderr, "CURL Error"); | 141 | fprintf (stderr, "CURL Error"); |
138 | exit (1); | 142 | exit (1); |
139 | } | 143 | } |
140 | /* CPU used to go crazy here */ | 144 | /* CPU used to go crazy here */ |
141 | (void)sleep (1); | 145 | (void) sleep (1); |
142 | 146 | ||
143 | curl_easy_cleanup (curl); | 147 | curl_easy_cleanup (curl); |
144 | MHD_stop_daemon (daemon); | 148 | MHD_stop_daemon (daemon); |