<div dir="ltr">Hi,<div><br></div><div>isn't it a good idea to extract the read loop into a separate function (I thought we already had one in the past...)?</div><div><br></div><div>I mean, the read syscall is not guaranteed to actually read the number requested bytes (not even if we are reading from a local file).</div><div><br></div><div>Besides, if I remember correctly, there are multiple code locations that could use that new function.</div><div><br></div><div>cheers,</div><div>rodrigo</div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-07-10 12:56 GMT+01:00 Omri Kramer <span dir="ltr"><<a href="mailto:omri.kramer@gmail.com" target="_blank">omri.kramer@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">When the --remote option is used, the file descriptor<br>
used in bread is a socketand it may return after only<br>
part of the data is read. Keep going looping until all<br>
the data is received when --remote option is on.<br>
<br>
Signed-off-by: Omri Kramer <<a href="mailto:omri.kramer@gmail.com">omri.kramer@gmail.com</a>><br>
Signed-off-by: Lior Fisch <<a href="mailto:fischlior@gmail.com">fischlior@gmail.com</a>><br>
---<br>
criu/bfd.c | 25 +++++++++++++++++++++++--<br>
1 file changed, 23 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/criu/bfd.c b/criu/bfd.c<br>
index 8269ab1..7c54d9b 100644<br>
--- a/criu/bfd.c<br>
+++ b/criu/bfd.c<br>
@@ -15,6 +15,7 @@<br>
#include "util.h"<br>
#include "xmalloc.h"<br>
#include "page.h"<br>
+#include "cr_options.h"<br>
<br>
#undef LOG_PREFIX<br>
#define LOG_PREFIX "bfd: "<br>
@@ -298,9 +299,29 @@ int bread(struct bfd *bfd, void *buf, int size)<br>
{<br>
struct xbuf *b = &bfd->b;<br>
int more = 1, filled = 0;<br>
+ int ret;<br>
+ size_t curr = 0;<br>
<br>
- if (!bfd_buffered(bfd))<br>
- return read(bfd->fd, buf, size);<br>
+ if (!bfd_buffered(bfd)) {<br>
+ if(!opts.remote)<br>
+ return read(bfd->fd, buf, size);<br>
+ /*<br>
+ * Required to keep reading,<br>
+ * for succesfully Reading all the data<br>
+ * from the socket, when on remote option.<br>
+ */<br>
+ while (1) {<br>
+ ret = read(bfd->fd, buf + curr, size - curr);<br>
+ if (ret < 0) {<br>
+ pr_perror("Can't read from buffer\n");<br>
+ return -1;<br>
+ }<br>
+<br>
+ curr += ret;<br>
+ if (curr == size || ret == 0)<br>
+ return curr;<br>
+ }<br>
+ }<br>
<br>
while (more > 0) {<br>
int chunk;<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.7.4<br>
<br>
</font></span></blockquote></div><br></div>