From 722a5c0462f38827f4097065bfc3826b9e0e9fb4 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Tue, 12 May 2009 16:26:16 -0700 Subject: Add support for "standalone months" to tztime's strftime(). The idea here is that some languages need a different form of the month name in constructions like "January 2" than in "January 2009", since the one in the "January 2" case really means "of January." So with this change, a format string of "%-B" will use the standalone month, while "%B" will continue to use the format month. --- include/cutils/tztime.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/cutils') diff --git a/include/cutils/tztime.h b/include/cutils/tztime.h index 9b3ece8..69dbc88 100644 --- a/include/cutils/tztime.h +++ b/include/cutils/tztime.h @@ -27,6 +27,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; -- cgit v1.1 From 414ff7d98ac8d7610a26206335954ad15f43f3ac Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Mon, 18 May 2009 17:07:46 +0200 Subject: Move fdevent from libcutils into adb directory. ADB is the only client of this API, and I intend to modify it extensively to clean its codebase soon. --- include/cutils/fdevent.h | 74 ------------------------------------------------ 1 file changed, 74 deletions(-) delete mode 100644 include/cutils/fdevent.h (limited to 'include/cutils') 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 -- cgit v1.1 From 8f13782e7b4a705484d7f97f07513781b82be0dc Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Wed, 20 May 2009 14:16:34 -0700 Subject: move native_handle stuff from master_gl --- include/cutils/native_handle.h | 47 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'include/cutils') diff --git a/include/cutils/native_handle.h b/include/cutils/native_handle.h index 2b64893..8a44b72 100644 --- a/include/cutils/native_handle.h +++ b/include/cutils/native_handle.h @@ -17,12 +17,55 @@ #ifndef NATIVE_HANDLE_H_ #define NATIVE_HANDLE_H_ +#include + +__BEGIN_DECLS + 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_t + * + * return 0 on success, or a negative error code on failure + * + */ +int native_handle_close(const native_handle_t* h); + + +/* + * native_handle_create + * + * creates a native_handle_t and initializes it. must be destroyed with + * native_handle_delete(). + * + */ +native_handle_t* native_handle_create(int numFds, int numInts); + +/* + * native_handle_delete + * + * 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_t* h); + + +__END_DECLS #endif /* NATIVE_HANDLE_H_ */ -- cgit v1.1 From 92a7541bce0f8ed7649dcbadd83b27d71e4f391f Mon Sep 17 00:00:00 2001 From: Nick Pelly Date: Tue, 19 May 2009 19:22:42 -0700 Subject: 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/cutils/abort_socket.h | 103 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 include/cutils/abort_socket.h (limited to 'include/cutils') 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 +#include + +#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__ -- cgit v1.1 From 3fc51ba17d33c38d327d875d973e787b4dd076b6 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Wed, 20 May 2009 14:16:34 -0700 Subject: move native_handle stuff from master_gl --- include/cutils/native_handle.h | 47 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'include/cutils') diff --git a/include/cutils/native_handle.h b/include/cutils/native_handle.h index 2b64893..8a44b72 100644 --- a/include/cutils/native_handle.h +++ b/include/cutils/native_handle.h @@ -17,12 +17,55 @@ #ifndef NATIVE_HANDLE_H_ #define NATIVE_HANDLE_H_ +#include + +__BEGIN_DECLS + 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_t + * + * return 0 on success, or a negative error code on failure + * + */ +int native_handle_close(const native_handle_t* h); + + +/* + * native_handle_create + * + * creates a native_handle_t and initializes it. must be destroyed with + * native_handle_delete(). + * + */ +native_handle_t* native_handle_create(int numFds, int numInts); + +/* + * native_handle_delete + * + * 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_t* h); + + +__END_DECLS #endif /* NATIVE_HANDLE_H_ */ -- cgit v1.1 From fee77ec093f78c1bb0ce85aa16d7ee8e8fa06f8a Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Thu, 21 May 2009 13:08:39 -0700 Subject: don't use cdefs.h as it breaks the windows build. --- include/cutils/native_handle.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'include/cutils') diff --git a/include/cutils/native_handle.h b/include/cutils/native_handle.h index 8a44b72..89d6b65 100644 --- a/include/cutils/native_handle.h +++ b/include/cutils/native_handle.h @@ -17,9 +17,9 @@ #ifndef NATIVE_HANDLE_H_ #define NATIVE_HANDLE_H_ -#include - -__BEGIN_DECLS +#ifdef __cplusplus +extern "C" { +#endif typedef struct { @@ -66,6 +66,8 @@ native_handle_t* native_handle_create(int numFds, int numInts); int native_handle_delete(native_handle_t* h); -__END_DECLS +#ifdef __cplusplus +} +#endif #endif /* NATIVE_HANDLE_H_ */ -- cgit v1.1