<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>MQX Software Solutions中的主题 Re: Keepalive sock option</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/Keepalive-sock-option/m-p/450786#M15094</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Garabo,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you&amp;nbsp; for the advice. it can be an useful solution. but can you give me some information, or some docs, about OPT_KEEPALIVE and ENET_STATS. are these useful in my case?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 22 May 2015 07:30:54 GMT</pubDate>
    <dc:creator>emanueletrapani</dc:creator>
    <dc:date>2015-05-22T07:30:54Z</dc:date>
    <item>
      <title>Keepalive sock option</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Keepalive-sock-option/m-p/450784#M15092</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi, i have codewarrior 10.6 and mqx 4.1. i use frdmk64f demo board.&lt;/P&gt;&lt;P&gt;i modified the eth_to_serial demo to have multiple sock that send messages from ethernet to serial and the serial send messages on every active sock . i would to know if it is possible to individuate when i lost the connection (as would happen if a cable breaks, for example) so i can shutdown the opportune sock and close the relative task. for this purpouse i try to set OPT_KEEPALIVE with the function setsockopt() and i use optval=1 so i expect to notice something after 1 minute since i unplug the cable. but i notice an error on the recv() function after that 8 minutes are passed (that i reduced to 3 minute setting the option OPT_CONNECT_TIMEOUT). i set true the opt_receive_nowait option on every sockets i accepted. i see that the recv() give the error RTCSERR_TCP_CONN_ABORTED (software caused connection abort).&amp;nbsp; i read the rtcs user guide but i have not found an exaustive explanation of this keepalive option. can you help me on this?&lt;/P&gt;&lt;P&gt;on the other side i read that, in ENET_STATS, exist ST_TX_SQE (Heartbeats lost), and ST_TX_CARRIER (Carrier sense lost), physical errors/conditions that maybe they do right for me. but i check them with ENET_get_stats() and i see they are fixed to 0 even if i unplug the cable. maybe you know these physical errors/conditions and you can tell me how i can use them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;here are some code:&lt;/P&gt;&lt;P&gt;main task&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="_jivemacro_uid_14321328404345019 jive_macro_code jive_text_macro" data-renderedposition="260_8_1232_112" jivemacro_uid="_14321328404345019"&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; option = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retval = setsockopt(sockets.sock4, SOL_TCP, OPT_KEEPALIVE, &amp;amp;option, sizeof(option));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; option = 181000;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retval = setsockopt(sockets.sock4, SOL_TCP, OPT_CONNECT_TIMEOUT, &amp;amp;option, sizeof(option));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;trasmission task&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14321329411785530" data-renderedposition="393_8_1232_178" jivemacro_uid="_14321329411785530"&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;while(1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count = recv(sock_local, buff, RX_BUFFER_SIZE, 0);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (count != RTCS_ERROR)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count = fwrite(buff, 1, count, ser_device_local);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="line-height: 1.5;"&gt; status = shutdown(sock_local, 0);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it work fine. i would have some advice&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i get the enet stats with&lt;/P&gt;&lt;P&gt;control task&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14321334735551937 jive_text_macro" data-renderedposition="697_8_1232_528" jivemacro_uid="_14321334735551937"&gt;&lt;P&gt;ihandle = ipcfg_get_ihandle(BSP_DEFAULT_ENET_DEVICE);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if(ihandle != NULL)&lt;/P&gt;&lt;P&gt;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp; ehandle = RTCS_get_enet_handle(ihandle);&lt;/P&gt;&lt;P&gt;&amp;nbsp; fprintf(stdout, "\n\rCTRL: ehandle is: 0x%x", ehandle);&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp; optlen = sizeof(uint32_t);&lt;/P&gt;&lt;P&gt;&amp;nbsp; while(1) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; retval = getsockopt(client, SOL_SOCKET, OPT_SOCKET_ERROR, &amp;amp;opt, optlen);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (retval != RTCS_OK)&lt;/P&gt;&lt;P&gt;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fputs("Fatal Error CTRL: Unable to get socket options.", stderr);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _task_block();&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; fprintf(stdout, "\n\rCTRL: sock error is: 0x%x", opt);&lt;/P&gt;&lt;P&gt;&amp;nbsp; fprintf(stdout, "\t 0x%x", RTCS_geterror(client));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; enet_stat_ptr = ENET_get_stats(ehandle);&lt;/P&gt;&lt;P&gt;&amp;nbsp; fprintf(stdout, "\n\rCTRL: enet stat sqe is: %d", enet_stat_ptr-&amp;gt;ST_TX_SQE);&lt;/P&gt;&lt;P&gt;&amp;nbsp; fprintf(stdout, "\n\rCTRL: carrier is: %d", enet_stat_ptr-&amp;gt;ST_TX_CARRIER);&lt;/P&gt;&lt;P&gt;&amp;nbsp; fprintf(stdout, "\n\rCTRL: Ethernet packets received: %d", enet_stat_ptr-&amp;gt;COMMON.ST_RX_TOTAL);&lt;/P&gt;&lt;P&gt;&amp;nbsp; enet_stat_ptr = ENET_get_stats(ehandle);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (temp != enet_stat_ptr-&amp;gt;ST_TX_SQE) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; temp = enet_stat_ptr-&amp;gt;ST_TX_SQE;&lt;/P&gt;&lt;P&gt;&amp;nbsp; fprintf(stdout, "\n\rCTRL: enet stat sqe is: %d ; different from previous", enet_stat_ptr-&amp;gt;ST_TX_SQE);&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (temp2 != enet_stat_ptr-&amp;gt;ST_TX_CARRIER) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; temp2 = enet_stat_ptr-&amp;gt;ST_TX_CARRIER;&lt;/P&gt;&lt;P&gt;&amp;nbsp; fprintf(stdout, "\n\rCTRL: enet stat carrier is: %d ; different from previous", enet_stat_ptr-&amp;gt;ST_TX_CARRIER);&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp; _time_delay(1);&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i read in another question on this forum about to check the opt socket error for the socket in which i active the keepalive option, but it does not run on my app.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you for the patience about my english and my explanation.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2015 14:58:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Keepalive-sock-option/m-p/450784#M15092</guid>
      <dc:creator>emanueletrapani</dc:creator>
      <dc:date>2015-05-20T14:58:17Z</dc:date>
    </item>
    <item>
      <title>Re: Keepalive sock option</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Keepalive-sock-option/m-p/450785#M15093</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Emanuele,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try setting the OPT_RECEIVE_TIMEOUT to a low value. While you are in the recv() you should have this time out running and expiring according with the data you provide.&lt;/P&gt;&lt;P&gt;For instance:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14322362742169336" data-renderedposition="134_8_1155_112" jivemacro_uid="_14322362742169336" modifiedtitle="true"&gt;&lt;P&gt;/* Wait 250ms then check if session is still connected. */&lt;/P&gt;&lt;P&gt;option = 250;&lt;/P&gt;&lt;P&gt;error = setsockopt(sock, SOL_TCP, OPT_RECEIVE_TIMEOUT, &amp;amp;option, sizeof(option));&lt;/P&gt;&lt;P&gt;if (error != RTCS_OK)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return(-1);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Garabo&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;&lt;STRONG&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;/STRONG&gt;&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 May 2015 19:25:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Keepalive-sock-option/m-p/450785#M15093</guid>
      <dc:creator>Luis_Garabo</dc:creator>
      <dc:date>2015-05-21T19:25:03Z</dc:date>
    </item>
    <item>
      <title>Re: Keepalive sock option</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Keepalive-sock-option/m-p/450786#M15094</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Garabo,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you&amp;nbsp; for the advice. it can be an useful solution. but can you give me some information, or some docs, about OPT_KEEPALIVE and ENET_STATS. are these useful in my case?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 May 2015 07:30:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Keepalive-sock-option/m-p/450786#M15094</guid>
      <dc:creator>emanueletrapani</dc:creator>
      <dc:date>2015-05-22T07:30:54Z</dc:date>
    </item>
    <item>
      <title>Re: Keepalive sock option</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Keepalive-sock-option/m-p/450787#M15095</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Emanuele,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the documentation that we have about Keep alive:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/33098i44DED63DF8B2489D/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.png" alt="pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regarding ENET_STAT you can find the description of the structure in the section &lt;STRONG&gt;9.2.9 ENET_STATS&lt;/STRONG&gt; from the RTCS user's guide located in the C:\Freescale\Freescale_MQX_4_2\doc\rtcs directory.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have a great day,&lt;BR /&gt;Garabo&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;&lt;STRONG&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;/STRONG&gt;&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 May 2015 17:25:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Keepalive-sock-option/m-p/450787#M15095</guid>
      <dc:creator>Luis_Garabo</dc:creator>
      <dc:date>2015-05-25T17:25:33Z</dc:date>
    </item>
    <item>
      <title>Re: Keepalive sock option</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Keepalive-sock-option/m-p/450788#M15096</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thank you Garabo. i read this docs yet. &lt;SPAN style="color: #51626f; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;i try to set OPT_KEEPALIVE with the function setsockopt() and i use optval=1 so i expect to notice something after 1 minute since i unplug the cable. but i se the error "connection aborted" after 8 minute. &lt;SPAN style="color: #51626f; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;i read these docs, so i know in ENET_STATS, exist ST_TX_SQE (Heartbeats lost), and ST_TX_CARRIER (Carrier sense lost), physical errors/conditions that maybe they do right for me. but i check them with ENET_get_stats() and i see they are fixed to 0 even if i unplug the cable. maybe somebady know how they work. &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 May 2015 07:26:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Keepalive-sock-option/m-p/450788#M15096</guid>
      <dc:creator>emanueletrapani</dc:creator>
      <dc:date>2015-05-26T07:26:25Z</dc:date>
    </item>
  </channel>
</rss>

