diff options
author | Vladimir Chtchetkine <vchtchetkine@google.com> | 2012-04-03 10:27:12 -0700 |
---|---|---|
committer | Vladimir Chtchetkine <vchtchetkine@google.com> | 2012-04-03 16:13:42 -0700 |
commit | ef4ccd385650612a830a098f4b1eac48482b65b3 (patch) | |
tree | dad74ea321507a3a0912a0142387e8df3bff901f /android/async-socket.h | |
parent | 6dc5c2cef91004488f04fc6e9c0946f6d3a29705 (diff) | |
download | external_qemu-ef4ccd385650612a830a098f4b1eac48482b65b3.zip external_qemu-ef4ccd385650612a830a098f4b1eac48482b65b3.tar.gz external_qemu-ef4ccd385650612a830a098f4b1eac48482b65b3.tar.bz2 |
Make all async I/O object referenced.
Since it's hard to control lifespan of an object in asynchronous environment, we
should make all AsyncXxx objects a referenced objecst, that will self-destruct
when its reference count drops to zero, indicating that the last client that
used the object has abandoned it.
Change-Id: I6f8194aa14e52a23a8772d827583782989654504
Diffstat (limited to 'android/async-socket.h')
-rw-r--r-- | android/async-socket.h | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/android/async-socket.h b/android/async-socket.h index 1402126..661fae5 100644 --- a/android/async-socket.h +++ b/android/async-socket.h @@ -29,6 +29,11 @@ * Since all the operations (including connection) are asynchronous, all the * operation results are reported back to the client of this API via set of * callbacks that client supplied to this API. + * + * Since it's hard to control lifespan of an object in asynchronous environment, + * we make AsyncSocketConnector a referenced object, that will self-destruct when + * its reference count drops to zero, indicating that the last client has + * abandoned that object. */ /* Declares asynchronous socket descriptor. */ @@ -65,7 +70,26 @@ typedef AsyncIOAction (*on_as_io_cb)(void* io_opaque, * AsyncSocketIO API *******************************************************************************/ -/* Gets AsyncSocket instance for an I/O */ +/* References AsyncSocketIO object. + * Param: + * asio - Initialized AsyncSocketIO instance. + * Return: + * Number of outstanding references to the object. + */ +extern int async_socket_io_reference(AsyncSocketIO* asio); + +/* Releases AsyncSocketIO object. + * Note that upon exit from this routine the object might be destroyed, even if + * the routine returns value other than zero. + * Param: + * asio - Initialized AsyncSocketIO instance. + * Return: + * Number of outstanding references to the object. + */ +extern int async_socket_io_release(AsyncSocketIO* asio); + +/* Gets AsyncSocket instance for an I/O. Note that this routine will reference + * AsyncSocket instance before returning it to the caller. */ extern AsyncSocket* async_socket_io_get_socket(const AsyncSocketIO* asio); /* Cancels time out set for an I/O */ @@ -121,6 +145,24 @@ extern AsyncSocket* async_socket_new(int port, on_as_connection_cb connect_cb, void* client_opaque); +/* References AsyncSocket object. + * Param: + * as - Initialized AsyncSocket instance. + * Return: + * Number of outstanding references to the object. + */ +extern int async_socket_reference(AsyncSocket* as); + +/* Releases AsyncSocket object. + * Note that upon exit from this routine the object might be destroyed, even if + * the routine returns value other than zero. + * Param: + * as - Initialized AsyncSocket instance. + * Return: + * Number of outstanding references to the object. + */ +extern int async_socket_release(AsyncSocket* as); + /* Asynchronously connects to an asynchronous socket. * Note that connection result will be reported via callback passed to the * async_socket_new routine. @@ -216,4 +258,7 @@ extern Duration async_socket_deadline(AsyncSocket* as, int rel); /* Gets an opaque pointer associated with the socket's client */ extern void* async_socket_get_client_opaque(const AsyncSocket* as); +/* Gets TCP port for the socket. */ +extern int async_socket_get_port(const AsyncSocket* as); + #endif /* ANDROID_ASYNC_SOCKET_H_ */ |