From d87b080495e71ada650b165a1f06616b433e6073 Mon Sep 17 00:00:00 2001 From: Vladimir Chtchetkine Date: Mon, 6 Dec 2010 10:55:11 -0800 Subject: Submit merged Squashed commit of the following: commit aeefab810c6331e2f96e81f20e4408b39dd3a2ca Author: Vladimir Chtchetkine Date: Thu Dec 2 07:40:34 2010 -0800 Implement -attach-core UI option Change-Id: I4168e2d707cab1b4873ee16d86d5126c1a316abf Change-Id: I2da1ef5d53641f3c60d83d8d5ddf3aff34b0c6c7 --- android/sync-utils.h | 93 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 77 insertions(+), 16 deletions(-) (limited to 'android/sync-utils.h') diff --git a/android/sync-utils.h b/android/sync-utils.h index 8456e9f..f522e27 100644 --- a/android/sync-utils.h +++ b/android/sync-utils.h @@ -47,7 +47,8 @@ void syncsocket_close(SyncSocket* ssocket); /* * Frees memory allocated for SyncSocket descriptor obtained from - * syncsocket_connect routine. + * syncsocket_connect routine. Note that this routine will also close socket + * connection. * Param: * ssocket - SyncSocket descriptor obtained from syncsocket_connect routine. */ @@ -76,6 +77,28 @@ int syncsocket_start_read(SyncSocket* ssocket); int syncsocket_stop_read(SyncSocket* ssocket); /* + * Prepares the socket for write. + * Note: this routine must be called before calling into syncsocket_write_xxx + * routines. + * Param: + * ssocket - SyncSocket descriptor obtained from syncsocket_connect routine. + * Return: + * 0 on success, or -1 on failure. + */ +int syncsocket_start_write(SyncSocket* ssocket); + +/* + * Clears the socket after writing. + * Note: this routine must be called after all data has been written to the + * socket. + * Param: + * ssocket - SyncSocket descriptor obtained from syncsocket_connect routine. + * Return: + * 0 on success, or -1 on failure. + */ +int syncsocket_stop_write(SyncSocket* ssocket); + +/* * Synchronously reads from the socket. * Note: syncsocket_start_read must be called before first call to this routine. * Once syncsocket_start_read has been called, multiple syncsocket_read_xxx can @@ -87,12 +110,12 @@ int syncsocket_stop_read(SyncSocket* ssocket); * size - Number of bytes to read. * deadline - Absoulte deadline time to complete the reading. * Return: - * Number of bytes read on success, 0 on deadline expiration, or -1 on failure. + * Number of bytes read on success, or -1 on failure. */ -int syncsocket_read_absolute(SyncSocket* ssocket, - void* buf, - size_t size, - int64_t deadline); +ssize_t syncsocket_read_absolute(SyncSocket* ssocket, + void* buf, + size_t size, + int64_t deadline); /* * Synchronously reads from the socket. @@ -106,9 +129,47 @@ int syncsocket_read_absolute(SyncSocket* ssocket, * size - Number of bytes to read. * timeout - Timeout (in milliseconds) to complete the reading. * Return: - * Number of bytes read on success, 0 on timeout expiration, or -1 on failure. + * Number of bytes read on success, or -1 on failure. */ -int syncsocket_read(SyncSocket* ssocket, void* buf, size_t size, int timeout); +ssize_t syncsocket_read(SyncSocket* ssocket, void* buf, size_t size, int timeout); + +/* + * Synchronously writes to the socket. + * Note: syncsocket_start_write must be called before first call to this routine. + * Once syncsocket_start_write has been called, multiple syncsocket_write_xxx can + * be called to write all necessary data to the socket. When all necessary data + * has been written, syncsocket_stop_write must be called. + * Param: + * ssocket - SyncSocket descriptor obtained from syncsocket_connect routine. + * buf - Buffer containing data to write. + * size - Number of bytes to write. + * deadline - Absoulte deadline time to complete the writing. + * Return: + * Number of bytes written on success,or -1 on failure. + */ +ssize_t syncsocket_write_absolute(SyncSocket* ssocket, + const void* buf, + size_t size, + int64_t deadline); + +/* + * Synchronously writes to the socket. + * Note: syncsocket_start_write must be called before first call to this routine. + * Once syncsocket_start_write has been called, multiple syncsocket_write_xxx can + * be called to write all necessary data to the socket. When all necessary data + * has been written, syncsocket_stop_write must be called. + * Param: + * ssocket - SyncSocket descriptor obtained from syncsocket_connect routine. + * buf - Buffer containing data to write. + * size - Number of bytes to write. + * timeout - Timeout (in milliseconds) to complete the writing. + * Return: + * Number of bytes written on success, or -1 on failure. + */ +ssize_t syncsocket_write(SyncSocket* ssocket, + const void* buf, + size_t size, + int timeout); /* * Synchronously reads a line terminated with '\n' from the socket. @@ -122,10 +183,10 @@ int syncsocket_read(SyncSocket* ssocket, void* buf, size_t size, int timeout); * Number of chracters read on success, 0 on deadline expiration, * or -1 on failure. */ -int syncsocket_read_line_absolute(SyncSocket* ssocket, - char* buffer, - size_t size, - int64_t deadline); +ssize_t syncsocket_read_line_absolute(SyncSocket* ssocket, + char* buffer, + size_t size, + int64_t deadline); /* * Synchronously reads a line terminated with '\n' from the socket. @@ -139,9 +200,9 @@ int syncsocket_read_line_absolute(SyncSocket* ssocket, * Number of chracters read on success, 0 on deadline expiration, * or -1 on failure. */ -int syncsocket_read_line(SyncSocket* ssocket, - char* buffer, - size_t size, - int timeout); +ssize_t syncsocket_read_line(SyncSocket* ssocket, + char* buffer, + size_t size, + int timeout); #endif // ANDROID_SYNC_UTILS_H -- cgit v1.1