Socket programming: send() function blocked
Hello, I am using the MQTT-C library (https://github.com/LiamBindle/MQTT-C) in my NuttX project and I am facing a quite interesting issue with a specific server. For a specific broker, which is a commercial one, after the connection is established, when the MQTT Connect message is sent, the firmware gets stuck. Debugging the code, I can see that the send() function is blocked. When I set the socket, I setup to work in non-blocking mode: === /* * Opening socket */ int sockfd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, IPPROTO_IP); if (sockfd == -1) { syslog(LOG_ERR, "MqttClient: error socket() %d (%s)\n",errno,strerror(errno)); return -1; } struct timeval tv; tv.tv_sec = 3; tv.tv_usec = 0; setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (FAR const void *)&tv, sizeof(struct timeval)); setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, (FAR const void *)&tv, sizeof(struct timeval)); /* * Connecting */ int rv = connect(sockfd, server_address, server_address_len); syslog(LOG_DEBUG,"connect() = %d\n",rv); if(rv == -1) { syslog(LOG_ERR, "MqttClient: error connect() %d (%s)\n",errno,strerror(errno)); close(sockfd); sockfd = -1; return -1; } /* * make non-blocking */ if (sockfd != -1) { fcntl(sockfd, F_SETFL, fcntl(sockfd, F_GETFL) | O_NONBLOCK); } === I couldn't find the reason why the send() function gets stuck. And, worst, it happens when I try to communicate with a specific broker. Can anyone give me advice about why it is happening and what I am doing wrong? Best regards, Flavio -- Flavio de Castro Alves Filho flavio.al...@gmail.com Twitter: http://twitter.com/#!/fraviofii LinkedIn profile: www.linkedin.com/in/flaviocastroalves
Re: Socket programming: send() function blocked
Do you have CONFIG_NET_TCP_WRITE_BUFFERS=y selected? It is required for TCP non-blocking send.
Re: Socket programming: send() function blocked
Hello Greg, No. It was not set :-( I turned on the configuration, but the problem persisted. :-( Best regards, Flavio Em sáb., 26 de jun. de 2021 às 10:41, Gregory Nutt escreveu: > > Do you have CONFIG_NET_TCP_WRITE_BUFFERS=y selected? It is required for > TCP non-blocking send. > -- Flavio de Castro Alves Filho flavio.al...@gmail.com Twitter: http://twitter.com/#!/fraviofii LinkedIn profile: www.linkedin.com/in/flaviocastroalves
Re: Socket programming: send() function blocked
Is there any chance that the broker didn't like the mqtt connect message and shutdown the connection and leaving my device alone ... all during send call? Em sáb., 26 de jun. de 2021 às 11:42, Flavio Castro Alves Filho escreveu: > > Hello Greg, > > No. It was not set :-( > > I turned on the configuration, but the problem persisted. :-( > > Best regards, > > Flavio > > Em sáb., 26 de jun. de 2021 às 10:41, Gregory Nutt > escreveu: > > > > Do you have CONFIG_NET_TCP_WRITE_BUFFERS=y selected? It is required for > > TCP non-blocking send. > > > > > -- > Flavio de Castro Alves Filho > > flavio.al...@gmail.com > Twitter: http://twitter.com/#!/fraviofii > LinkedIn profile: www.linkedin.com/in/flaviocastroalves -- Flavio de Castro Alves Filho flavio.al...@gmail.com Twitter: http://twitter.com/#!/fraviofii LinkedIn profile: www.linkedin.com/in/flaviocastroalves
Re: Socket programming: send() function blocked
Is there any chance that the broker didn't like the mqtt connect message and shutdown the connection and leaving my device alone ... all during send call? If the peer disconnects, the socket should be marked disconnected and the send() should fail with an error.