<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>nrf_poll may be consuming data when not supposed to on nrf9160</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/52437/nrf_poll-may-be-consuming-data-when-not-supposed-to-on-nrf9160</link><description>I&amp;#39;m using the socket(AF_LTE) to talk directly to the modem on the nrf9160 and wanted to add a timeout to my recv() call. I added a call to poll() before recv() and am seeing strange results now. It looks like the poll is consuming some of the data. I</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 23 Nov 2019 02:58:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/52437/nrf_poll-may-be-consuming-data-when-not-supposed-to-on-nrf9160" /><item><title>RE: nrf_poll may be consuming data when not supposed to on nrf9160</title><link>https://devzone.nordicsemi.com/thread/221676?ContentTypeID=1</link><pubDate>Sat, 23 Nov 2019 02:58:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d20caf14-e63c-480a-b7b3-14cff65e350f</guid><dc:creator>miked531</dc:creator><description>&lt;p&gt;I ran the test again with ncs v1.1.0 and modem firmware v1.1.0. I no longer get the EINVAL, however the send() does now return ENOMEM after a few thousand iterations, which is understandable.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_poll may be consuming data when not supposed to on nrf9160</title><link>https://devzone.nordicsemi.com/thread/220058?ContentTypeID=1</link><pubDate>Thu, 14 Nov 2019 12:06:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:82665568-42f5-49a0-b2a2-246e4a6fd57c</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Sounds like a good plan. Get in touch if&amp;nbsp;encounter any more problems.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;
&lt;div style="left:207px;top:-20.0076px;"&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_poll may be consuming data when not supposed to on nrf9160</title><link>https://devzone.nordicsemi.com/thread/219972?ContentTypeID=1</link><pubDate>Thu, 14 Nov 2019 06:21:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3f61a25e-dc8d-4e2c-9439-97b9fb39960b</guid><dc:creator>miked531</dc:creator><description>&lt;p&gt;I was having the issue with nrf v1.0.0. I came across a similar issue and v1.1.0 resolved it with the updated nrfxlib. I&amp;#39;ll give this another shot once the new modem firmware comes out&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_poll may be consuming data when not supposed to on nrf9160</title><link>https://devzone.nordicsemi.com/thread/218182?ContentTypeID=1</link><pubDate>Mon, 04 Nov 2019 11:12:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:43c8255d-a324-409c-8b3e-68612972c1ab</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Hello miked!&lt;/p&gt;
&lt;p&gt;Have you made any progress on this, or should I take a deeper look at your problem?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_poll may be consuming data when not supposed to on nrf9160</title><link>https://devzone.nordicsemi.com/thread/216975?ContentTypeID=1</link><pubDate>Sun, 27 Oct 2019 23:42:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:34c03700-e9eb-4131-b3e4-018912506308</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I tested your code, and I got the same error message as you (&lt;span&gt;EINVAL=22&lt;/span&gt;). However, I noticed something interesting, the EINVAL error is not the initial cause of the problem. I saw that the send function in three of the five threads failed with the errno &lt;a href="https://github.com/NordicPlayground/nrfxlib/blob/v1.0.0/bsdlib/include/nrf_errno.h#L25"&gt;NRF_ENOMEM=12&lt;/a&gt;&amp;nbsp;(Cannot allocate memory) initially. Then, following that, the send() functions in the respective threads failed with EINVAL.&lt;/p&gt;
&lt;p&gt;I am not sure what specifically is happening internally, but will look into it. By the way, I tried changing the stack size of all the threads to 512, then it didn&amp;#39;t fail until&amp;nbsp;63000 iterations was passed by.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_poll may be consuming data when not supposed to on nrf9160</title><link>https://devzone.nordicsemi.com/thread/216263?ContentTypeID=1</link><pubDate>Wed, 23 Oct 2019 04:30:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2333f97f-b030-4d9e-bbd6-44e9ad2462e6</guid><dc:creator>miked531</dc:creator><description>&lt;p&gt;The sample did work. I modified it to add concurrency with multiple AF_LTE sockets open and it starts to fail after just a few thousand iterations, mostly with EINVAL&lt;/p&gt;
&lt;p&gt;#include &amp;lt;zephyr.h&amp;gt;&lt;/p&gt;
&lt;p&gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;#include &amp;lt;string.h&amp;gt;&lt;/p&gt;
&lt;p&gt;//functions like send() and rev() is declared here&lt;br /&gt;#include &amp;lt;net/socket.h&amp;gt;&lt;/p&gt;
&lt;p&gt;static const u8_t at_buf[256] = &amp;quot;AT+CGMI\r\n&amp;quot;;&lt;br /&gt;static const u8_t at_cfun[256] = &amp;quot;AT+CFUN=4\r\n&amp;quot;;&lt;br /&gt;#define SENDME at_buf&lt;/p&gt;
&lt;p&gt;void runner(void *a, void *b, void *c)&lt;br /&gt;{&lt;br /&gt; int counter = 0;&lt;br /&gt; int id = (int)a;&lt;br /&gt; char buf[256];&lt;br /&gt; int sockfd, bytes_sent, bytes_read;&lt;/p&gt;
&lt;p&gt;sockfd = socket(AF_LTE, 0, NPROTO_AT);&lt;/p&gt;
&lt;p&gt;if (sockfd == -1) {&lt;br /&gt; printk(&amp;quot;[%d] Could not open socket\n&amp;quot;, id);&lt;br /&gt; k_sleep(86400 * 1000);&lt;br /&gt; } else {&lt;br /&gt; printk(&amp;quot;[%d] sockfd %d\n&amp;quot;, id, sockfd);&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;struct timeval tv;&lt;br /&gt; tv.tv_sec = 1;&lt;br /&gt; tv.tv_usec = 0;&lt;br /&gt; setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&amp;amp;tv, sizeof tv);&lt;br /&gt; &lt;br /&gt; int bytes_to_send = strlen(SENDME);&lt;/p&gt;
&lt;p&gt;while(1) {&lt;br /&gt; if( (++counter % 1000) == 0 ) printk(&amp;quot;[%d] count %d\n&amp;quot;, id, counter);&lt;br /&gt; bytes_sent = send(sockfd, SENDME, bytes_to_send, 0);&lt;br /&gt; if (bytes_sent != bytes_to_send) {&lt;br /&gt; printk(&amp;quot;[%d] send failed, returned %d, errno %d\n&amp;quot;, id, bytes_sent, errno);&lt;br /&gt; } else{&lt;br /&gt; //printk(&amp;quot;[%d] sent %d bytes\n&amp;quot;, id, bytes_sent);&lt;br /&gt; }&lt;br /&gt; bytes_read = recv(sockfd, buf, sizeof(buf), 0);&lt;br /&gt; if( bytes_read &amp;gt; 0 ) {&lt;br /&gt; //printk(&amp;quot;[%d] recv %d bytes: %s\n&amp;quot;, id, bytes_read, buf);&lt;br /&gt; } else {&lt;br /&gt; printk(&amp;quot;[%d] recv failed, errno %d\n&amp;quot;, id, errno);&lt;br /&gt; }&lt;br /&gt; //k_sleep(100);&lt;br /&gt; }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;K_THREAD_DEFINE(zero, 1024, runner, 0, 0, 0, 5, 0, 0);&lt;br /&gt;K_THREAD_DEFINE(one, 1024, runner, 1, 0, 0, 5, 0, 0);&lt;br /&gt;K_THREAD_DEFINE(two, 1024, runner, 2, 0, 0, 5, 0, 0);&lt;br /&gt;K_THREAD_DEFINE(three, 1024, runner, 3, 0, 0, 5, 0, 0);&lt;br /&gt;K_THREAD_DEFINE(four, 1024, runner, 4, 0, 0, 5, 0, 0);&lt;br /&gt;K_THREAD_DEFINE(five, 1024, runner, 5, 0, 0, 5, 0, 0);&lt;/p&gt;
&lt;p&gt;void main(void)&lt;br /&gt;{&lt;br /&gt; k_sleep(86400 * 1000);&lt;br /&gt;}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_poll may be consuming data when not supposed to on nrf9160</title><link>https://devzone.nordicsemi.com/thread/215244?ContentTypeID=1</link><pubDate>Wed, 16 Oct 2019 10:20:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:84cdd663-1675-4be5-8c24-005a43c99ae7</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Test out the sample below, and check if you are able to get that to work.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-e1cf9136ec50440da65aeb445fa1285f/recv_5F00_timeout.zip"&gt;devzone.nordicsemi.com/.../recv_5F00_timeout.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_poll may be consuming data when not supposed to on nrf9160</title><link>https://devzone.nordicsemi.com/thread/215186?ContentTypeID=1</link><pubDate>Wed, 16 Oct 2019 02:23:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e7e201b9-58c9-4702-ac5a-daa9240e1078</guid><dc:creator>miked531</dc:creator><description>&lt;p&gt;I tried the code above and strangeness happened as soon at I put it in (setsockopt failed with errno EPERM!?). I&amp;#39;m now convinced there is an issue, and my guess is that it&amp;#39;s in nrfxlib. Note that my test was using the AF_LTE socket&lt;/p&gt;
&lt;p&gt;Mike&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_poll may be consuming data when not supposed to on nrf9160</title><link>https://devzone.nordicsemi.com/thread/215136?ContentTypeID=1</link><pubDate>Tue, 15 Oct 2019 15:52:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ffecf54c-ad67-4cbf-907f-29f6efc05f91</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I tested the suggestion, and it worked fine as far as I could see. I added the lines in the snippet below, and if nothing was received in a second, the function stopped and the program continued.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;struct timeval tv;
tv.tv_sec = 1;
tv.tv_usec = 0;
setsockopt(common_socket_fd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&amp;amp;tv, sizeof tv);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;
&lt;div style="left:133px;top:154.2px;"&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_poll may be consuming data when not supposed to on nrf9160</title><link>https://devzone.nordicsemi.com/thread/214704?ContentTypeID=1</link><pubDate>Sun, 13 Oct 2019 18:50:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6cdc0e95-bca3-48fd-a798-2ae5c1bb299d</guid><dc:creator>miked531</dc:creator><description>&lt;p&gt;Thanks for the suggestion. For my application, I can can use a polling loop with recv(MSG_DONTWAIT). I&amp;#39;d like to use the SO_RCVTIMEO, but I&amp;#39;m not confident it is immune from the same&amp;nbsp;behavior I see with&amp;nbsp;and don&amp;#39;t have time to experiment currently.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_poll may be consuming data when not supposed to on nrf9160</title><link>https://devzone.nordicsemi.com/thread/212794?ContentTypeID=1</link><pubDate>Tue, 01 Oct 2019 11:08:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:23951942-675e-49e2-8cbc-22e431426566</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I think you can enable a timeout on the recv() function by using the&amp;nbsp;&lt;a href="https://github.com/NordicPlayground/fw-nrfconnect-zephyr/blob/v1.14.99-ncs2/include/net/socket_offload.h#L83"&gt;setsockopt()&lt;/a&gt;&amp;nbsp;function (See this &lt;a href="https://stackoverflow.com/questions/2876024/linux-is-there-a-read-or-recv-from-socket-with-timeout"&gt;link&lt;/a&gt;). It can be done by&amp;nbsp;setting &amp;quot;level&amp;quot; to SOL_SOCKET and &amp;quot;option name&amp;quot; to SO_RCVTIMEO and set&amp;nbsp;your timeout and size of timeout variable to respectively&amp;nbsp;&amp;quot;optval&amp;quot;&amp;nbsp;and&amp;nbsp;&amp;quot;optlen&amp;quot;.&lt;/p&gt;
&lt;p&gt;Take a look&lt;a href="https://github.com/NordicPlayground/fw-nrfconnect-nrf/blob/master/lib/bsdlib/nrf91_sockets.c#L536"&gt;&amp;nbsp;here&lt;/a&gt;, to get an understanding of the arguments used when setting a timeout.&lt;/p&gt;
&lt;p&gt;I have not tested this, and I am not sure if I understand it correctly, but it is worth taking a look at.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_poll may be consuming data when not supposed to on nrf9160</title><link>https://devzone.nordicsemi.com/thread/211076?ContentTypeID=1</link><pubDate>Sun, 22 Sep 2019 14:58:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c08ba2c-014f-4ca6-9a1b-be5106e62ae3</guid><dc:creator>miked531</dc:creator><description>&lt;p&gt;Note that this is not limited to AF_LTE. I have been seeing strange behavior with an AF_INET socket also.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>