Collaboration diagram for Network Routines:
| #define SWITCH_INET AF_INET |
Not all platforms have these defined, so we'll define them here The default values come from FreeBSD 4.1.1
Definition at line 1044 of file switch_apr.h.
| #define SWITCH_SO_DEBUG 4 |
Definition at line 1030 of file switch_apr.h.
| #define SWITCH_SO_DISCONNECTED 256 |
Definition at line 1035 of file switch_apr.h.
| #define SWITCH_SO_KEEPALIVE 2 |
Definition at line 1029 of file switch_apr.h.
| #define SWITCH_SO_LINGER 1 |
Definition at line 1028 of file switch_apr.h.
| #define SWITCH_SO_NONBLOCK 8 |
Definition at line 1031 of file switch_apr.h.
Referenced by do_flush(), init_nat_monitor(), switch_rtp_clear_flag(), switch_rtp_set_flag(), switch_rtp_set_local_address(), switch_rtp_udptl_mode(), and switch_stun_lookup().
| #define SWITCH_SO_RCVBUF 128 |
Definition at line 1034 of file switch_apr.h.
| #define SWITCH_SO_REUSEADDR 16 |
Definition at line 1032 of file switch_apr.h.
Referenced by enable_local_rtcp_socket(), init_nat_monitor(), and switch_rtp_set_local_address().
| #define SWITCH_SO_SNDBUF 64 |
Definition at line 1033 of file switch_apr.h.
| #define SWITCH_SO_TCP_NODELAY 512 |
Definition at line 1036 of file switch_apr.h.
| #define SWITCH_UNSPEC 0 |
Let the system decide which address family to use
Definition at line 1052 of file switch_apr.h.
Referenced by enable_local_rtcp_socket(), enable_remote_rtcp_socket(), init_nat_monitor(), switch_ivr_activate_unicast(), switch_rtp_activate_stun_ping(), switch_rtp_set_local_address(), switch_rtp_set_remote_address(), switch_stun_host_lookup(), and switch_stun_lookup().
| typedef struct apr_sockaddr_t switch_sockaddr_t |
Freeswitch's socket address type, used to ensure protocol independence
Definition at line 1059 of file switch_apr.h.
| typedef struct apr_socket_t switch_socket_t |
A structure to represent sockets
Definition at line 1056 of file switch_apr.h.
| SWITCH_SHUTDOWN_READ | no longer allow read request |
| SWITCH_SHUTDOWN_WRITE | no longer allow write requests |
| SWITCH_SHUTDOWN_READWRITE | no longer allow read or write requests |
Definition at line 1061 of file switch_apr.h.
01061 { 01062 SWITCH_SHUTDOWN_READ, /**< no longer allow read request */ 01063 SWITCH_SHUTDOWN_WRITE, /**< no longer allow write requests */ 01064 SWITCH_SHUTDOWN_READWRITE /**< no longer allow read or write requests */ 01065 } switch_shutdown_how_e;
| const char* switch_get_addr | ( | char * | buf, | |
| switch_size_t | len, | |||
| switch_sockaddr_t * | in | |||
| ) |
Definition at line 829 of file switch_apr.c.
References get_addr(), get_addr6(), and SWITCH_BLANK_STRING.
Referenced by enable_local_rtcp_socket(), enable_remote_rtcp_socket(), handle_ice(), rtp_common_read(), rtp_common_write(), and switch_stun_host_lookup().
00830 { 00831 if (!in) { 00832 return SWITCH_BLANK_STRING; 00833 } 00834 00835 if (in->family == AF_INET) { 00836 return get_addr(buf, len, (struct sockaddr *) &in->sa, in->salen); 00837 } 00838 00839 return get_addr6(buf, len, (struct sockaddr_in6 *) &in->sa, in->salen); 00840 }
| switch_status_t switch_mcast_hops | ( | switch_socket_t * | sock, | |
| uint8_t | ttl | |||
| ) |
Set the Multicast Time to Live (ttl) for a multicast transmission.
| sock | The socket to set the multicast ttl | |
| ttl | Time to live to Assign. 0-255, default=1 |
Definition at line 817 of file switch_apr.c.
| switch_status_t switch_mcast_join | ( | switch_socket_t * | sock, | |
| switch_sockaddr_t * | join, | |||
| switch_sockaddr_t * | iface, | |||
| switch_sockaddr_t * | source | |||
| ) |
Join a Multicast Group
| sock | The socket to join a multicast group | |
| join | The address of the multicast group to join | |
| iface | Address of the interface to use. If NULL is passed, the default multicast interface will be used. (OS Dependent) | |
| source | Source Address to accept transmissions from (non-NULL implies Source-Specific Multicast) |
Definition at line 812 of file switch_apr.c.
Referenced by init_nat_monitor().
| switch_status_t switch_mcast_loopback | ( | switch_socket_t * | sock, | |
| uint8_t | opt | |||
| ) |
| switch_status_t switch_sockaddr_create | ( | switch_sockaddr_t ** | sa, | |
| switch_memory_pool_t * | pool | |||
| ) |
Definition at line 764 of file switch_apr.c.
References switch_assert, and SWITCH_STATUS_SUCCESS.
Referenced by switch_rtp_create().
00765 { 00766 switch_sockaddr_t *new_sa; 00767 unsigned short family = APR_INET; 00768 00769 new_sa = apr_pcalloc(pool, sizeof(apr_sockaddr_t)); 00770 switch_assert(new_sa); 00771 new_sa->pool = pool; 00772 memset(new_sa, 0, sizeof(*new_sa)); 00773 00774 new_sa->family = family; 00775 new_sa->sa.sin.sin_family = family; 00776 00777 new_sa->salen = sizeof(struct sockaddr_in); 00778 new_sa->addr_str_len = 16; 00779 new_sa->ipaddr_ptr = &(new_sa->sa.sin.sin_addr); 00780 new_sa->ipaddr_len = sizeof(struct in_addr); 00781 00782 *sa = new_sa; 00783 return SWITCH_STATUS_SUCCESS; 00784 }
| int switch_sockaddr_equal | ( | const switch_sockaddr_t * | sa1, | |
| const switch_sockaddr_t * | sa2 | |||
| ) |
| int32_t switch_sockaddr_get_family | ( | switch_sockaddr_t * | sa | ) |
Definition at line 847 of file switch_apr.c.
Referenced by enable_local_rtcp_socket(), enable_remote_rtcp_socket(), switch_rtp_set_local_address(), and switch_rtp_set_remote_address().
| uint16_t switch_sockaddr_get_port | ( | switch_sockaddr_t * | sa | ) |
Definition at line 842 of file switch_apr.c.
Referenced by enable_local_rtcp_socket(), handle_ice(), rtp_common_read(), and rtp_common_write().
| switch_status_t switch_sockaddr_info_get | ( | switch_sockaddr_t ** | sa, | |
| const char * | hostname, | |||
| int32_t | family, | |||
| switch_port_t | port, | |||
| int32_t | flags, | |||
| switch_memory_pool_t * | pool | |||
| ) |
Create apr_sockaddr_t from hostname, address family, and port.
| sa | The new apr_sockaddr_t. | |
| hostname | The hostname or numeric address string to resolve/parse, or NULL to build an address that corresponds to 0.0.0.0 or :: | |
| family | The address family to use, or SWITCH_UNSPEC if the system should decide. | |
| port | The port number. | |
| flags | Special processing flags:
APR_IPV4_ADDR_OK first query for IPv4 addresses; only look
for IPv6 addresses if the first query failed;
only valid if family is APR_UNSPEC and hostname
isn't NULL; mutually exclusive with
APR_IPV6_ADDR_OK
APR_IPV6_ADDR_OK first query for IPv6 addresses; only look
for IPv4 addresses if the first query failed;
only valid if family is APR_UNSPEC and hostname
isn't NULL and APR_HAVE_IPV6; mutually exclusive
with APR_IPV4_ADDR_OK
| |
| pool | The pool for the apr_sockaddr_t and associated storage. |
Definition at line 786 of file switch_apr.c.
Referenced by enable_local_rtcp_socket(), enable_remote_rtcp_socket(), init_nat_monitor(), switch_ivr_activate_unicast(), switch_rtp_activate_stun_ping(), switch_rtp_set_local_address(), switch_rtp_set_remote_address(), switch_stun_host_lookup(), and switch_stun_lookup().
00788 { 00789 return apr_sockaddr_info_get(sa, hostname, family, port, flags, pool); 00790 }
| switch_status_t switch_sockaddr_ip_get | ( | char ** | addr, | |
| switch_sockaddr_t * | sa | |||
| ) |
| switch_status_t switch_socket_accept | ( | switch_socket_t ** | new_sock, | |
| switch_socket_t * | sock, | |||
| switch_memory_pool_t * | pool | |||
| ) |
Accept a new connection request
| new_sock | A copy of the socket that is connected to the socket that made the connection request. This is the socket which should be used for all future communication. | |
| sock | The socket we are listening on. | |
| pool | The pool for the new socket. |
Definition at line 698 of file switch_apr.c.
00699 { 00700 return apr_socket_accept(new_sock, sock, pool); 00701 }
| switch_status_t switch_socket_atmark | ( | switch_socket_t * | sock, | |
| int * | atmark | |||
| ) |
| switch_status_t switch_socket_bind | ( | switch_socket_t * | sock, | |
| switch_sockaddr_t * | sa | |||
| ) |
Bind the socket to its associated port
| sock | The socket to bind | |
| sa | The socket address to bind to |
Definition at line 688 of file switch_apr.c.
Referenced by enable_local_rtcp_socket(), init_nat_monitor(), switch_ivr_activate_unicast(), switch_rtp_set_local_address(), and switch_stun_lookup().
| switch_status_t switch_socket_close | ( | switch_socket_t * | sock | ) |
Close a socket.
| sock | The socket to close |
Definition at line 683 of file switch_apr.c.
Referenced by enable_local_rtcp_socket(), enable_remote_rtcp_socket(), init_nat_monitor(), switch_ivr_deactivate_unicast(), switch_rtp_destroy(), switch_rtp_set_local_address(), switch_rtp_set_remote_address(), switch_rtp_udptl_mode(), and switch_stun_lookup().
| switch_status_t switch_socket_connect | ( | switch_socket_t * | sock, | |
| switch_sockaddr_t * | sa | |||
| ) |
Issue a connection request to a socket either on the same machine or a different one.
| sock | The socket we wish to use for our side of the connection | |
| sa | The address of the machine we wish to connect to. |
Definition at line 703 of file switch_apr.c.
| switch_status_t switch_socket_create | ( | switch_socket_t ** | new_sock, | |
| int | family, | |||
| int | type, | |||
| int | protocol, | |||
| switch_memory_pool_t * | pool | |||
| ) |
Create a socket.
| new_sock | The new socket that has been set up. | |
| family | The address family of the socket (e.g., SWITCH_INET). | |
| type | The type of the socket (e.g., SOCK_STREAM). | |
| protocol | The protocol of the socket (e.g., SWITCH_PROTO_TCP). | |
| pool | The pool to use |
Definition at line 673 of file switch_apr.c.
Referenced by enable_local_rtcp_socket(), enable_remote_rtcp_socket(), init_nat_monitor(), switch_ivr_activate_unicast(), switch_rtp_set_local_address(), switch_rtp_set_remote_address(), and switch_stun_lookup().
00674 { 00675 return apr_socket_create(new_sock, family, type, protocol, pool); 00676 }
| switch_status_t switch_socket_listen | ( | switch_socket_t * | sock, | |
| int32_t | backlog | |||
| ) |
Listen to a bound socket for connections.
| sock | The socket to listen on | |
| backlog | The number of outstanding connections allowed in the sockets listen queue. If this value is less than zero, the listen queue size is set to zero. |
Definition at line 693 of file switch_apr.c.
| switch_status_t switch_socket_opt_set | ( | switch_socket_t * | sock, | |
| int32_t | opt, | |||
| int32_t | on | |||
| ) |
Setup socket options for the specified socket
| sock | The socket to set up. | |
| opt | The option we would like to configure. One of:
APR_SO_DEBUG -- turn on debugging information
APR_SO_KEEPALIVE -- keep connections active
APR_SO_LINGER -- lingers on close if data is present
APR_SO_NONBLOCK -- Turns blocking on/off for socket
When this option is enabled, use
the APR_STATUS_IS_EAGAIN() macro to
see if a send or receive function
could not transfer data without
blocking.
APR_SO_REUSEADDR -- The rules used in validating addresses
supplied to bind should allow reuse
of local addresses.
APR_SO_SNDBUF -- Set the SendBufferSize
APR_SO_RCVBUF -- Set the ReceiveBufferSize
| |
| on | Value for the option. |
Definition at line 792 of file switch_apr.c.
Referenced by do_flush(), enable_local_rtcp_socket(), init_nat_monitor(), switch_rtp_clear_flag(), switch_rtp_set_flag(), switch_rtp_set_local_address(), switch_rtp_udptl_mode(), and switch_stun_lookup().
| switch_status_t switch_socket_recv | ( | switch_socket_t * | sock, | |
| char * | buf, | |||
| switch_size_t * | len | |||
| ) |
Read data from a network.
| sock | The socket to read the data from. | |
| buf | The buffer to store the data in. | |
| len | On entry, the number of bytes to receive; on exit, the number of bytes received. |
This functions acts like a blocking read by default. To change this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK socket option. The number of bytes actually received is stored in argument 3.
APR_EINTR is never returned.
Definition at line 751 of file switch_apr.c.
References SWITCH_STATUS_BREAK.
Referenced by unicast_thread_run().
00752 { 00753 switch_status_t r; 00754 00755 r = apr_socket_recv(sock, buf, len); 00756 00757 if (r == 35 || r == 730035) { 00758 r = SWITCH_STATUS_BREAK; 00759 } 00760 00761 return r; 00762 }
| switch_status_t switch_socket_recvfrom | ( | switch_sockaddr_t * | from, | |
| switch_socket_t * | sock, | |||
| int32_t | flags, | |||
| char * | buf, | |||
| size_t * | len | |||
| ) |
| from | The apr_sockaddr_t to fill in the recipient info | |
| sock | The socket to use | |
| flags | The flags to use | |
| buf | The buffer to use | |
| len | The length of the available buffer |
Definition at line 857 of file switch_apr.c.
References SWITCH_STATUS_BREAK, and SWITCH_STATUS_GENERR.
Referenced by do_flush(), read_rtcp_packet(), read_rtp_packet(), switch_nat_multicast_runtime(), switch_rtp_set_local_address(), and switch_stun_lookup().
00858 { 00859 apr_status_t r = SWITCH_STATUS_GENERR; 00860 00861 if (from && sock && (r = apr_socket_recvfrom(from, sock, flags, buf, len)) == APR_SUCCESS) { 00862 from->port = ntohs(from->sa.sin.sin_port); 00863 /* from->ipaddr_ptr = &(from->sa.sin.sin_addr); 00864 * from->ipaddr_ptr = inet_ntoa(from->sa.sin.sin_addr); 00865 */ 00866 } 00867 00868 if (r == 35 || r == 730035) { 00869 r = SWITCH_STATUS_BREAK; 00870 } 00871 00872 return r; 00873 }
| switch_status_t switch_socket_send | ( | switch_socket_t * | sock, | |
| const char * | buf, | |||
| switch_size_t * | len | |||
| ) |
Send data over a network.
| sock | The socket to send the data over. | |
| buf | The buffer which contains the data to be sent. | |
| len | On entry, the number of bytes to send; on exit, the number of bytes sent. |
This functions acts like a blocking write by default. To change this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK socket option.
APR_EINTR is never returned.
Definition at line 708 of file switch_apr.c.
References SWITCH_STATUS_BREAK, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_yield.
00709 { 00710 switch_status_t status = SWITCH_STATUS_SUCCESS; 00711 switch_size_t req = *len, wrote = 0, need = *len; 00712 int to_count = 0; 00713 00714 while ((wrote < req && status == SWITCH_STATUS_SUCCESS) || (need == 0 && status == SWITCH_STATUS_BREAK) || status == 730035 || status == 35) { 00715 need = req - wrote; 00716 status = apr_socket_send(sock, buf + wrote, &need); 00717 if (status == SWITCH_STATUS_BREAK || status == 730035 || status == 35) { 00718 if (++to_count > 60000) { 00719 status = SWITCH_STATUS_FALSE; 00720 break; 00721 } 00722 switch_yield(10000); 00723 } else { 00724 to_count = 0; 00725 } 00726 wrote += need; 00727 } 00728 00729 *len = wrote; 00730 return status; 00731 }
| switch_status_t switch_socket_send_nonblock | ( | switch_socket_t * | sock, | |
| const char * | buf, | |||
| switch_size_t * | len | |||
| ) |
Definition at line 733 of file switch_apr.c.
References SWITCH_STATUS_GENERR.
00734 { 00735 if (!sock || !buf || !len) { 00736 return SWITCH_STATUS_GENERR; 00737 } 00738 00739 return apr_socket_send(sock, buf, len); 00740 }
| switch_status_t switch_socket_sendto | ( | switch_socket_t * | sock, | |
| switch_sockaddr_t * | where, | |||
| int32_t | flags, | |||
| const char * | buf, | |||
| switch_size_t * | len | |||
| ) |
| sock | The socket to send from | |
| where | The apr_sockaddr_t describing where to send the data | |
| flags | The flags to use | |
| buf | The data to send | |
| len | The length of the data to send |
Definition at line 742 of file switch_apr.c.
References SWITCH_STATUS_GENERR.
Referenced by do_stun_ping(), handle_ice(), ice_out(), ping_socket(), rtp_common_read(), rtp_common_write(), switch_ivr_park(), switch_rtp_set_local_address(), switch_rtp_write_frame(), switch_rtp_write_manual(), and switch_stun_lookup().
00744 { 00745 if (!where || !buf || !len || !*len) { 00746 return SWITCH_STATUS_GENERR; 00747 } 00748 return apr_socket_sendto(sock, where, flags, buf, len); 00749 }
| switch_status_t switch_socket_shutdown | ( | switch_socket_t * | sock, | |
| switch_shutdown_how_e | how | |||
| ) |
Shutdown either reading, writing, or both sides of a socket.
| sock | The socket to close | |
| how | How to shutdown the socket. One of:
SWITCH_SHUTDOWN_READ no longer allow read requests
SWITCH_SHUTDOWN_WRITE no longer allow write requests
SWITCH_SHUTDOWN_READWRITE no longer allow read or write requests
|
Definition at line 678 of file switch_apr.c.
Referenced by switch_ivr_deactivate_unicast(), switch_rtp_kill_socket(), switch_rtp_udptl_mode(), and switch_stun_lookup().
| switch_status_t switch_socket_timeout_set | ( | switch_socket_t * | sock, | |
| switch_interval_time_t | t | |||
| ) |
Setup socket timeout for the specified socket
| sock | The socket to set up. | |
| t | Value for the timeout.
t > 0 -- read and write calls return APR_TIMEUP if specified time
elapsess with no data read or written
t == 0 -- read and write calls never block
t < 0 -- read and write calls block
|
Definition at line 797 of file switch_apr.c.
1.4.7