<?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>topic Re: RTCS detecting remote side close on a socket in MQX Software Solutions</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/RTCS-detecting-remote-side-close-on-a-socket/m-p/335363#M10812</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Correct, after MQX 4.1.1.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 14 Nov 2014 06:06:03 GMT</pubDate>
    <dc:creator>Martin_</dc:creator>
    <dc:date>2014-11-14T06:06:03Z</dc:date>
    <item>
      <title>RTCS detecting remote side close on a socket</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/RTCS-detecting-remote-side-close-on-a-socket/m-p/335360#M10809</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How do I detect if the remote endpoint is closed, or issued a shutdown request without actually reading or writing data to the socket (or using a KEEPALIVE which is only a polled test)?&amp;nbsp; I.E. how do I determine the socket state?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;'RTCS_selectset(s, 1, -1) == s' tells me if "Data or shutdown request is initiated by remote endpoint or all sent data are acknowledged", but how do I determine which one (shutdown or data ack)?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;PMT&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Nov 2014 20:23:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/RTCS-detecting-remote-side-close-on-a-socket/m-p/335360#M10809</guid>
      <dc:creator>pmt</dc:creator>
      <dc:date>2014-11-12T20:23:16Z</dc:date>
    </item>
    <item>
      <title>Re: RTCS detecting remote side close on a socket</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/RTCS-detecting-remote-side-close-on-a-socket/m-p/335361#M10810</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;RTCS_selectset() cannot return you this information, as it has just one return value, which is socket handle. Latest RTCS already has BSD-like select() function and it can distinguish between data requests/ close or reset requests/ acknowledge received for send data. It is part of the Freescale MQX for Kinetis SDK, and also will be in next MQX classic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In "older MQX" you need to use other RTCS functions. recv()/send() functions give you an error when remote endpoint is reset/connection closed, example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; retval = recv(sock,...);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(retval &amp;lt; 0)&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; uint32_t error_code = RTCS_geterror(sock);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* this might be for example RTCSERR_TCP_CONN_RLSD or RTCSERR_TCP_CONN_RESET */&lt;/P&gt;&lt;P&gt;&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; RTCS_shutdown(sock, 0); /* complete graceful connection close. destroy socket. */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sock = RTCS_SOCKET_ERROR;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Personally I would use RTCS_selectset() only on listening sockets to block wait for connection requests. If you like non-portable customization, you can just read the state from the TCB of a valid TCP socket:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14158694255899068" jivemacro_uid="_14158694255899068"&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; struct tcb_struct *tcb = ((struct socket_struct *)sock)-&amp;gt;TCB_PTR;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if(NULL == tcb)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; {&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* connection is released -&amp;gt; reset, abort */&lt;/P&gt;
&lt;P&gt;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp; else&lt;/P&gt;
&lt;P&gt;&amp;nbsp; {&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint16_t tcp_state = tcb-&amp;gt;state;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* it will be one of states defined in tcp_prv.h:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * TCB states */&lt;/P&gt;
&lt;P&gt;#define LISTEN&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;#define SYN_SENT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;#define SYN_RECEIVED&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;#define ESTABLISHED&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;
&lt;P&gt;#define FINWAIT_1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/P&gt;
&lt;P&gt;#define FINWAIT_2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&lt;/P&gt;
&lt;P&gt;#define CLOSE_WAIT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&lt;/P&gt;
&lt;P&gt;#define CLOSING&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&lt;/P&gt;
&lt;P&gt;#define LAST_ACK&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&lt;/P&gt;
&lt;P&gt;#define TIME_WAIT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&lt;/P&gt;
&lt;P&gt;#define CLOSED&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&lt;/P&gt;
&lt;P&gt;#define BOUND&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11&lt;/P&gt;
&lt;P&gt;*/&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; }&lt;/P&gt;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Martin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Nov 2014 09:02:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/RTCS-detecting-remote-side-close-on-a-socket/m-p/335361#M10810</guid>
      <dc:creator>Martin_</dc:creator>
      <dc:date>2014-11-13T09:02:31Z</dc:date>
    </item>
    <item>
      <title>Re: RTCS detecting remote side close on a socket</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/RTCS-detecting-remote-side-close-on-a-socket/m-p/335362#M10811</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Martin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&amp;nbsp; I'm glad to see the full BSD select functionality coming in the next release.&amp;nbsp; For my reference, this is after MQX 4.1.1, correct? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Nov 2014 17:39:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/RTCS-detecting-remote-side-close-on-a-socket/m-p/335362#M10811</guid>
      <dc:creator>pmt</dc:creator>
      <dc:date>2014-11-13T17:39:51Z</dc:date>
    </item>
    <item>
      <title>Re: RTCS detecting remote side close on a socket</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/RTCS-detecting-remote-side-close-on-a-socket/m-p/335363#M10812</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Correct, after MQX 4.1.1.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Nov 2014 06:06:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/RTCS-detecting-remote-side-close-on-a-socket/m-p/335363#M10812</guid>
      <dc:creator>Martin_</dc:creator>
      <dc:date>2014-11-14T06:06:03Z</dc:date>
    </item>
  </channel>
</rss>

