Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is one possible problem with your code; this may not be the one that is causing you to only get 64 bytes but it could explain what you are seeing. Assume that you invoke the function Readport_Refid() with a buffer of 128 bytes. In other words, your invocation was something like:</p> <pre><code>char buffer[128]; Readport_Refid(128, buffer); </code></pre> <p>Assume for whatever reason that the first call to select() gets you a return value of 1 (since one bit is set). Your code is only setting one bit so you go off and you read()</p> <pre><code>iret = read(m_fdRefdev, buf, ilen); g_dbg-&gt;debug("Refid portread: Read len(%d):%d\n",ilen,iret); break; </code></pre> <p>iret returns 64 (which means 64 bytes are read) and your program prints a nice message and since ierr is still 0 and iret (64) is less than ilen (128) you go round again and call select().</p> <p>Assume that you get more data and select() returns 1 again. Then you will go read again on the same buffer with the same ilen and overwrite the first 64 bytes that were read.</p> <p>At the very least, you should do the following. I have only shown below the changed lines. First add an iread variable and make sure you use it to preserve data that you've already read. Then use iread to determine whether you've read enough or not.</p> <pre><code>int CACS_RefID::Readport_Refid(int ilen, char* buf) { int ierr=0, iret = 0, ictr=0, iread = 0; [...] default: iret = read(m_fdRefdev, buf + iread, ilen - iread); if (iret &gt; 0) iread += iret; g_dbg-&gt;debug("Refid portread: Read len(%d):%d\n",ilen,iret); break; } }while((ierr == 0) &amp;&amp; (iread&lt;ilen) ); [...] </code></pre> <p>**** EDITED 2013-08-19 ****</p> <p>I want to reiterate a comment made by <a href="https://stackoverflow.com/users/905902/wildplasser">@wildplasser</a></p> <p>You should really also be setting FD_SET on each trip around the loop. Great catch. </p> <p>With respect to your new code, does it work or do you still have a problem?</p> <p>**** EDITED again 2013-08-19 ****</p> <p>Getting EINTR is nothing to be worried about. You should just plan on resetting FD_SET and trying again.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload