mirror of
https://github.com/cesanta/mongoose.git
synced 2025-06-07 17:42:30 +08:00
Report errors in the netcat example
PUBLISHED_FROM=f43dc48512ff13028a57571b537c41d9658034b5
This commit is contained in:
parent
fecb11f2fa
commit
147c095105
@ -105,7 +105,7 @@ int main(int argc, char *argv[]) {
|
|||||||
int i, is_listening = 0;
|
int i, is_listening = 0;
|
||||||
const char *address = NULL;
|
const char *address = NULL;
|
||||||
struct mg_connection *c;
|
struct mg_connection *c;
|
||||||
// struct mg_bind_opts = {};
|
const char *err = NULL;
|
||||||
|
|
||||||
mg_mgr_init(&mgr, NULL);
|
mg_mgr_init(&mgr, NULL);
|
||||||
|
|
||||||
@ -133,14 +133,22 @@ int main(int argc, char *argv[]) {
|
|||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
|
||||||
if (is_listening) {
|
if (is_listening) {
|
||||||
if ((c = mg_bind(&mgr, address, ev_handler)) == NULL) {
|
struct mg_bind_opts opts;
|
||||||
fprintf(stderr, "mg_bind(%s) failed\n", address);
|
memset(&opts, 0, sizeof(opts));
|
||||||
|
opts.error_string = &err;
|
||||||
|
if ((c = mg_bind_opt(&mgr, address, ev_handler, opts)) == NULL) {
|
||||||
|
fprintf(stderr, "mg_bind(%s) failed: %s\n", address, err);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
} else if ((c = mg_connect(&mgr, address, ev_handler)) == NULL) {
|
} else {
|
||||||
fprintf(stderr, "mg_connect(%s) failed\n", address);
|
struct mg_connect_opts opts;
|
||||||
|
memset(&opts, 0, sizeof(opts));
|
||||||
|
opts.error_string = &err;
|
||||||
|
if ((c = mg_connect_opt(&mgr, address, ev_handler, opts)) == NULL) {
|
||||||
|
fprintf(stderr, "mg_connect(%s) failed: %s\n", address, err);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (s_is_websocket) {
|
if (s_is_websocket) {
|
||||||
mg_set_protocol_http_websocket(c);
|
mg_set_protocol_http_websocket(c);
|
||||||
if (!is_listening) {
|
if (!is_listening) {
|
||||||
|
Loading…
Reference in New Issue
Block a user