aboutsummaryrefslogtreecommitdiffstats
path: root/android/sync-utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'android/sync-utils.h')
-rw-r--r--android/sync-utils.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/android/sync-utils.h b/android/sync-utils.h
index 1dcf649..d99caaf 100644
--- a/android/sync-utils.h
+++ b/android/sync-utils.h
@@ -22,6 +22,8 @@
#ifndef ANDROID_SYNC_UTILS_H
#define ANDROID_SYNC_UTILS_H
+#include "sockets.h"
+
/* Descriptor for a connected non-blocking socket providing synchronous I/O */
typedef struct SyncSocket SyncSocket;
@@ -224,4 +226,25 @@ ssize_t syncsocket_read_line(SyncSocket* ssocket,
*/
int syncsocket_get_socket(SyncSocket* ssocket);
+/* Converts syncsocket_xxx operation status into success / failure result.
+ * Param:
+ * status - syncsocket_xxx operation status to convert.
+ * Return:
+ * 0 if status passed to this routine indicated a success, or < 0 if status
+ * indicated a failure.
+ */
+static inline int
+syncsocket_result(int status)
+{
+ if (status == 0) {
+ // Status 0 returned from syncsocket_xxx means "disconnection", which is
+ // a failure.
+ status = -1;
+ } else if (status > 0) {
+ // Status > 0 means success.
+ status = 0;
+ }
+ return status;
+}
+
#endif // ANDROID_SYNC_UTILS_H