<?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のトピックMQX 4.1 RTCS web_hvac response.content_length question</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-4-1-RTCS-web-hvac-response-content-length-question/m-p/384523#M12821</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's not clear to me how to set response.content_length in my CGI functions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The MQX_RTCS User Guide says in section 8.2.14:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;content_length&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Length of the response entity from CGI script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you look at the web_hvac example there are conflicting examples of how to set the content_length field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Example 1 - content_length is set to data_length&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;In cgi_index.c there is this code:&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14129721747585954" jivemacro_uid="_14129721747585954"&gt;
&lt;P&gt;/* Calculate content length while saving it to buffer */&lt;/P&gt;
&lt;P&gt;length = snprintf(str, BUFF_SIZE, "%ld\n%ld\n%ld\n", hour, min, sec);&lt;/P&gt;
&lt;P&gt;response.data = str;&lt;/P&gt;
&lt;P&gt;response.data_length = length;&lt;/P&gt;
&lt;P&gt;response.content_length = response.data_length;&lt;/P&gt;
&lt;P&gt;/* Send response */&lt;/P&gt;
&lt;P&gt;HTTPSRV_cgi_write(&amp;amp;response);&lt;/P&gt;
&lt;P&gt;return (response.content_length);&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This seems to match what it says in the MQX RTCS User Guide.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Example 2 - content_length is set to zero&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;In cgi_hvac.c there is this code:&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14129721747307863" jivemacro_uid="_14129721747307863"&gt;
&lt;P&gt;response.ses_handle = param-&amp;gt;ses_handle;&lt;/P&gt;
&lt;P&gt;response.content_type = HTTPSRV_CONTENT_TYPE_HTML;&lt;/P&gt;
&lt;P&gt;response.status_code = 200;&lt;/P&gt;
&lt;P&gt;response.data = "&amp;lt;!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"&amp;gt;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;HVAC Settings response&amp;lt;/title&amp;gt;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "&amp;lt;meta http-equiv=\"REFRESH\" content=\"0;url=hvac.shtml\"&amp;gt;&amp;lt;/head&amp;gt;\n&amp;lt;body&amp;gt;\n";&lt;/P&gt;
&lt;P&gt;response.data_length = strlen(response.data);&lt;/P&gt;
&lt;P&gt;response.content_length = 0;&lt;/P&gt;
&lt;P&gt;HTTPSRV_cgi_write(&amp;amp;response);&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;if (!bParams)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; response.data = "No parameters received.&amp;lt;br&amp;gt;\n";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; response.data_length = strlen(response.data);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; HTTPSRV_cgi_write(&amp;amp;response);&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;response.data = "&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;\n&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;";&lt;/P&gt;
&lt;P&gt;response.data_length = strlen(response.data);&lt;/P&gt;
&lt;P&gt;HTTPSRV_cgi_write(&amp;amp;response);&lt;/P&gt;
&lt;P&gt;return (response.content_length);&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this case there are multiple calls to HTTPSRV_cgi_write() and content_length is set to zero on line 8.&amp;nbsp; It is never set to non-zero.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question:&lt;/P&gt;&lt;P&gt;1. When should content_length be set to data_length and when should it be set to zero?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Oct 2014 16:13:38 GMT</pubDate>
    <dc:creator>pbanta</dc:creator>
    <dc:date>2014-10-10T16:13:38Z</dc:date>
    <item>
      <title>MQX 4.1 RTCS web_hvac response.content_length question</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-4-1-RTCS-web-hvac-response-content-length-question/m-p/384523#M12821</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's not clear to me how to set response.content_length in my CGI functions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The MQX_RTCS User Guide says in section 8.2.14:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;content_length&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Length of the response entity from CGI script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you look at the web_hvac example there are conflicting examples of how to set the content_length field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Example 1 - content_length is set to data_length&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;In cgi_index.c there is this code:&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14129721747585954" jivemacro_uid="_14129721747585954"&gt;
