aboutsummaryrefslogtreecommitdiffstats
path: root/android/sync-utils.c
diff options
context:
space:
mode:
authorVladimir Chtchetkine <vchtchetkine@google.com>2010-12-01 17:29:09 -0800
committerVladimir Chtchetkine <vchtchetkine@google.com>2010-12-02 07:32:47 -0800
commit0d4c88288c6109eec4c4b4801519809f0c23cd46 (patch)
treef65480b565192f07f6ce2cac26cfb736307177e8 /android/sync-utils.c
parentb2c1727d5f5820402ebb1f78e039e758e57389ef (diff)
downloadexternal_qemu-0d4c88288c6109eec4c4b4801519809f0c23cd46.zip
external_qemu-0d4c88288c6109eec4c4b4801519809f0c23cd46.tar.gz
external_qemu-0d4c88288c6109eec4c4b4801519809f0c23cd46.tar.bz2
Implement line reading on syncsocket
Change-Id: I1fa22c34203b163e1b0a78240be73a4a7473691e
Diffstat (limited to 'android/sync-utils.c')
-rw-r--r--android/sync-utils.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/android/sync-utils.c b/android/sync-utils.c
index aedc2e6..1695615 100644
--- a/android/sync-utils.c
+++ b/android/sync-utils.c
@@ -132,7 +132,7 @@ syncsocket_stop_read(SyncSocket* ssocket)
int
syncsocket_read_absolute(SyncSocket* ssocket,
void* buf,
- int size,
+ size_t size,
int64_t deadline)
{
int ret;
@@ -156,7 +156,39 @@ syncsocket_read_absolute(SyncSocket* ssocket,
}
int
-syncsocket_read(SyncSocket* ssocket, void* buf, int size, int timeout)
+syncsocket_read(SyncSocket* ssocket, void* buf, size_t size, int timeout)
{
return syncsocket_read_absolute(ssocket, buf, size, iolooper_now() + timeout);
}
+
+int
+syncsocket_read_line_absolute(SyncSocket* ssocket,
+ char* buffer,
+ size_t size,
+ int64_t deadline)
+{
+ size_t read_chars = 0;
+
+ while (read_chars < size) {
+ char ch;
+ int ret = syncsocket_read_absolute(ssocket, &ch, 1, deadline);
+ if (ret <= 0) {
+ return ret;
+ }
+ buffer[read_chars++] = ch;
+ if (ch == '\n') {
+ return (int)read_chars;
+ }
+ }
+
+ /* Not enough room in the input buffer!*/
+ errno = ENOMEM;
+ return -1;
+}
+
+int
+syncsocket_read_line(SyncSocket* ssocket, char* buffer, size_t size, int timeout)
+{
+ return syncsocket_read_line_absolute(ssocket, buffer, size,
+ iolooper_now() + timeout);
+}