nx_tcp_server_socket_accept error

Michael Fowler 131 Reputation points
2022-08-29T22:38:19.727+00:00

Hello,
I added the following listen callback function:

 void adc_connect_request_cb(NX_TCP_SOCKET *socket_ptr, UINT port) {  
    	// Wait for 200 ticks for the client socket connection to complete.  
    	UINT status = nx_tcp_server_socket_accept(socket_ptr, 400);  
    	if (status != NX_SUCCESS) {  
    		// Unaccept the server socket. Note that unaccept is called even if disconnect or accept fails  
    		nx_tcp_server_socket_unaccept(socket_ptr);  
    		return;  
    	}  
    	PRINTF("Connected!\r\n");  
    	// Simply set the semaphore to wake up the server thread.  
    	assert (TX_SUCCESS == tx_semaphore_ceiling_put(&adcConnectRequest, 1));		//TODO switch to event flags  
    }  

nx_tcp_server_socket_accept always returns NX_IN_PROGRESS (0x37) No wait was specified, the connection attempt is in progress.
Before I made the call back function that same line of code returned 0 when it followed

nx_tcp_server_socket_listen(&ip_0, ADC_PORT, &tcp_server_socket, 1,  
			adc_connect_request_cb);  

Can nx_tcp_server_socket_accept not be called from a callback?

Azure RTOS
Azure RTOS
An Azure embedded development suite including a small but powerful operating system for resource-constrained devices.
323 questions
{count} votes

Accepted answer
  1. Tiejun Zhou 1,126 Reputation points Microsoft Employee
    2022-08-31T06:50:16.813+00:00

    Since the listen callback is in the IP thread context, user application cannot block it, or else no subsequent packets can be processed. Thus, a blocking call from NetX TCP APIs will not block the IP thread even the wait option is none zero. But you can still call the nx_tcp_server_socket_accept() in listen callback to start accepting an incoming connection. It is IP thread's responsibility to complete the packet exchange to establish a connection. You can setup a callback function by nx_tcp_socket_establish_notify or call nx_tcp_socket_state_wait to check whether the connection is established or not.

    2 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful