FreeSWITCH API Documentation  1.7.0
Macros | Typedefs | Functions
+ Collaboration diagram for Poll Routines:

Macros

#define SWITCH_POLLIN   0x001
 
#define SWITCH_POLLPRI   0x002
 
#define SWITCH_POLLOUT   0x004
 
#define SWITCH_POLLERR   0x010
 
#define SWITCH_POLLHUP   0x020
 
#define SWITCH_POLLNVAL   0x040
 

Typedefs

typedef struct switch_pollfd switch_pollfd_t
 
typedef struct apr_pollset_t switch_pollset_t
 

Functions

switch_status_t switch_pollset_create (switch_pollset_t **pollset, uint32_t size, switch_memory_pool_t *pool, uint32_t flags)
 
switch_status_t switch_pollset_add (switch_pollset_t *pollset, const switch_pollfd_t *descriptor)
 
switch_status_t switch_pollset_remove (switch_pollset_t *pollset, const switch_pollfd_t *descriptor)
 
switch_status_t switch_poll (switch_pollfd_t *aprset, int32_t numsock, int32_t *nsds, switch_interval_time_t timeout)
 
switch_status_t switch_pollset_poll (switch_pollset_t *pollset, switch_interval_time_t timeout, int32_t *num, const switch_pollfd_t **descriptors)
 
switch_status_t switch_socket_create_pollset (switch_pollfd_t **poll, switch_socket_t *sock, int16_t flags, switch_memory_pool_t *pool)
 Create a set of file descriptors to poll from a socket. More...
 
switch_interval_time_t switch_interval_time_from_timeval (struct timeval *tvp)
 
switch_status_t switch_socket_create_pollfd (switch_pollfd_t **pollfd, switch_socket_t *sock, int16_t flags, void *client_data, switch_memory_pool_t *pool)
 Create a pollfd out of a socket. More...
 
switch_status_t switch_match_glob (const char *pattern, switch_array_header_t **result, switch_memory_pool_t *pool)
 
switch_status_t switch_os_sock_get (switch_os_socket_t *thesock, switch_socket_t *sock)
 
switch_status_t switch_os_sock_put (switch_socket_t **sock, switch_os_socket_t *thesock, switch_memory_pool_t *pool)
 
switch_status_t switch_socket_addr_get (switch_sockaddr_t **sa, switch_bool_t remote, switch_socket_t *sock)
 
switch_status_t switch_file_pipe_create (switch_file_t **in, switch_file_t **out, switch_memory_pool_t *pool)
 
switch_status_t switch_file_pipe_timeout_get (switch_file_t *thepipe, switch_interval_time_t *timeout)
 
switch_status_t switch_file_pipe_timeout_set (switch_file_t *thepipe, switch_interval_time_t timeout)
 
switch_status_t switch_thread_exit (switch_thread_t *thd, switch_status_t retval)
 
switch_status_t switch_thread_join (switch_status_t *retval, switch_thread_t *thd)
 
char * switch_strerror (switch_status_t statcode, char *buf, switch_size_t bufsize)
 

Detailed Description

Macro Definition Documentation

#define SWITCH_POLLERR   0x010

Pending error

Definition at line 1324 of file switch_apr.h.

Referenced by enable_local_rtcp_socket(), and switch_rtp_set_local_address().

#define SWITCH_POLLHUP   0x020

Hangup occurred

Definition at line 1325 of file switch_apr.h.

#define SWITCH_POLLIN   0x001

Poll optionsCan read without blocking

Definition at line 1321 of file switch_apr.h.

Referenced by enable_local_rtcp_socket(), and switch_rtp_set_local_address().

#define SWITCH_POLLNVAL   0x040

Descriptior invalid

Definition at line 1326 of file switch_apr.h.

#define SWITCH_POLLOUT   0x004

Can write without blocking

Definition at line 1323 of file switch_apr.h.

#define SWITCH_POLLPRI   0x002

Priority data available

Definition at line 1322 of file switch_apr.h.

Typedef Documentation

Poll descriptor set.

Definition at line 1313 of file switch_apr.h.

typedef struct apr_pollset_t switch_pollset_t

Opaque structure used for pollset API

Definition at line 1316 of file switch_apr.h.

Function Documentation

switch_status_t switch_file_pipe_create ( switch_file_t **  in,
switch_file_t **  out,
switch_memory_pool_t pool 
)

Create an anonymous pipe.

Parameters
inThe file descriptor to use as input to the pipe.
outThe file descriptor to use as output from the pipe.
poolThe pool to operate on.

Definition at line 1213 of file switch_apr.c.

1214 {
1215  return apr_file_pipe_create((apr_file_t **) in, (apr_file_t **) out, pool);
1216 }
switch_memory_pool_t * pool
switch_byte_t in
switch_status_t switch_file_pipe_timeout_get ( switch_file_t thepipe,
switch_interval_time_t timeout 
)

