Skip to content

Commit 5d1d640

Browse files
committed
Catch connection error in http_load_test
1 parent b950efd commit 5d1d640

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

examples/http_load_test.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ struct us_socket_t *on_http_socket_timeout(struct us_socket_t *s) {
102102
return s;
103103
}
104104

105+
struct us_socket_t *on_http_socket_connect_error(struct us_socket_t *s, int code) {
106+
printf("Cannot connect to server\n");
107+
108+
return s;
109+
}
110+
105111
int main(int argc, char **argv) {
106112

107113
/* Parse host and port */
@@ -138,9 +144,12 @@ int main(int argc, char **argv) {
138144
us_socket_context_on_timeout(SSL, http_context, on_http_socket_timeout);
139145
us_socket_context_on_long_timeout(SSL, http_context, on_http_socket_long_timeout);
140146
us_socket_context_on_end(SSL, http_context, on_http_socket_end);
147+
us_socket_context_on_connect_error(SSL, http_context, on_http_socket_connect_error);
141148

142149
/* Start making HTTP connections */
143-
us_socket_context_connect(SSL, http_context, host, port, NULL, 0, sizeof(struct http_socket));
150+
if (!us_socket_context_connect(SSL, http_context, host, port, NULL, 0, sizeof(struct http_socket))) {
151+
printf("Cannot connect to server\n");
152+
}
144153

145154
us_loop_run(loop);
146155

0 commit comments

Comments
 (0)