diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2007-12-17 15:30:45 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2007-12-17 15:30:45 +0000 |
commit | e2dfba3be4d4103cee944be98848ab52506231bf (patch) | |
tree | c7a9f6d60a1ff432f4a9e978cc64b0ef652b8c19 | |
parent | 7a1d5f307d88d8cf6bbf25bb465693a43809dbdd (diff) |
Add a small buffer for writes.
-rw-r--r-- | src/lwp.c | 45 |
1 files changed, 43 insertions, 2 deletions
@@ -209,8 +209,11 @@ _lwp_read_time (void) return tv.tv_usec / 1000 + tv.tv_sec * 1000; } +static gchar _lwp_write_buf[8192]; +static guint _lwp_write_len; + static gboolean -_lwp_writen (int fd, gconstpointer _data, gsize len) +__lwp_writen (int fd, gconstpointer _data, gsize len) { const gchar *data = _data; @@ -234,6 +237,44 @@ _lwp_writen (int fd, gconstpointer _data, gsize len) } static gboolean +_lwp_flush (int fd) +{ + gboolean ret; + + ret = __lwp_writen (fd, _lwp_write_buf, _lwp_write_len); + _lwp_write_len = 0; + + return ret; +} + +static gboolean +_lwp_close (int fd) +{ + gboolean ret = TRUE; + + ret &= _lwp_flush (fd); + ret &= close (fd) != -1; + + return ret; +} + +static gboolean +_lwp_writen (int fd, gconstpointer data, gsize len) +{ + if (len + _lwp_write_len > G_N_ELEMENTS (_lwp_write_buf)) { + if (! _lwp_flush (fd)) + return FALSE; + + if (len >= G_N_ELEMENTS (_lwp_write_buf)) + return __lwp_writen (fd, data, len); + } + + memcpy (_lwp_write_buf + _lwp_write_len, data, len); + _lwp_write_len += len; + return TRUE; +} + +static gboolean _lwp_write_string (int fd, const char *str) { gushort len = strlen (str); @@ -524,7 +565,7 @@ _lwp_write_events (const LWP_EventRecord *events, gushort n_events) pending_allocators = NULL; } - return close (fd) != -1; + return _lwp_close (fd); CLEAN_FD: close (fd); |