[pypy-commit] pypy reverse-debugger: Handle partial write()

arigo pypy.commits at gmail.com
Mon Jun 6 13:01:27 EDT 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: reverse-debugger
Changeset: r84974:58ec0aa13c9b
Date: 2016-06-06 19:02 +0200
http://bitbucket.org/pypy/pypy/changeset/58ec0aa13c9b/

Log:	Handle partial write()

diff --git a/rpython/translator/revdb/rdb-src/revdb.c b/rpython/translator/revdb/rdb-src/revdb.c
--- a/rpython/translator/revdb/rdb-src/revdb.c
+++ b/rpython/translator/revdb/rdb-src/revdb.c
@@ -62,14 +62,28 @@
 {
     /* write the current buffer content to the OS */
 
-    ssize_t size = rpy_revdb.buf_p - rpy_rev_buffer;
+    ssize_t wsize, size = rpy_revdb.buf_p - rpy_rev_buffer;
+    char *p;
     rpy_revdb.buf_p = rpy_rev_buffer;
-    if (size > 0 && rpy_rev_fileno >= 0) {
-        if (write(rpy_rev_fileno, rpy_rev_buffer, size) != size) {
+    if (size == 0 || rpy_rev_fileno < 0)
+        return;
+
+    p = rpy_rev_buffer;
+ retry:
+    wsize = write(rpy_rev_fileno, p, size);
+    if (wsize >= size)
+        return;
+    if (wsize <= 0) {
+        if (wsize == 0)
+            fprintf(stderr, "Writing to PYPYREVDB file: "
+                            "unexpected non-blocking mode\n");
+        else
             fprintf(stderr, "Fatal error: writing to PYPYREVDB file: %m\n");
-            abort();
-        }
+        abort();
     }
+    p += wsize;
+    size -= wsize;
+    goto retry;
 }
 
 


More information about the pypy-commit mailing list