aboutsummaryrefslogtreecommitdiffstats
path: root/android/async-io-common.h
diff options
context:
space:
mode:
authorVladimir Chtchetkine <vchtchetkine@google.com>2012-04-02 07:48:19 -0700
committerVladimir Chtchetkine <vchtchetkine@google.com>2012-04-02 07:48:19 -0700
commit6dc5c2cef91004488f04fc6e9c0946f6d3a29705 (patch)
tree41fdf1c93fef544aea1a08a5066dbb3f26df6351 /android/async-io-common.h
parenta7383ef4eb8d3863c8d582ea0d6b2ddb42125cba (diff)
downloadexternal_qemu-6dc5c2cef91004488f04fc6e9c0946f6d3a29705.zip
external_qemu-6dc5c2cef91004488f04fc6e9c0946f6d3a29705.tar.gz
external_qemu-6dc5c2cef91004488f04fc6e9c0946f6d3a29705.tar.bz2
Refactor asynchronous socket APIs
The initial implementation was a bit too complex in two ways: 1. Each component (the connector, and async socket) had its own set of state and action enums, which was confusing, required value translation, and was not really needed. So, all these enums have been combined into two common enums that are now declared in android/async-io-common.h 2. Too many callbacks, which really complicated implementation of the clients. It is much more efficient to have just two callbacks (one to monitor connection, and another to monitor I/O), letting the client to dispatch on particular event (success/timeout/etc.) This CL fixes these two issues. Change-Id: I545c93dee2e9e9c72c1d25e6cd218c8680933ee3
Diffstat (limited to 'android/async-io-common.h')
-rw-r--r--android/async-io-common.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/android/async-io-common.h b/android/async-io-common.h
new file mode 100644
index 0000000..02714a7
--- /dev/null
+++ b/android/async-io-common.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_ASYNC_IO_COMMON_H_
+#define ANDROID_ASYNC_IO_COMMON_H_
+
+/*
+ * Contains declarations common for asynchronous socket I/O
+ */
+
+/* Enumerates asynchronous I/O states.
+ * Values from this enum are passed to callbacks associated with an I/O,
+ * indicating at what state the I/O is. */
+typedef enum AsyncIOState {
+ /* Asynchronous I/O has been queued. (0) */
+ ASIO_STATE_QUEUED,
+ /* Asynchronous I/O has started. This state indicates that I/O has been
+ * performed for the first time. (1) */
+ ASIO_STATE_STARTED,
+ /* Asynchronous I/O is continuing. This state indicates that I/O has been
+ * invoked for the second (or more) time. (2) */
+ ASIO_STATE_CONTINUES,
+ /* Asynchronous I/O is about to be retried. (3) */
+ ASIO_STATE_RETRYING,
+ /* Asynchronous I/O has been successfuly completed. (4) */
+ ASIO_STATE_SUCCEEDED,
+ /* Asynchronous I/O has failed. (5) */
+ ASIO_STATE_FAILED,
+ /* Asynchronous I/O has timed out. (6) */
+ ASIO_STATE_TIMED_OUT,
+ /* Asynchronous I/O has been cancelled (due to disconnect, for
+ * instance). (7) */
+ ASIO_STATE_CANCELLED,
+} AsyncIOState;
+
+/* Enumerates actions to perform with an I/O on state transition.
+ * Values from this enum are returned from async I/O callbacks, indicating what
+ * action should be performed with the I/O by I/O handler. */
+typedef enum AsyncIOAction {
+ /* I/O is done. Perform default action depending on I/O type. */
+ ASIO_ACTION_DONE,
+ /* Abort the I/O. */
+ ASIO_ACTION_ABORT,
+ /* Retry the I/O. */
+ ASIO_ACTION_RETRY,
+} AsyncIOAction;
+
+#endif /* ANDROID_ASYNC_IO_COMMON_H_ */