Hello, I'm working on programming a cycle to measure the power consumption. I need to send a message and wait for a response for some time, then shut the modem off, no matter if there was a response or not. The recvfrom function is going to wait for a response indefinitely, so I'm trying to make it non-blocking by setting the O_NONBLOCK flag, without success. Here's what I tried, this is edited NTP sample to ensure it works fine:
int client_fd = socket(AF_INET, SOCK_DGRAM, 0); printk("client_fd: %d\n\r", client_fd); int flags = fcntl(client_fd, F_GETFL); printk("Flags = %d\n Errno = %d\n", flags, errno); fcntl(client_fd, F_SETFL, flags | O_NONBLOCK); printk("Flags = %d\n Errno = %d\n", flags, errno);
this is the response:
client_fd: 2 Flags = -1 Errno = 88 Flags = -1 Errno = 88
so basically the socket opening function works fine, but somehow the fcntl doesn't recognize just opened socket descriptor. The program goes all the way down to the recvfrom function and the bind/send functions work fine with the same socket:
bind err: 0 sendto ret: 48
I've also tried to do it with setsockopt:
struct timeval tv; tv.tv_sec = 1; /* 1 Secs Timeout */ setsockopt(client_fd, SOL_SOCKET, SO_RCVTIMEO,(struct timeval *)&tv,sizeof(struct timeval));
but the response is the same, indicating that there's a problem with the socket descriptor. Any of these lines don't change the behavior at all, it's just waiting for response indefinitely.
Firmware: 1.0.0
Board v0.7.0
SES V4.16 Nordic Edition (64-bit)