&lt;P&gt;/* Calculate content length while saving it to buffer */&lt;/P&gt;
&lt;P&gt;length = snprintf(str, BUFF_SIZE, "%ld\n%ld\n%ld\n", hour, min, sec);&lt;/P&gt;
&lt;P&gt;response.data = str;&lt;/P&gt;
&lt;P&gt;response.data_length = length;&lt;/P&gt;
&lt;P&gt;response.content_length = response.data_length;&lt;/P&gt;
&lt;P&gt;/* Send response */&lt;/P&gt;
&lt;P&gt;HTTPSRV_cgi_write(&amp;amp;response);&lt;/P&gt;
&lt;P&gt;return (response.content_length);&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This seems to match what it says in the MQX RTCS User Guide.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Example 2 - content_length is set to zero&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;In cgi_hvac.c there is this code:&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14129721747307863" jivemacro_uid="_14129721747307863"&gt;
&lt;P&gt;response.ses_handle = param-&amp;gt;ses_handle;&lt;/P&gt;
&lt;P&gt;response.content_type = HTTPSRV_CONTENT_TYPE_HTML;&lt;/P&gt;
&lt;P&gt;response.status_code = 200;&lt;/P&gt;
&lt;P&gt;response.data = "&amp;lt;!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"&amp;gt;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;HVAC Settings response&amp;lt;/title&amp;gt;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "&amp;lt;meta http-equiv=\"REFRESH\" content=\"0;url=hvac.shtml\"&amp;gt;&amp;lt;/head&amp;gt;\n&amp;lt;body&amp;gt;\n";&lt;/P&gt;
&lt;P&gt;response.data_length = strlen(response.data);&lt;/P&gt;
&lt;P&gt;response.content_length = 0;&lt;/P&gt;
&lt;P&gt;HTTPSRV_cgi_write(&amp;amp;response);&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;if (!bParams)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; response.data = "No parameters received.&amp;lt;br&amp;gt;\n";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; response.data_length = strlen(response.data);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; HTTPSRV_cgi_write(&amp;amp;response);&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;response.data = "&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;\n&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;";&lt;/P&gt;
&lt;P&gt;response.data_length = strlen(response.data);&lt;/P&gt;
&lt;P&gt;HTTPSRV_cgi_write(&amp;amp;response);&lt;/P&gt;
&lt;P&gt;return (response.content_length);&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this case there are multiple calls to HTTPSRV_cgi_write() and content_length is set to zero on line 8.&amp;nbsp; It is never set to non-zero.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question:&lt;/P&gt;&lt;P&gt;1. When should content_length be set to data_length and when should it be set to zero?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Oct 2014 16:13:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-4-1-RTCS-web-hvac-response-content-length-question/m-p/384523#M12821</guid>
      <dc:creator>pbanta</dc:creator>
      <dc:date>2014-10-10T16:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: MQX 4.1 RTCS web_hvac response.content_length question</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-4-1-RTCS-web-hvac-response-content-length-question/m-p/384524#M12822</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Paul,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;If &lt;EM&gt;content_length&lt;/EM&gt; is set to zero in first call of &lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;HTTPSRV_cgi_write()&lt;/SPAN&gt;, The server will signalize end of response entity by closing the connection and thus ignoring keep-alive flag of session. If you set &lt;EM&gt;content_length &lt;/EM&gt;to non-zero value it is send to client to inform him about length of response entity and thus it is not required to close the connection and keep-alive can be used. Variable &lt;EM&gt;data_length &lt;/EM&gt;is used for storing length of data to be written in one specific call of &lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;HTTPSRV_cgi_write()&lt;/SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;So in short: &lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;You MUST set content_length non-zero if you have keep-alive enabled. Otherwise client will not know that it has all the data and the connection will stall. But you CAN have it set to zero with keep-alive disabled.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;Set &lt;EM&gt;data_length&lt;/EM&gt; to length of data pointed to by &lt;EM&gt;data &lt;/EM&gt;variable for every call of &lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;HTTPSRV_cgi_write()&lt;/SPAN&gt;.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;I hope this answered your question.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;P.S: &lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;In MQX 4.2 there will be support for chunked transmission encoding so you will not have to worry about content length.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;Best regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;Karel&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Oct 2014 08:18:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/MQX-4-1-RTCS-web-hvac-response-content-length-question/m-p/384524#M12822</guid>
      <dc:creator>karelm_</dc:creator>
      <dc:date>2014-10-14T08:18:35Z</dc:date>
    </item>
  </channel>
</rss>