Get the timeout value for a pipe or manipulate the blocking state.

Parameters
thepipeThe pipe we are getting a timeout for.
timeoutThe current timeout value in microseconds.

Definition at line 1223 of file switch_apr.c.

1224 {
1225  return apr_file_pipe_timeout_get((apr_file_t *) thepipe, (apr_interval_time_t *) timeout);
1226 }
switch_status_t switch_file_pipe_timeout_set ( switch_file_t thepipe,
switch_interval_time_t  timeout 
)

Set the timeout value for a pipe or manipulate the blocking state.

Parameters
thepipeThe pipe we are setting a timeout on.
timeoutThe timeout value in microseconds. Values < 0 mean wait forever, 0 means do not wait at all.

Definition at line 1234 of file switch_apr.c.

1235 {
1236  return apr_file_pipe_timeout_set((apr_file_t *) thepipe, (apr_interval_time_t) timeout);
1237 }
switch_interval_time_t switch_interval_time_from_timeval ( struct timeval *  tvp)

Definition at line 682 of file switch_apr.c.

683 {
684  return ((switch_interval_time_t)tvp->tv_sec * 1000000) + tvp->tv_usec / 1000;
685 }
int64_t switch_interval_time_t
Definition: switch_apr.h:191
switch_status_t switch_match_glob ( const char *  pattern,
switch_array_header_t **  result,
switch_memory_pool_t pool 
)

Definition at line 1202 of file switch_apr.c.

1203 {
1204  return apr_match_glob(pattern, (apr_array_header_t **) result, pool);
1205 }
switch_memory_pool_t * pool
switch_status_t switch_os_sock_get ( switch_os_socket_t thesock,
switch_socket_t sock 
)

Definition at line 689 of file switch_apr.c.

690 {
691  return apr_os_sock_get(thesock, sock);
692 }
switch_status_t switch_os_sock_put ( switch_socket_t **  sock,
switch_os_socket_t thesock,
switch_memory_pool_t pool 
)

Definition at line 694 of file switch_apr.c.

695 {
696  return apr_os_sock_put(sock, thesock, pool);
697 }
switch_memory_pool_t * pool
switch_status_t switch_poll ( switch_pollfd_t aprset,
int32_t  numsock,
int32_t *  nsds,
switch_interval_time_t  timeout 
)

Poll the sockets in the poll structure

Parameters
aprsetThe poll structure we will be using.
numsockThe number of sockets we are polling
nsdsThe number of sockets signalled.
timeoutThe amount of time in microseconds to wait. This is a maximum, not a minimum. If a socket is signalled, we will wake up before this time. A negative number means wait until a socket is signalled.
Remarks
The number of sockets signalled is returned in the third argument. This is a blocking call, and it will not return until either a socket has been signalled, or the timeout has expired.

Definition at line 1015 of file switch_apr.c.

References SWITCH_STATUS_FALSE, SWITCH_STATUS_GENERR, and SWITCH_STATUS_TIMEOUT.

Referenced by read_rtp_packet(), rtp_common_read(), and switch_socket_waitfor().

1016 {
1017  apr_status_t st = SWITCH_STATUS_FALSE;
1018 
1019  if (aprset) {
1020  st = apr_poll((apr_pollfd_t *) aprset, numsock, nsds, timeout);
1021 
1022  if (numsock == 1 && ((aprset[0].rtnevents & APR_POLLERR) || (aprset[0].rtnevents & APR_POLLHUP) || (aprset[0].rtnevents & APR_POLLNVAL))) {
1023  st = SWITCH_STATUS_GENERR;
1024  } else if (st == APR_TIMEUP) {
1025  st = SWITCH_STATUS_TIMEOUT;
1026  }
1027  }
1028 
1029  return st;
1030 }
switch_status_t switch_pollset_add ( switch_pollset_t pollset,
const switch_pollfd_t descriptor 
)

Add a socket or file descriptor to a pollset

Parameters
pollsetThe pollset to which to add the descriptor
descriptorThe descriptor to add
Remarks
If you set client_data in the descriptor, that value will be returned in the client_data field whenever this descriptor is signalled in apr_pollset_poll().
If the pollset has been created with APR_POLLSET_THREADSAFE and thread T1 is blocked in a call to apr_pollset_poll() for this same pollset that is being modified via apr_pollset_add() in thread T2, the currently executing apr_pollset_poll() call in T1 will either: (1) automatically include the newly added descriptor in the set of descriptors it is watching or (2) return immediately with APR_EINTR. Option (1) is recommended, but option (2) is allowed for implementations where option (1) is impossible or impractical.

Definition at line 961 of file switch_apr.c.

References SWITCH_STATUS_FALSE.

Referenced by switch_socket_create_pollset().

962 {
963  if (!pollset || !descriptor) {
964  return SWITCH_STATUS_FALSE;
965  }
966 
967  return apr_pollset_add((apr_pollset_t *) pollset, (const apr_pollfd_t *) descriptor);
968 }
switch_status_t switch_pollset_create ( switch_pollset_t **  pollset,
uint32_t  size,
switch_memory_pool_t pool,
uint32_t  flags 
)

Setup a pollset object

Parameters
pollsetThe pointer in which to return the newly created object
sizeThe maximum number of descriptors that this pollset can hold
poolThe pool from which to allocate the pollset
flagsOptional flags to modify the operation of the pollset.
Remarks
If flags equals APR_POLLSET_THREADSAFE, then a pollset is created on which it is safe to make concurrent calls to apr_pollset_add(), apr_pollset_remove() and apr_pollset_poll() from separate threads. This feature is only supported on some platforms; the apr_pollset_create() call will fail with APR_ENOTIMPL on platforms where it is not supported.

Definition at line 956 of file switch_apr.c.

Referenced by switch_socket_create_pollset().

957 {
958  return apr_pollset_create(pollset, size, pool, flags);
959 }
switch_memory_pool_t * pool
switch_status_t switch_pollset_poll ( switch_pollset_t pollset,
switch_interval_time_t  timeout,
int32_t *  num,
const switch_pollfd_t **  descriptors 
)

Block for activity on the descriptor(s) in a pollset

Parameters
pollsetThe pollset to use
timeoutTimeout in microseconds
numNumber of signalled descriptors (output parameter)
descriptorsArray of signalled descriptors (output parameter)

Definition at line 1000 of file switch_apr.c.

References SWITCH_STATUS_FALSE, and SWITCH_STATUS_TIMEOUT.

1001 {
1002  apr_status_t st = SWITCH_STATUS_FALSE;
1003 
1004  if (pollset) {
1005  st = apr_pollset_poll((apr_pollset_t *) pollset, timeout, num, (const apr_pollfd_t **) descriptors);
1006 
1007  if (st == APR_TIMEUP) {
1008  st = SWITCH_STATUS_TIMEOUT;
1009  }
1010  }
1011 
1012  return st;
1013 }
switch_status_t switch_pollset_remove ( switch_pollset_t pollset,
const switch_pollfd_t descriptor 
)

Remove a descriptor from a pollset

Parameters
pollsetThe pollset from which to remove the descriptor
descriptorThe descriptor to remove
Remarks
If the pollset has been created with APR_POLLSET_THREADSAFE and thread T1 is blocked in a call to apr_pollset_poll() for this same pollset that is being modified via apr_pollset_remove() in thread T2, the currently executing apr_pollset_poll() call in T1 will either: (1) automatically exclude the newly added descriptor in the set of descriptors it is watching or (2) return immediately with APR_EINTR. Option (1) is recommended, but option (2) is allowed for implementations where option (1) is impossible or impractical.

Definition at line 970 of file switch_apr.c.

References SWITCH_STATUS_FALSE.

971 {
972  if (!pollset || !descriptor) {
973  return SWITCH_STATUS_FALSE;
974  }
975 
976  return apr_pollset_remove((apr_pollset_t *) pollset, (const apr_pollfd_t *) descriptor);
977 }
switch_status_t switch_socket_addr_get ( switch_sockaddr_t **  sa,
switch_bool_t  remote,
switch_socket_t sock 
)

Definition at line 699 of file switch_apr.c.

700 {
701  return apr_socket_addr_get(sa, (apr_interface_e) remote, sock);
702 }
switch_status_t switch_socket_create_pollfd ( switch_pollfd_t **  pollfd,
switch_socket_t sock,
int16_t  flags,
void *  client_data,
switch_memory_pool_t pool 
)

Create a pollfd out of a socket.

Parameters
pollfdthe pollfd to create
sockthe socket to add
flagsthe flags to modify the behaviour
client_datacustom user data
poolthe memory pool to use
Returns
SWITCH_STATUS_SUCCESS when successful

Definition at line 979 of file switch_apr.c.

References memset(), SWITCH_STATUS_FALSE, SWITCH_STATUS_MEMERR, and SWITCH_STATUS_SUCCESS.

Referenced by switch_socket_create_pollset().

980 {
981  if (!pollfd || !sock) {
982  return SWITCH_STATUS_FALSE;
983  }
984 
985  if ((*pollfd = (switch_pollfd_t*)apr_palloc(pool, sizeof(switch_pollfd_t))) == 0) {
986  return SWITCH_STATUS_MEMERR;
987  }
988 
989  memset(*pollfd, 0, sizeof(switch_pollfd_t));
990 
991  (*pollfd)->desc_type = (switch_pollset_type_t) APR_POLL_SOCKET;
992  (*pollfd)->reqevents = flags;
993  (*pollfd)->desc.s = sock;
994  (*pollfd)->client_data = client_data;
995 
996  return SWITCH_STATUS_SUCCESS;
997 }
switch_memory_pool_t * pool
switch_pollset_type_t
Definition: switch_apr.h:1283
memset(buf, 0, buflen)
switch_status_t switch_socket_create_pollset ( switch_pollfd_t **  poll,
switch_socket_t sock,
int16_t  flags,
switch_memory_pool_t pool 
)

Create a set of file descriptors to poll from a socket.

Parameters
pollthe polfd to create
sockthe socket to add
flagsthe flags to modify the behaviour
poolthe memory pool to use
Returns
SWITCH_STATUS_SUCCESS when successful

Definition at line 1032 of file switch_apr.c.

References switch_pollset_add(), switch_pollset_create(), switch_socket_create_pollfd(), SWITCH_STATUS_GENERR, and SWITCH_STATUS_SUCCESS.

Referenced by enable_local_rtcp_socket(), and switch_rtp_set_local_address().

1033 {
1034  switch_pollset_t *pollset;
1035 
1036  if (switch_pollset_create(&pollset, 1, pool, 0) != SWITCH_STATUS_SUCCESS) {
1037  return SWITCH_STATUS_GENERR;
1038  }
1039 
1040  if (switch_socket_create_pollfd(poll, sock, flags, sock, pool) != SWITCH_STATUS_SUCCESS) {
1041  return SWITCH_STATUS_GENERR;
1042  }
1043 
1044  if (switch_pollset_add(pollset, *poll) != SWITCH_STATUS_SUCCESS) {
1045  return SWITCH_STATUS_GENERR;
1046  }
1047 
1048  return SWITCH_STATUS_SUCCESS;
1049 }
switch_memory_pool_t * pool
switch_status_t switch_pollset_add(switch_pollset_t *pollset, const switch_pollfd_t *descriptor)
Definition: switch_apr.c:961
struct apr_pollset_t switch_pollset_t
Definition: switch_apr.h:1316
switch_status_t switch_socket_create_pollfd(switch_pollfd_t **pollfd, switch_socket_t *sock, int16_t flags, void *client_data, switch_memory_pool_t *pool)
Create a pollfd out of a socket.
Definition: switch_apr.c:979
switch_status_t switch_pollset_create(switch_pollset_t **pollset, uint32_t size, switch_memory_pool_t *pool, uint32_t flags)
Definition: switch_apr.c:956
char* switch_strerror ( switch_status_t  statcode,
char *  buf,
switch_size_t  bufsize 
)

Return a human readable string describing the specified error.

Parameters
statcodeThe error code the get a string for.
bufA buffer to hold the error string. Size of the buffer to hold the string.

Definition at line 1316 of file switch_apr.c.

1317 {
1318  return apr_strerror(statcode, buf, bufsize);
1319 }
switch_byte_t switch_byte_t * buf
switch_status_t switch_thread_exit ( switch_thread_t thd,
switch_status_t  retval 
)

stop the current thread

Parameters
thdThe thread to stop
retvalThe return value to pass back to any thread that cares

Definition at line 1245 of file switch_apr.c.

Referenced by switch_loadable_module_exec().

1246 {
1247  return apr_thread_exit((apr_thread_t *) thd, retval);
1248 }
switch_status_t switch_thread_join ( switch_status_t retval,
switch_thread_t thd 
)

block until the desired thread stops executing.

Parameters
retvalThe return value from the dead thread.
thdThe thread to join

Definition at line 1255 of file switch_apr.c.

References SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, switch_log_printf(), and SWITCH_STATUS_FALSE.

Referenced by do_shutdown(), record_callback(), speech_callback(), switch_core_media_bug_close(), switch_core_media_deactivate_rtp(), switch_core_media_set_video_file(), switch_core_memory_stop(), switch_core_sqldb_stop(), switch_event_shutdown(), switch_ivr_deactivate_unicast(), switch_ivr_enterprise_originate(), switch_ivr_originate(), switch_loadable_module_shutdown(), switch_log_shutdown(), switch_nat_thread_stop(), switch_scheduler_task_thread_stop(), and switch_sql_queue_manager_stop().

1256 {
1257  if ( !thd ) {
1258  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERROR: Attempting to join thread that does not exist\n");
1259  return SWITCH_STATUS_FALSE;
1260  }
1261 
1262  return apr_thread_join((apr_status_t *) retval, (apr_thread_t *) thd);
1263 }
#define SWITCH_CHANNEL_LOG
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.