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-connector.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-connector.h')
-rw-r--r-- | android/async-socket-connector.h | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/android/async-socket-connector.h b/android/async-socket-connector.h index 4c05059..0769f56 100644 --- a/android/async-socket-connector.h +++ b/android/async-socket-connector.h @@ -58,9 +58,10 @@ * to cancel further connection attempts by returning ASIO_ACTION_ABORT, or it * can allow another connection attempt by returning ASIO_ACTION_RETRY. * - * The client has no control over the lifespan of initialized connector instance. - * It always self-destructs after client's cllback returns with a status other - * than ASIO_ACTION_RETRY. + * 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 async socket connector descriptor. */ @@ -81,6 +82,8 @@ typedef AsyncIOAction (*asc_event_cb)(void* opaque, AsyncIOState event); /* Creates and initializes AsyncSocketConnector instance. + * Note that upon exit from this routine the reference count to the returned + * object is set to 1. * Param: * address - Initialized socket address to connect to. * retry_to - Timeout to retry a failed connection attempt in milliseconds. @@ -98,6 +101,24 @@ extern AsyncSocketConnector* async_socket_connector_new(const SockAddress* addre asc_event_cb cb, void* cb_opaque); +/* References AsyncSocketConnector object. + * Param: + * connector - Initialized AsyncSocketConnector instance. + * Return: + * Number of outstanding references to the object. + */ +extern int async_socket_connector_reference(AsyncSocketConnector* connector); + +/* Releases AsyncSocketConnector object. + * Note that upon exit from this routine the object might be destroyed, even if + * the routine returns value other than zero. + * Param: + * connector - Initialized AsyncSocketConnector instance. + * Return: + * Number of outstanding references to the object. + */ +extern int async_socket_connector_release(AsyncSocketConnector* connector); + /* Initiates asynchronous connection. * Note that connection result will be reported via callback set with the call to * async_socket_connector_new routine. |