Commit 441eaa7f authored by rojer's avatar rojer Committed by Sergey Lyubka

Handle errors better in listening code for CC3200

PUBLISHED_FROM=9d4ab680fa672690735b827f56e135330f72beed
parent 632153a1
...@@ -11208,9 +11208,7 @@ int mg_if_listen_tcp(struct mg_connection *nc, union socket_address *sa) { ...@@ -11208,9 +11208,7 @@ int mg_if_listen_tcp(struct mg_connection *nc, union socket_address *sa) {
int proto = 0; int proto = 0;
if (nc->flags & MG_F_SSL) proto = SL_SEC_SOCKET; if (nc->flags & MG_F_SSL) proto = SL_SEC_SOCKET;
sock_t sock = mg_open_listening_socket(sa, SOCK_STREAM, proto); sock_t sock = mg_open_listening_socket(sa, SOCK_STREAM, proto);
if (sock == INVALID_SOCKET) { if (sock < 0) return sock;
return (errno ? errno : 1);
}
mg_sock_set(nc, sock); mg_sock_set(nc, sock);
#ifdef MG_ENABLE_SSL #ifdef MG_ENABLE_SSL
return sl_set_ssl_opts(nc); return sl_set_ssl_opts(nc);
...@@ -11286,17 +11284,18 @@ static int mg_accept_conn(struct mg_connection *lc) { ...@@ -11286,17 +11284,18 @@ static int mg_accept_conn(struct mg_connection *lc) {
/* 'sa' must be an initialized address to bind to */ /* 'sa' must be an initialized address to bind to */
static sock_t mg_open_listening_socket(union socket_address *sa, int type, static sock_t mg_open_listening_socket(union socket_address *sa, int type,
int proto) { int proto) {
int r;
socklen_t sa_len = socklen_t sa_len =
(sa->sa.sa_family == AF_INET) ? sizeof(sa->sin) : sizeof(sa->sin6); (sa->sa.sa_family == AF_INET) ? sizeof(sa->sin) : sizeof(sa->sin6);
sock_t sock = sl_Socket(sa->sa.sa_family, type, proto); sock_t sock = sl_Socket(sa->sa.sa_family, type, proto);
if (sock < 0) return INVALID_SOCKET; if (sock < 0) return sock;
if (bind(sock, &sa->sa, sa_len) < 0) { if ((r = bind(sock, &sa->sa, sa_len)) < 0) {
sl_Close(sock); sl_Close(sock);
return INVALID_SOCKET; return r;
} }
if (type != SOCK_DGRAM && sl_Listen(sock, SOMAXCONN) < 0) { if (type != SOCK_DGRAM && (r = sl_Listen(sock, SOMAXCONN)) < 0) {
sl_Close(sock); sl_Close(sock);
return INVALID_SOCKET; return r;
} }
mg_set_non_blocking_mode(sock); mg_set_non_blocking_mode(sock);
return sock; return sock;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment