Skip to contentSkip to conversation

read returns more bytes than requested?

Xenomai-help Jeff Webb 2 participants 4 messages Sep 11, 2006 – Sep 14, 2006

lore
Share & tools
lore

Jeff Webb

author
#0 lore raw

I am having some success porting my RTLinux application, but I have encountered a strange error.

I have this snippet of code that is reading data from an rtai-skin FIFO:

result = read(runtime2io_fd, &resp, sizeof(resp)); if (result != sizeof(resp))

   {
     printf("requested %d bytes, got %d\n", sizeof(resp), result);
     snprintf(err_str, MAX_STR_LEN, "cannot read response from %s",
              RUNTIME2IO_FIFO_DEV);
     sim_halt(err_str);
     return;

}

I get the following output:

requested 312 bytes, got 1220
halting the sim: cannot read response from /dev/rtf1

I didn't think that a read could return more bytes than was requested. Does anyone understand this behaviour? This is code that works under RT-Linux. I am trying to determine why it is working differently under xenomai.

-Jeff

#1 lore raw
Quoted 14 lines · Jeff Webb

I am having some success porting my RTLinux application, but I have encountered a strange error.

I have this snippet of code that is reading data from an rtai-skin FIFO:

  result = read(runtime2io_fd, &resp, sizeof(resp));
  if (result != sizeof(resp))
    {
      printf("requested %d bytes, got %d\n", sizeof(resp), result);
      snprintf(err_str, MAX_STR_LEN, "cannot read response from %s",
               RUNTIME2IO_FIFO_DEV);
      sim_halt(err_str);
      return;
    }
Quoted 6 lines

I get the following output:

requested 312 bytes, got 1220
halting the sim: cannot read response from /dev/rtf1

I didn't think that a read could return more bytes than was requested. Does anyone understand this behaviour?

The initial patch has introduced a bug. Will fix.

Quoted 9 lines

This is code that works under RT-Linux. I am trying to determine why it is working differently under xenomai.

-Jeff

_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help

Signature · 1 line
Philippe.
#2 lore raw
In reply to Jeff Webb
Quoted 14 lines · Jeff Webb

I am having some success porting my RTLinux application, but I have encountered a strange error.

I have this snippet of code that is reading data from an rtai-skin FIFO:

  result = read(runtime2io_fd, &resp, sizeof(resp));
  if (result != sizeof(resp))
    {
      printf("requested %d bytes, got %d\n", sizeof(resp), result);
      snprintf(err_str, MAX_STR_LEN, "cannot read response from %s",
               RUNTIME2IO_FIFO_DEV);
      sim_halt(err_str);
      return;
    }
Quoted 6 lines

I get the following output:

requested 312 bytes, got 1220
halting the sim: cannot read response from /dev/rtf1

I didn't think that a read could return more bytes than was requested. Does anyone understand this behaviour? This is code that works under RT-Linux. I am trying to determine why it is working differently under xenomai.

Another round of refactoring the message pipe support. This time, it introduces the ability to get partial reads from the /dev/rtp* device endpoint, instead of requiring read() calls to collect all of the pending data at once. The remaining work will allow the same from the real-time API endpoint. This patch applies against the latest patch sent.

nucleus/pipe.h +3 -0
@@ -57,6 +57,7 @@
 
     xnholder_t link;
     unsigned size;
+    unsigned rdoff;
     
 } xnpipe_mh_t;
 
@@ -156,6 +157,8 @@
 
 #define xnpipe_m_size(mh) ((mh)->size)
 
+#define xnpipe_m_rdoff(mh) ((mh)->rdoff)
+
 #endif /* __KERNEL__ */
 
 #endif /* !_XENO_NUCLEUS_PIPE_H */
nucleus/pipe.c +42 -42

124 lines not on this page · raw message

Signature · 1 line
Philippe.
author
#3 lore raw
Quoted 10 lines · Philippe Gerum
Quoted 2 lines · Jeff Webb

I didn't think that a read could return more bytes than was requested. Does anyone understand this behaviour? This is code that works under RT-Linux. I am trying to determine why it is working differently under xenomai.

Another round of refactoring the message pipe support. This time, it introduces the ability to get partial reads from the /dev/rtp* device endpoint, instead of requiring read() calls to collect all of the pending data at once. The remaining work will allow the same from the real-time API endpoint. This patch applies against the latest patch sent.

Thanks again! The read appears to be working now, at least as far as I can tell. I am now hunting down the source of an unrelated bug, a little further down the line.

-Jeff