History log of /system/core/include/cutils/abort_socket.h
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
92a7541bce0f8ed7649dcbadd83b27d71e4f391f 20-May-2009 Nick Pelly <npelly@google.com> Helper to perform abortable blocking operations on a socket:
These calls are similar to the regular syscalls, but can be aborted with:

Calling close() on a regular POSIX socket does not abort blocked syscalls on
that socket in other threads.

After calling asocket_abort() the socket cannot be reused.

Call asocket_destory() *after* all threads have finished with the socket to
finish closing the socket and free the asocket structure.

The helper is implemented by setting the socket non-blocking to initiate
syscalls connect(), accept(), read(), write(), then using a blocking poll()
on both the primary socket and a local pipe. This makes the poll() abortable
by writing a byte to the local pipe in asocket_abort().

asocket_create() sets the fd to non-blocking mode. It must not be changed to
blocking mode.

Using asocket will triple the number of file descriptors required per
socket, due to the local pipe. It may be possible to use a global pipe per
process rather than per socket, but we have not been able to come up with a
race-free implementation yet.

All functions except asocket_init() and asocket_destroy() are thread safe.