@@ -142,6 +142,8 @@ bool mg_send(struct mg_connection *c, const void *buf, size_t len) {
142142 return n > 0 ;
143143 } else {
144144 return mg_iobuf_add (& c -> send , c -> send .len , buf , len );
145+ // returning 0 means an OOM condition (iobuf couldn't resize), yet this is
146+ // so far recoverable, let the caller decide
145147 }
146148}
147149
@@ -163,7 +165,7 @@ static void mg_set_non_blocking_mode(MG_SOCKET_TYPE fd) {
163165#elif MG_ARCH == MG_ARCH_THREADX
164166 // NetxDuo fails to send large blocks of data to the non-blocking sockets
165167 (void ) fd ;
166- //fcntl(fd, F_SETFL, O_NONBLOCK);
168+ // fcntl(fd, F_SETFL, O_NONBLOCK);
167169#elif MG_ARCH == MG_ARCH_TIRTOS
168170 int val = 0 ;
169171 setsockopt (fd , SOL_SOCKET , SO_BLOCKING , & val , sizeof (val ));
@@ -195,9 +197,10 @@ void mg_multicast_add(struct mg_connection *c, char *ip) {
195197 struct ip_mreq mreq ;
196198 mreq .imr_multiaddr .s_addr = inet_addr (ip );
197199 mreq .imr_interface .s_addr = mg_htonl (INADDR_ANY );
198- setsockopt (FD (c ), IPPROTO_IP , IP_ADD_MEMBERSHIP , (char * ) & mreq , sizeof (mreq ));
199- #endif // !Zephyr
200- #endif // !lwIP
200+ setsockopt (FD (c ), IPPROTO_IP , IP_ADD_MEMBERSHIP , (char * ) & mreq ,
201+ sizeof (mreq ));
202+ #endif // !Zephyr
203+ #endif // !lwIP
201204#endif
202205}
203206
@@ -315,9 +318,9 @@ static void read_conn(struct mg_connection *c) {
315318 if (n == MG_IO_ERR || n == MG_IO_RESET ) { // Windows, see #3031
316319 if (c -> rtls .len == 0 || m < 0 ) {
317320 // Close only when we have fully drained both rtls and TLS buffers
318- c -> is_closing = 1 ; // or there's nothing we can do about it.
319- if (m < 0 ) m = MG_IO_ERR ; // but return last record data, see #3104
320- } else { // see #2885
321+ c -> is_closing = 1 ; // or there's nothing we can do about it.
322+ if (m < 0 ) m = MG_IO_ERR ; // but return last record data, see #3104
323+ } else { // see #2885
321324 // TLS buffer is capped to max record size, even though, there can
322325 // be more than one record, give TLS a chance to process them.
323326 }
@@ -367,7 +370,7 @@ static void connect_conn(struct mg_connection *c) {
367370 mg_call (c , MG_EV_CONNECT , NULL );
368371 MG_EPOLL_MOD (c , 0 );
369372 if (c -> is_tls_hs ) mg_tls_handshake (c );
370- if (!c -> is_tls_hs ) c -> is_tls = 0 ; // user did not call mg_tls_init()
373+ if (!c -> is_tls_hs ) c -> is_tls = 0 ; // user did not call mg_tls_init()
371374 } else {
372375 mg_error (c , "socket error" );
373376 }
@@ -419,9 +422,9 @@ void mg_connect_resolved(struct mg_connection *c) {
419422 rc = connect (FD (c ), & usa .sa , slen ); // Attempt to connect
420423 if (rc == 0 ) { // Success
421424 setlocaddr (FD (c ), & c -> loc );
422- mg_call (c , MG_EV_CONNECT , NULL ); // Send MG_EV_CONNECT to the user
423- if (!c -> is_tls_hs ) c -> is_tls = 0 ; // user did not call mg_tls_init()
424- } else if (MG_SOCK_PENDING (rc )) { // Need to wait for TCP handshake
425+ mg_call (c , MG_EV_CONNECT , NULL ); // Send MG_EV_CONNECT to the user
426+ if (!c -> is_tls_hs ) c -> is_tls = 0 ; // user did not call mg_tls_init()
427+ } else if (MG_SOCK_PENDING (rc )) { // Need to wait for TCP handshake
425428 MG_DEBUG (("%lu %ld -> %M pend" , c -> id , c -> fd , mg_print_ip_port , & c -> rem ));
426429 c -> is_connecting = 1 ;
427430 } else {
@@ -481,7 +484,7 @@ static void accept_conn(struct mg_mgr *mgr, struct mg_connection *lsn) {
481484 & c -> rem , mg_print_ip_port , & c -> loc ));
482485 mg_call (c , MG_EV_OPEN , NULL );
483486 mg_call (c , MG_EV_ACCEPT , NULL );
484- if (!c -> is_tls_hs ) c -> is_tls = 0 ; // user did not call mg_tls_init()
487+ if (!c -> is_tls_hs ) c -> is_tls = 0 ; // user did not call mg_tls_init()
485488 }
486489}
487490
0 commit comments