mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-02 02:18:31 +00:00
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r182810 | russell | 2009-03-17 21:09:13 -0500 (Tue, 17 Mar 2009) | 44 lines Fix cases where the internal poll() was not being used when it needed to be. We have seen a number of problems caused by poll() not working properly on Mac OSX. If you search around, you'll find a number of references to using select() instead of poll() to work around these issues. In Asterisk, we've had poll.c which implements poll() using select() internally. However, we were still getting reports of problems. vadim investigated a bit and realized that at least on his system, even though we were compiling in poll.o, the system poll() was still being used. So, the primary purpose of this patch is to ensure that we're using the internal poll() when we want it to be used. The changes are: 1) Remove logic for when internal poll should be used from the Makefile. Instead, put it in the configure script. The logic in the configure script is the same as it was in the Makefile. Ideally, we would have a functionality test for the problem, but that's not actually possible, since we would have to be able to run an application on the _target_ system to test poll() behavior. 2) Always include poll.o in the build, but it will be empty if AST_POLL_COMPAT is not defined. 3) Change uses of poll() throughout the source tree to ast_poll(). I feel that it is good practice to give the API call a new name when we are changing its behavior and not using the system version directly in all cases. So, normally, ast_poll() is just redefined to poll(). On systems where AST_POLL_COMPAT is defined, ast_poll() is redefined to ast_internal_poll(). 4) Change poll() in main/poll.c to be ast_internal_poll(). It's worth noting that any code that still uses poll() directly will work fine (if they worked fine before). So, for example, out of tree modules that are using poll() will not stop working or anything. However, for modules to work properly on Mac OSX, ast_poll() needs to be used. (closes issue #13404) Reported by: agalbraith Tested by: russell, vadim http://reviewboard.digium.com/r/198/ ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@182847 65c4cc65-6c06-0410-ace0-fbb531ad65f3
147 lines
4.0 KiB
C
147 lines
4.0 KiB
C
/*
|
|
* Asterisk -- An open source telephony toolkit.
|
|
*
|
|
* Copyright (C) 1999 - 2005, Digium, Inc.
|
|
*
|
|
* Mark Spencer <markster@digium.com>
|
|
*
|
|
* See http://www.asterisk.org for more information about
|
|
* the Asterisk project. Please do not directly contact
|
|
* any of the maintainers of this project for assistance;
|
|
* the project provides a web site, mailing lists and IRC
|
|
* channels for your use.
|
|
*
|
|
* This program is free software, distributed under the terms of
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
* at the top of the source tree.
|
|
*/
|
|
|
|
/*! \file
|
|
* \brief I/O Management (derived from Cheops-NG)
|
|
*/
|
|
|
|
#ifndef _ASTERISK_IO_H
|
|
#define _ASTERISK_IO_H
|
|
|
|
#include "asterisk/poll-compat.h"
|
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
extern "C" {
|
|
#endif
|
|
|
|
/*! Input ready */
|
|
#define AST_IO_IN POLLIN
|
|
/*! Output ready */
|
|
#define AST_IO_OUT POLLOUT
|
|
/*! Priority input ready */
|
|
#define AST_IO_PRI POLLPRI
|
|
|
|
/* Implicitly polled for */
|
|
/*! Error condition (errno or getsockopt) */
|
|
#define AST_IO_ERR POLLERR
|
|
/*! Hangup */
|
|
#define AST_IO_HUP POLLHUP
|
|
/*! Invalid fd */
|
|
#define AST_IO_NVAL POLLNVAL
|
|
|
|
/*! \brief
|
|
* An Asterisk IO callback takes its id, a file descriptor, list of events, and
|
|
* callback data as arguments and returns 0 if it should not be
|
|
* run again, or non-zero if it should be run again.
|
|
*/
|
|
|
|
struct io_context;
|
|
|
|
/*!
|
|
* \brief Creates a context
|
|
* Create a context for I/O operations
|
|
* Basically mallocs an IO structure and sets up some default values.
|
|
* \return an allocated io_context structure
|
|
*/
|
|
struct io_context *io_context_create(void);
|
|
|
|
/*!
|
|
* \brief Destroys a context
|
|
* \param ioc structure to destroy
|
|
* Destroy a context for I/O operations
|
|
* Frees all memory associated with the given io_context structure along with the structure itself
|
|
*/
|
|
void io_context_destroy(struct io_context *ioc);
|
|
|
|
typedef int (*ast_io_cb)(int *id, int fd, short events, void *cbdata);
|
|
#define AST_IO_CB(a) ((ast_io_cb)(a))
|
|
|
|
/*!
|
|
* \brief Adds an IO context
|
|
* \param ioc which context to use
|
|
* \param fd which fd to monitor
|
|
* \param callback callback function to run
|
|
* \param events event mask of events to wait for
|
|
* \param data data to pass to the callback
|
|
* Watch for any of revents activites on fd, calling callback with data as
|
|
* callback data.
|
|
* \retval a pointer to ID of the IO event
|
|
* \retval NULL on failure
|
|
*/
|
|
int *ast_io_add(struct io_context *ioc, int fd, ast_io_cb callback, short events, void *data);
|
|
|
|
/*!
|
|
* \brief Changes an IO handler
|
|
* \param ioc which context to use
|
|
* \param id
|
|
* \param fd the fd you wish it to contain now
|
|
* \param callback new callback function
|
|
* \param events event mask to wait for
|
|
* \param data data to pass to the callback function
|
|
* Change an I/O handler, updating fd if > -1, callback if non-null,
|
|
* and revents if >-1, and data if non-null.
|
|
* \retval a pointer to the ID of the IO event
|
|
* \retval NULL on failure
|
|
*/
|
|
int *ast_io_change(struct io_context *ioc, int *id, int fd, ast_io_cb callback, short events, void *data);
|
|
|
|
/*!
|
|
* \brief Removes an IO context
|
|
* \param ioc which io_context to remove it from
|
|
* \param id which ID to remove
|
|
* Remove an I/O id from consideration
|
|
* \retval 0 on success
|
|
* \retval -1 on failure
|
|
*/
|
|
int ast_io_remove(struct io_context *ioc, int *id);
|
|
|
|
/*!
|
|
* \brief Waits for IO
|
|
* \param ioc which context to act upon
|
|
* \param howlong how many milliseconds to wait
|
|
* Wait for I/O to happen, returning after
|
|
* howlong milliseconds, and after processing
|
|
* any necessary I/O.
|
|
* \return he number of I/O events which took place.
|
|
*/
|
|
int ast_io_wait(struct io_context *ioc, int howlong);
|
|
|
|
/*!
|
|
* \brief Dumps the IO array.
|
|
* Debugging: Dump everything in the I/O array
|
|
*/
|
|
void ast_io_dump(struct io_context *ioc);
|
|
|
|
/*! Set fd into non-echoing mode (if fd is a tty) */
|
|
|
|
int ast_hide_password(int fd);
|
|
|
|
/*!
|
|
* \brief Restores TTY mode.
|
|
* Call with result from previous ast_hide_password
|
|
*/
|
|
int ast_restore_tty(int fd, int oldstatus);
|
|
|
|
int ast_get_termcols(int fd);
|
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
}
|
|
#endif
|
|
|
|
#endif /* _ASTERISK_IO_H */
|