diff options
author | Mathias Agopian <mathias@google.com> | 2009-05-22 01:08:01 -0700 |
---|---|---|
committer | Mathias Agopian <mathias@google.com> | 2009-05-22 01:08:01 -0700 |
commit | 67667115c51693ac27338be2aa7004789b15ff81 (patch) | |
tree | 19b840f4ae9c91448722069085a5e97f6c5a1d10 /include/cutils | |
parent | b862ab74c95e4f76c7081ea5756c7ba719833f8c (diff) | |
parent | ad3f0d74b4d0c52a819b0b4b242f26bd4ce07bc9 (diff) | |
download | system_core-67667115c51693ac27338be2aa7004789b15ff81.zip system_core-67667115c51693ac27338be2aa7004789b15ff81.tar.gz system_core-67667115c51693ac27338be2aa7004789b15ff81.tar.bz2 |
merge master to master_gl
Diffstat (limited to 'include/cutils')
-rw-r--r-- | include/cutils/abort_socket.h | 103 | ||||
-rw-r--r-- | include/cutils/fdevent.h | 74 | ||||
-rw-r--r-- | include/cutils/native_handle.h | 31 | ||||
-rw-r--r-- | include/cutils/tztime.h | 1 |
4 files changed, 122 insertions, 87 deletions
diff --git a/include/cutils/abort_socket.h b/include/cutils/abort_socket.h new file mode 100644 index 0000000..fbb1112 --- /dev/null +++ b/include/cutils/abort_socket.h @@ -0,0 +1,103 @@ +/* + * Copyright 2009, 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. + */ + +/* Helper to perform abortable blocking operations on a socket: + * asocket_connect() + * asocket_accept() + * asocket_read() + * asocket_write() + * These calls are similar to the regular syscalls, but can be aborted with: + * asocket_abort() + * + * 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. + */ + +#include <stdlib.h> +#include <sys/socket.h> + +#ifndef __CUTILS_ABORT_SOCKET_H__ +#define __CUTILS_ABORT_SOCKET_H__ +#ifdef __cplusplus +extern "C" { +#endif + +struct asocket { + int fd; /* primary socket fd */ + int abort_fd[2]; /* pipe used to abort */ +}; + +/* Create an asocket from fd. + * Sets the socket to non-blocking mode. + * Returns NULL on error with errno set. + */ +struct asocket *asocket_init(int fd); + +/* Blocking socket I/O with timeout. + * Calling asocket_abort() from another thread will cause each of these + * functions to immediately return with value -1 and errno ECANCELED. + * timeout is in ms, use -1 to indicate no timeout. On timeout -1 is returned + * with errno ETIMEDOUT. + * EINTR is handled in-call. + * Other semantics are identical to the regular syscalls. + */ +int asocket_connect(struct asocket *s, const struct sockaddr *addr, + socklen_t addrlen, int timeout); + +int asocket_accept(struct asocket *s, struct sockaddr *addr, + socklen_t *addrlen, int timeout); + +int asocket_read(struct asocket *s, void *buf, size_t count, int timeout); + +int asocket_write(struct asocket *s, const void *buf, size_t count, + int timeout); + +/* Abort above calls and shutdown socket. + * Further I/O operations on this socket will immediately fail after this call. + * asocket_destroy() should be used to release resources once all threads + * have returned from blocking calls on the socket. + */ +void asocket_abort(struct asocket *s); + +/* Close socket and free asocket structure. + * Must not be called until all calls on this structure have completed. + */ +void asocket_destroy(struct asocket *s); + +#ifdef __cplusplus +} +#endif +#endif //__CUTILS_ABORT_SOCKET__H__ diff --git a/include/cutils/fdevent.h b/include/cutils/fdevent.h deleted file mode 100644 index 7a442d4..0000000 --- a/include/cutils/fdevent.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2006 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 __FDEVENT_H -#define __FDEVENT_H - -/* events that may be observed */ -#define FDE_READ 0x0001 -#define FDE_WRITE 0x0002 -#define FDE_ERROR 0x0004 - -/* features that may be set (via the events set/add/del interface) */ -#define FDE_DONT_CLOSE 0x0080 - -typedef struct fdevent fdevent; - -typedef void (*fd_func)(int fd, unsigned events, void *userdata); - -/* Allocate and initialize a new fdevent object -*/ -fdevent *fdevent_create(int fd, fd_func func, void *arg); - -/* Uninitialize and deallocate an fdevent object that was -** created by fdevent_create() -*/ -void fdevent_destroy(fdevent *fde); - -/* Initialize an fdevent object that was externally allocated -*/ -void fdevent_install(fdevent *fde, int fd, fd_func func, void *arg); - -/* Uninitialize an fdevent object that was initialized by -** fdevent_install() -*/ -void fdevent_remove(fdevent *item); - -/* Change which events should cause notifications -*/ -void fdevent_set(fdevent *fde, unsigned events); -void fdevent_add(fdevent *fde, unsigned events); -void fdevent_del(fdevent *fde, unsigned events); - -/* loop forever, handling events. -*/ -void fdevent_loop(); - -struct fdevent -{ - fdevent *next; - fdevent *prev; - - int fd; - unsigned short state; - unsigned short events; - - fd_func func; - void *arg; -}; - - -#endif diff --git a/include/cutils/native_handle.h b/include/cutils/native_handle.h index 38ac11a..89d6b65 100644 --- a/include/cutils/native_handle.h +++ b/include/cutils/native_handle.h @@ -17,52 +17,57 @@ #ifndef NATIVE_HANDLE_H_ #define NATIVE_HANDLE_H_ -#include <sys/cdefs.h> - -__BEGIN_DECLS +#ifdef __cplusplus +extern "C" { +#endif typedef struct { - int version; /* sizeof(native_handle) */ + int version; /* sizeof(native_handle_t) */ int numFds; /* number of file-descriptors at &data[0] */ int numInts; /* number of ints at &data[numFds] */ int data[0]; /* numFds + numInts ints */ -} native_handle; +} native_handle_t; + +/* keep the old definition for backward source-compatibility */ +typedef native_handle_t native_handle; /* * native_handle_close * - * closes the file descriptors contained in this native_handle + * closes the file descriptors contained in this native_handle_t * * return 0 on success, or a negative error code on failure * */ -int native_handle_close(const native_handle* h); +int native_handle_close(const native_handle_t* h); /* * native_handle_create * - * creates a native_handle and initializes it. must be destroyed with + * creates a native_handle_t and initializes it. must be destroyed with * native_handle_delete(). * */ -native_handle* native_handle_create(int numFds, int numInts); +native_handle_t* native_handle_create(int numFds, int numInts); /* * native_handle_delete * - * frees a native_handle allocated with native_handle_create(). - * This ONLY frees the memory allocated for the native_handle, but doesn't + * frees a native_handle_t allocated with native_handle_create(). + * This ONLY frees the memory allocated for the native_handle_t, but doesn't * close the file descriptors; which can be achieved with native_handle_close(). * * return 0 on success, or a negative error code on failure * */ -int native_handle_delete(native_handle* h); +int native_handle_delete(native_handle_t* h); -__END_DECLS +#ifdef __cplusplus +} +#endif #endif /* NATIVE_HANDLE_H_ */ diff --git a/include/cutils/tztime.h b/include/cutils/tztime.h index 4af2ce4..cf103ca 100644 --- a/include/cutils/tztime.h +++ b/include/cutils/tztime.h @@ -32,6 +32,7 @@ void localtime_tz(const time_t * const timep, struct tm * tmp, const char* tz); struct strftime_locale { const char *mon[12]; /* short names */ const char *month[12]; /* long names */ + const char *standalone_month[12]; /* long standalone names */ const char *wday[7]; /* short names */ const char *weekday[7]; /* long names */ const char *X_fmt; |