This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

program hangs up at blocking_recv function sometimes

Environment
- Mac
- nrf tag; 1.1.0
- modem fw: 1.1.0
- DK 0.8.5
- debugging by SEGGER RTT
The program polls SMS for a certain time and if SMS is received, it reads the messages.

When the message is read by blocking_recv, the program hangs up. I coded this program referring to this source:
https://github.com/Rallare/fw-nrfconnect-nrf/blob/nrf9160_samples/samples/nrf9160/simple_at/src/main.c
Also "(sms_notif_fd_s.revents & POLLIN) == POLLIN" sometimes gets true although I don't send SMS to the device.
This symptom did not happen with v1.1.0 of nrf_tag and v1.1.0 of modem

int blocking_recv(int fd, u8_t *buf, u32_t size, u32_t flags)
{
	int err;

	do {
		err = recv(fd, buf, size, flags);
	} while (err < 0 && errno == EAGAIN);

	return err;
}

void main(void)
{
	sms_notif_fd = socket(AF_LTE, 0, NPROTO_AT);
	sms_notif_fd_s.fd = sms_notif_fd;
	sms_notif_fd_s.events = POLLIN;

	/* MQTT connect, publish, and disconnect here */

	while (1) {
		err = poll(&sms_notif_fd_s, 1, K_SECONDS(60));
		if (err < 0) {
            SEGGER_RTT_printf(0,"ERROR: poll %d\n", errno);
		    break;
		}
    if ((sms_notif_fd_s.revents & POLLIN) == POLLIN) { // This sometimes gets true although I don't send SMS to the device
        SEGGER_RTT_printf(0,"before blocking_recv\n");
        sms_notif_bytes = blocking_recv(sms_notif_fd, sms_notif_buf, SMS_NOTIF_BUF_LEN, MSG_DONTWAIT); // Error; stuck here
        SEGGER_RTT_printf(0,"sms is received!\n");
        .
        .
    }

    if ((sms_notif_fd_s.revents & POLLERR) == POLLERR) {
        SEGGER_RTT_printf(0,"POLLERR\n");
        break;
    }

    if ((sms_notif_fd_s.revents & POLLNVAL) == POLLNVAL) {
        SEGGER_RTT_printf(0,"POLLNVAL\n");
        break;
    }
}

Why does this happen and how can I solve this?
Should I close and open a socket at a certain interval?

I erase previous program by "nrfjprog -e" everytime I flash a new one, and delete an old build folder before building a new program.

Thanks!

---- update -----

when blocking_recv is stuck, err = -1 and errno = 11 are always reported.

Related