diff options
Diffstat (limited to 'src/testcurl/https/test_https_time_out.c')
-rw-r--r-- | src/testcurl/https/test_https_time_out.c | 75 |
1 files changed, 39 insertions, 36 deletions
diff --git a/src/testcurl/https/test_https_time_out.c b/src/testcurl/https/test_https_time_out.c index e46923eb..d2f4d92c 100644 --- a/src/testcurl/https/test_https_time_out.c +++ b/src/testcurl/https/test_https_time_out.c | |||
@@ -55,10 +55,10 @@ test_tls_session_time_out (gnutls_session_t session, int port) | |||
55 | 55 | ||
56 | sd = socket (AF_INET, SOCK_STREAM, 0); | 56 | sd = socket (AF_INET, SOCK_STREAM, 0); |
57 | if (sd == MHD_INVALID_SOCKET) | 57 | if (sd == MHD_INVALID_SOCKET) |
58 | { | 58 | { |
59 | fprintf (stderr, "Failed to create socket: %s\n", strerror (errno)); | 59 | fprintf (stderr, "Failed to create socket: %s\n", strerror (errno)); |
60 | return -1; | 60 | return -1; |
61 | } | 61 | } |
62 | 62 | ||
63 | memset (&sa, '\0', sizeof (struct sockaddr_in)); | 63 | memset (&sa, '\0', sizeof (struct sockaddr_in)); |
64 | sa.sin_family = AF_INET; | 64 | sa.sin_family = AF_INET; |
@@ -70,30 +70,30 @@ test_tls_session_time_out (gnutls_session_t session, int port) | |||
70 | ret = connect (sd, (struct sockaddr *) &sa, sizeof (struct sockaddr_in)); | 70 | ret = connect (sd, (struct sockaddr *) &sa, sizeof (struct sockaddr_in)); |
71 | 71 | ||
72 | if (ret < 0) | 72 | if (ret < 0) |
73 | { | 73 | { |
74 | fprintf (stderr, "Error: %s\n", MHD_E_FAILED_TO_CONNECT); | 74 | fprintf (stderr, "Error: %s\n", MHD_E_FAILED_TO_CONNECT); |
75 | MHD_socket_close_chk_ (sd); | 75 | MHD_socket_close_chk_ (sd); |
76 | return -1; | 76 | return -1; |
77 | } | 77 | } |
78 | 78 | ||
79 | ret = gnutls_handshake (session); | 79 | ret = gnutls_handshake (session); |
80 | if (ret < 0) | 80 | if (ret < 0) |
81 | { | 81 | { |
82 | fprintf (stderr, "Handshake failed\n"); | 82 | fprintf (stderr, "Handshake failed\n"); |
83 | MHD_socket_close_chk_ (sd); | 83 | MHD_socket_close_chk_ (sd); |
84 | return -1; | 84 | return -1; |
85 | } | 85 | } |
86 | 86 | ||
87 | (void)sleep (TIME_OUT + 1); | 87 | (void) sleep (TIME_OUT + 1); |
88 | 88 | ||
89 | /* check that server has closed the connection */ | 89 | /* check that server has closed the connection */ |
90 | /* TODO better RST trigger */ | 90 | /* TODO better RST trigger */ |
91 | if (send (sd, "", 1, 0) == 0) | 91 | if (send (sd, "", 1, 0) == 0) |
92 | { | 92 | { |
93 | fprintf (stderr, "Connection failed to time-out\n"); | 93 | fprintf (stderr, "Connection failed to time-out\n"); |
94 | MHD_socket_close_chk_ (sd); | 94 | MHD_socket_close_chk_ (sd); |
95 | return -1; | 95 | return -1; |
96 | } | 96 | } |
97 | 97 | ||
98 | MHD_socket_close_chk_ (sd); | 98 | MHD_socket_close_chk_ (sd); |
99 | return 0; | 99 | return 0; |
@@ -110,7 +110,7 @@ main (int argc, char *const *argv) | |||
110 | gnutls_datum_t cert; | 110 | gnutls_datum_t cert; |
111 | gnutls_certificate_credentials_t xcred; | 111 | gnutls_certificate_credentials_t xcred; |
112 | int port; | 112 | int port; |
113 | (void)argc; /* Unused. Silent compiler warning. */ | 113 | (void) argc; /* Unused. Silent compiler warning. */ |
114 | 114 | ||
115 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 115 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
116 | port = 0; | 116 | port = 0; |
@@ -126,8 +126,9 @@ main (int argc, char *const *argv) | |||
126 | gnutls_global_init (); | 126 | gnutls_global_init (); |
127 | gnutls_global_set_log_level (11); | 127 | gnutls_global_set_log_level (11); |
128 | 128 | ||
129 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | | 129 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
130 | MHD_USE_ERROR_LOG, port, | 130 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS |
131 | | MHD_USE_ERROR_LOG, port, | ||
131 | NULL, NULL, &http_dummy_ahc, NULL, | 132 | NULL, NULL, &http_dummy_ahc, NULL, |
132 | MHD_OPTION_CONNECTION_TIMEOUT, TIME_OUT, | 133 | MHD_OPTION_CONNECTION_TIMEOUT, TIME_OUT, |
133 | MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, | 134 | MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, |
@@ -135,24 +136,26 @@ main (int argc, char *const *argv) | |||
135 | MHD_OPTION_END); | 136 | MHD_OPTION_END); |
136 | 137 | ||
137 | if (NULL == d) | 138 | if (NULL == d) |
138 | { | 139 | { |
139 | fprintf (stderr, MHD_E_SERVER_INIT); | 140 | fprintf (stderr, MHD_E_SERVER_INIT); |
140 | return -1; | 141 | return -1; |
141 | } | 142 | } |
142 | if (0 == port) | 143 | if (0 == port) |
144 | { | ||
145 | const union MHD_DaemonInfo *dinfo; | ||
146 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
147 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
143 | { | 148 | { |
144 | const union MHD_DaemonInfo *dinfo; | 149 | MHD_stop_daemon (d); return -1; |
145 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
146 | if (NULL == dinfo || 0 == dinfo->port) | ||
147 | { MHD_stop_daemon (d); return -1; } | ||
148 | port = (int)dinfo->port; | ||
149 | } | 150 | } |
151 | port = (int) dinfo->port; | ||
152 | } | ||
150 | 153 | ||
151 | if (0 != setup_session (&session, &key, &cert, &xcred)) | 154 | if (0 != setup_session (&session, &key, &cert, &xcred)) |
152 | { | 155 | { |
153 | fprintf (stderr, "failed to setup session\n"); | 156 | fprintf (stderr, "failed to setup session\n"); |
154 | return 1; | 157 | return 1; |
155 | } | 158 | } |
156 | errorCount += test_tls_session_time_out (session, port); | 159 | errorCount += test_tls_session_time_out (session, port); |
157 | teardown_session (session, &key, &cert, xcred); | 160 | teardown_session (session, &key, &cert, xcred); |
158 | 161 | ||