aboutsummaryrefslogtreecommitdiffstats
path: root/android/async-utils.h
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@android.com>2011-03-17 14:57:51 +0100
committerDavid 'Digit' Turner <digit@android.com>2011-04-11 18:08:11 +0200
commitf9e333ade2529f257ced6bcff8e5824cb07eacf9 (patch)
treec3ea65717a284ae744764b4ecf8c5b745ea3415d /android/async-utils.h
parent2086c639648ccecc9081705a279249ce939d818b (diff)
downloadexternal_qemu-f9e333ade2529f257ced6bcff8e5824cb07eacf9.zip
external_qemu-f9e333ade2529f257ced6bcff8e5824cb07eacf9.tar.gz
external_qemu-f9e333ade2529f257ced6bcff8e5824cb07eacf9.tar.bz2
Simplify async utils by removing extra LoopIo parameter.
This patch removes the LoopIo parameter from asyncReader_run() by storing the initial pointer passed to asyncReader_init() inside the object itself. Same treatment is performed for: - AsyncReader - AsyncWriter - AsyncLineReader - AsyncConnector - AsyncConsoleConnect Change-Id: Ic74b817e4c326230ca1d38b3a5d8c4790c4f90c1
Diffstat (limited to 'android/async-utils.h')
-rw-r--r--android/async-utils.h47
1 files changed, 38 insertions, 9 deletions
diff --git a/android/async-utils.h b/android/async-utils.h
index 0b52f37..93148c1 100644
--- a/android/async-utils.h
+++ b/android/async-utils.h
@@ -32,6 +32,13 @@ typedef enum {
ASYNC_NEED_MORE /* more data is needed, try again later */
} AsyncStatus;
+/**************************************************************************
+ **************************************************************************
+ *****
+ ***** A S Y N C R E A D E R
+ *****
+ *****/
+
/* An AsyncReader makes it easier to read a given number of bytes into
* a target buffer asynchronously. Usage is the following:
*
@@ -44,6 +51,7 @@ typedef struct {
uint8_t* buffer;
size_t buffsize;
size_t pos;
+ LoopIo* io;
} AsyncReader;
/* Setup an ASyncReader, by giving the address of the read buffer,
@@ -68,8 +76,14 @@ void asyncReader_init(AsyncReader* ar,
* ASYNC_NEED_MORE: If there was not enough incoming data to complete
* the read (or if 'events' doesn't contain LOOP_IO_READ).
*/
-AsyncStatus asyncReader_read(AsyncReader* ar,
- LoopIo* io);
+AsyncStatus asyncReader_read(AsyncReader* ar);
+
+/**************************************************************************
+ **************************************************************************
+ *****
+ ***** A S Y N C W R I T E R
+ *****
+ *****/
/* An AsyncWriter is the counterpart of an AsyncReader, but for writing
* data to a file descriptor asynchronously.
@@ -78,6 +92,7 @@ typedef struct {
const uint8_t* buffer;
size_t buffsize;
size_t pos;
+ LoopIo* io;
} AsyncWriter;
/* Setup an ASyncWriter, by giving the address of the write buffer,
@@ -102,10 +117,16 @@ void asyncWriter_init(AsyncWriter* aw,
* ASYNC_NEED_MORE: If not all bytes could be sent yet (or if 'events'
* doesn't contain LOOP_IO_WRITE).
*/
-AsyncStatus asyncWriter_write(AsyncWriter* aw,
- LoopIo* io);
+AsyncStatus asyncWriter_write(AsyncWriter* aw);
+/**************************************************************************
+ **************************************************************************
+ *****
+ ***** A S Y N C L I N E R E A D E R
+ *****
+ *****/
+
/* An AsyncLineReader allows you to read one line of text asynchronously.
* The biggest difference with AsyncReader is that you don't know the line
* size in advance, so the object will read data byte-by-byte until it
@@ -115,6 +136,7 @@ typedef struct {
uint8_t* buffer;
size_t buffsize;
size_t pos;
+ LoopIo* io;
} AsyncLineReader;
/* Setup an AsyncLineReader to read at most 'buffsize' characters (bytes)
@@ -148,8 +170,7 @@ void asyncLineReader_init(AsyncLineReader* alr,
* ASYNC_NEED_MORE: If there was not enough incoming data (or events
* does not contain LOOP_IO_READ).
*/
-AsyncStatus asyncLineReader_read(AsyncLineReader* alr,
- LoopIo* io);
+AsyncStatus asyncLineReader_read(AsyncLineReader* alr);
/* Return a pointer to the NON-ZERO-TERMINATED line characters, if any.
* If 'pLength" is not NULL, the function sets '*pLength' to the length
@@ -169,11 +190,19 @@ const char* asyncLineReader_getLineRaw(AsyncLineReader* alr, int *pLength);
*/
const char* asyncLineReader_getLine(AsyncLineReader* alr);
+/**************************************************************************
+ **************************************************************************
+ *****
+ ***** A S Y N C C O N N E C T O R
+ *****
+ *****/
+
/* Asynchronous connection to a socket
*/
typedef struct {
- int error;
- int state;
+ int error;
+ int state;
+ LoopIo* io;
} AsyncConnector;
AsyncStatus
@@ -182,6 +211,6 @@ asyncConnector_init(AsyncConnector* ac,
LoopIo* io);
AsyncStatus
-asyncConnector_run(AsyncConnector* ac, LoopIo* io);
+asyncConnector_run(AsyncConnector* ac);
#endif /* ANDROID_ASYNC_UTILS_H */