@@ -61,8 +61,8 @@ int connectedWritableSockets_len = 0;
6161int * connectedWritableSockets = NULL ;
6262int selectClientSocket = -1 ;
6363int selectServerSocket = -1 ;
64- SemaphoreHandle_t xSemaphore ;
65- bool needsUnblock = false;
64+ volatile SemaphoreHandle_t xSemaphore ;
65+ volatile bool needsUnblock = false;
6666struct sockaddr_in target ;
6767
6868extern const uint8_t cacert_pem_start [] asm("_binary_cacert_pem_start" );
@@ -313,7 +313,14 @@ void select_task_it()
313313 }
314314 else
315315 {
316- jslog (ERROR , "select returns ERROR: %d" , errno );
316+ if (errno == 9 )
317+ {
318+ jslog (DEBUG , "select returns EBADF: Most likely due to socket read timeout during select." );
319+ }
320+ else
321+ {
322+ jslog (ERROR , "select returns ERROR: %d" , errno );
323+ }
317324 }
318325 }
319326 //wait for next loop
@@ -330,7 +337,6 @@ static void triggerNextSelectIteration()
330337 {
331338 //interrupt select through self-socket
332339 jslog (DEBUG , "Sending . to self-socket." );
333- needsUnblock = true;
334340 if (sendto (selectClientSocket , "." , 1 , 0 , (struct sockaddr * )& target , sizeof (target )) < 0 )
335341 {
336342 jslog (ERROR , "Self-socket sending was NOT successful: %d" , errno );
@@ -608,10 +614,6 @@ static duk_ret_t el_closeSocket(duk_context *ctx)
608614{
609615 int socketfd = duk_to_int (ctx , 0 );
610616
611- // prevent bad file descripter error on running select, caused
612- // by closing socket
613- triggerNextSelectIteration ();
614-
615617 closeSocket (socketfd );
616618 return 0 ;
617619}
0 commit comments