RTS API Documentation  1.10.11
Modules | Macros | Typedefs | Enumerations | Functions
Network Routines
+ Collaboration diagram for Network Routines:

Modules

 IP Protocol Definitions for use when creating sockets
 

Macros

#define SWITCH_SO_LINGER   1
 
#define SWITCH_SO_KEEPALIVE   2
 
#define SWITCH_SO_DEBUG   4
 
#define SWITCH_SO_NONBLOCK   8
 
#define SWITCH_SO_REUSEADDR   16
 
#define SWITCH_SO_SNDBUF   64
 
#define SWITCH_SO_RCVBUF   128
 
#define SWITCH_SO_DISCONNECTED   256
 
#define SWITCH_SO_TCP_NODELAY   512
 
#define SWITCH_SO_TCP_KEEPIDLE   520
 
#define SWITCH_SO_TCP_KEEPINTVL   530
 
#define SWITCH_SO_IPV6_V6ONLY   16384 /* Don't accept IPv4 connections on an IPv6 listening socket. */
 
#define SWITCH_INET   AF_INET
 
#define SWITCH_INET6   0
 
#define SWITCH_UNSPEC   0
 

Typedefs

typedef struct fspr_socket_t switch_socket_t
 
typedef struct fspr_sockaddr_t switch_sockaddr_t
 

Enumerations

enum  switch_shutdown_how_e { SWITCH_SHUTDOWN_READ, SWITCH_SHUTDOWN_WRITE, SWITCH_SHUTDOWN_READWRITE }
 

Functions

switch_status_t switch_socket_create (switch_socket_t **new_sock, int family, int type, int protocol, switch_memory_pool_t *pool)
 
switch_status_t switch_socket_shutdown (switch_socket_t *sock, switch_shutdown_how_e how)
 
switch_status_t switch_socket_close (switch_socket_t *sock)
 
switch_status_t switch_socket_bind (switch_socket_t *sock, switch_sockaddr_t *sa)
 
switch_status_t switch_socket_listen (switch_socket_t *sock, int32_t backlog)
 
switch_status_t switch_socket_accept (switch_socket_t **new_sock, switch_socket_t *sock, switch_memory_pool_t *pool)
 
switch_status_t switch_socket_connect (switch_socket_t *sock, switch_sockaddr_t *sa)
 
int switch_socket_fd_get (switch_socket_t *sock)
 
uint16_t switch_sockaddr_get_port (switch_sockaddr_t *sa)
 
const char * switch_get_addr (char *buf, switch_size_t len, switch_sockaddr_t *in)
 
switch_status_t switch_getnameinfo (char **hostname, switch_sockaddr_t *sa, int32_t flags)
 
int32_t switch_sockaddr_get_family (switch_sockaddr_t *sa)
 
switch_status_t switch_sockaddr_ip_get (char **addr, switch_sockaddr_t *sa)
 
int switch_sockaddr_equal (const switch_sockaddr_t *sa1, const switch_sockaddr_t *sa2)
 
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)
 
switch_status_t switch_sockaddr_create (switch_sockaddr_t **sa, switch_memory_pool_t *pool)
 
switch_status_t switch_sockaddr_new (switch_sockaddr_t **sa, const char *ip, switch_port_t port, switch_memory_pool_t *pool)
 
switch_status_t switch_socket_send (switch_socket_t *sock, const char *buf, switch_size_t *len)
 
switch_status_t switch_socket_sendto (switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf, switch_size_t *len)
 
switch_status_t switch_socket_send_nonblock (switch_socket_t *sock, const char *buf, switch_size_t *len)
 
switch_status_t switch_socket_recvfrom (switch_sockaddr_t *from, switch_socket_t *sock, int32_t flags, char *buf, size_t *len)
 
switch_status_t switch_socket_atmark (switch_socket_t *sock, int *atmark)
 
switch_status_t switch_socket_recv (switch_socket_t *sock, char *buf, switch_size_t *len)
 
switch_status_t switch_socket_opt_set (switch_socket_t *sock, int32_t opt, int32_t on)
 
switch_status_t switch_socket_timeout_get (switch_socket_t *sock, switch_interval_time_t *t)
 
switch_status_t switch_socket_timeout_set (switch_socket_t *sock, switch_interval_time_t t)
 
switch_status_t switch_mcast_join (switch_socket_t *sock, switch_sockaddr_t *join, switch_sockaddr_t *iface, switch_sockaddr_t *source)
 
switch_status_t switch_mcast_hops (switch_socket_t *sock, uint8_t ttl)
 
switch_status_t switch_mcast_loopback (switch_socket_t *sock, uint8_t opt)
 
switch_status_t switch_mcast_interface (switch_socket_t *sock, switch_sockaddr_t *iface)
 

Detailed Description

Macro Definition Documentation

◆ SWITCH_INET

#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 1009 of file switch_apr.h.

◆ SWITCH_INET6

#define SWITCH_INET6   0

Definition at line 1013 of file switch_apr.h.

◆ SWITCH_SO_DEBUG

#define SWITCH_SO_DEBUG   4

Definition at line 993 of file switch_apr.h.

◆ SWITCH_SO_DISCONNECTED

#define SWITCH_SO_DISCONNECTED   256

Definition at line 998 of file switch_apr.h.

◆ SWITCH_SO_IPV6_V6ONLY

#define SWITCH_SO_IPV6_V6ONLY   16384 /* Don't accept IPv4 connections on an IPv6 listening socket. */

Definition at line 1002 of file switch_apr.h.

Referenced by msock_init().

◆ SWITCH_SO_KEEPALIVE

#define SWITCH_SO_KEEPALIVE   2

Definition at line 992 of file switch_apr.h.

Referenced by msrp_worker().

◆ SWITCH_SO_LINGER

#define SWITCH_SO_LINGER   1

Definition at line 991 of file switch_apr.h.

◆ SWITCH_SO_NONBLOCK

#define SWITCH_SO_NONBLOCK   8

◆ SWITCH_SO_RCVBUF

#define SWITCH_SO_RCVBUF   128

Definition at line 997 of file switch_apr.h.

Referenced by switch_rtp_set_local_address().

◆ SWITCH_SO_REUSEADDR

#define SWITCH_SO_REUSEADDR   16

◆ SWITCH_SO_SNDBUF

#define SWITCH_SO_SNDBUF   64

Definition at line 996 of file switch_apr.h.

Referenced by switch_rtp_set_local_address().

◆ SWITCH_SO_TCP_KEEPIDLE

#define SWITCH_SO_TCP_KEEPIDLE   520

Definition at line 1000 of file switch_apr.h.

Referenced by msrp_worker(), and switch_socket_opt_set().

◆ SWITCH_SO_TCP_KEEPINTVL

#define SWITCH_SO_TCP_KEEPINTVL   530

Definition at line 1001 of file switch_apr.h.

Referenced by msrp_worker(), and switch_socket_opt_set().

◆ SWITCH_SO_TCP_NODELAY

#define SWITCH_SO_TCP_NODELAY   512

Definition at line 999 of file switch_apr.h.

Referenced by msrp_listener(), and msrp_worker().

◆ SWITCH_UNSPEC

#define SWITCH_UNSPEC   0

Typedef Documentation

◆ switch_sockaddr_t

typedef struct fspr_sockaddr_t switch_sockaddr_t

Freeswitch's socket address type, used to ensure protocol independence

Definition at line 1029 of file switch_apr.h.

◆ switch_socket_t

typedef struct fspr_socket_t switch_socket_t

A structure to represent sockets

Definition at line 1026 of file switch_apr.h.

Enumeration Type Documentation

◆ switch_shutdown_how_e

Enumerator
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 1031 of file switch_apr.h.

1289  {

Function Documentation

◆ switch_get_addr()

const char* switch_get_addr ( char *  buf,
switch_size_t  len,
switch_sockaddr_t in 
)

Definition at line 979 of file switch_apr.c.

References buf, get_addr(), get_addr6(), memset(), and SWITCH_BLANK_STRING.

Referenced by check_rtcp_and_ice(), do_dtls(), enable_local_rtcp_socket(), enable_remote_rtcp_socket(), handle_ice(), handle_nack(), msrp_listener(), read_bundle_rtp_packet(), read_rtcp_packet(), read_rtp_packet(), rtp_common_read(), rtp_common_write(), switch_print_host(), switch_rtp_activate_ice(), switch_rtp_write_frame(), and switch_stun_host_lookup().

980 {
981  if (!in) {
982  return SWITCH_BLANK_STRING;
983  }
984 
985  memset(buf, 0, len);
986 
987  if (in->family == AF_INET) {
988  get_addr(buf, len, (struct sockaddr *) &in->sa, in->salen);
989  return buf;
990  }
991 
992  get_addr6(buf, len, (struct sockaddr_in6 *) &in->sa, in->salen);
993  return buf;
994 }
switch_byte_t switch_byte_t * buf
switch_byte_t in
#define SWITCH_BLANK_STRING
Definition: switch_types.h:48
char * get_addr(char *buf, switch_size_t len, struct sockaddr *sa, socklen_t salen)
find the char representation of an ip adress
char * get_addr6(char *buf, switch_size_t len, struct sockaddr_in6 *sa, socklen_t salen)
memset(buf, 0, buflen)

◆ switch_getnameinfo()

switch_status_t switch_getnameinfo ( char **  hostname,
switch_sockaddr_t sa,
int32_t  flags 
)

Definition at line 1011 of file switch_apr.c.

1012 {
1013  return fspr_getnameinfo(hostname, sa, flags);
1014 }

◆ switch_mcast_hops()

switch_status_t switch_mcast_hops ( switch_socket_t sock,
uint8_t  ttl 
)

Set the Multicast Time to Live (ttl) for a multicast transmission.

Parameters
sockThe socket to set the multicast ttl
ttlTime to live to Assign. 0-255, default=1
Remarks
If the TTL is 0, packets will only be seen by sockets on the local machine, and only when multicast loopback is enabled.

Definition at line 961 of file switch_apr.c.

Referenced by switch_rtp_set_local_address().

962 {
963  return fspr_mcast_hops(sock, ttl);
964 }

◆ switch_mcast_interface()

switch_status_t switch_mcast_interface ( switch_socket_t sock,
switch_sockaddr_t iface 
)

Definition at line 971 of file switch_apr.c.

Referenced by switch_rtp_set_local_address().

972 {
973  return fspr_mcast_interface(sock, iface);
974 }

◆ switch_mcast_join()

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

Parameters
sockThe socket to join a multicast group
joinThe address of the multicast group to join
ifaceAddress of the interface to use. If NULL is passed, the default multicast interface will be used. (OS Dependent)
sourceSource Address to accept transmissions from (non-NULL implies Source-Specific Multicast)

Definition at line 956 of file switch_apr.c.

Referenced by init_nat_monitor(), and switch_rtp_set_local_address().

957 {
958  return fspr_mcast_join(sock, join, iface, source);
959 }

◆ switch_mcast_loopback()

switch_status_t switch_mcast_loopback ( switch_socket_t sock,
uint8_t  opt 
)

Definition at line 966 of file switch_apr.c.

967 {
968  return fspr_mcast_loopback(sock, opt);
969 }

◆ switch_sockaddr_create()

switch_status_t switch_sockaddr_create ( switch_sockaddr_t **  sa,
switch_memory_pool_t pool 
)

Definition at line 818 of file switch_apr.c.

References pool, switch_assert, and SWITCH_STATUS_SUCCESS.

Referenced by switch_rtp_create().

819 {
820  switch_sockaddr_t *new_sa;
821  unsigned short family = APR_INET;
822 
823  new_sa = fspr_pcalloc(pool, sizeof(fspr_sockaddr_t));
824  switch_assert(new_sa);
825  new_sa->pool = pool;
826 
827  new_sa->family = family;
828  new_sa->sa.sin.sin_family = family;
829 
830  new_sa->salen = sizeof(struct sockaddr_in);
831  new_sa->addr_str_len = 16;
832  new_sa->ipaddr_ptr = &(new_sa->sa.sin.sin_addr);
833  new_sa->ipaddr_len = sizeof(struct in_addr);
834 
835  *sa = new_sa;
836  return SWITCH_STATUS_SUCCESS;
837 }
switch_memory_pool_t * pool
struct fspr_sockaddr_t switch_sockaddr_t
Definition: switch_apr.h:1029
#define switch_assert(expr)

◆ switch_sockaddr_equal()

int switch_sockaddr_equal ( const switch_sockaddr_t sa1,
const switch_sockaddr_t sa2 
)

Definition at line 951 of file switch_apr.c.

952 {
953  return fspr_sockaddr_equal(sa1, sa2);
954 }

◆ switch_sockaddr_get_family()

int32_t switch_sockaddr_get_family ( switch_sockaddr_t sa)

◆ switch_sockaddr_get_port()

uint16_t switch_sockaddr_get_port ( switch_sockaddr_t sa)

◆ switch_sockaddr_info_get()

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 fspr_sockaddr_t from hostname, address family, and port.

Parameters
saThe new fspr_sockaddr_t.
hostnameThe hostname or numeric address string to resolve/parse, or NULL to build an address that corresponds to 0.0.0.0 or ::
familyThe address family to use, or SWITCH_UNSPEC if the system should decide.
portThe port number.
flagsSpecial 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
poolThe pool for the fspr_sockaddr_t and associated storage.

Definition at line 839 of file switch_apr.c.

Referenced by enable_local_rtcp_socket(), enable_remote_rtcp_socket(), handle_ice(), init_nat_monitor(), msock_init(), msrp_worker(), switch_ivr_activate_unicast(), switch_rtp_activate_ice(), switch_rtp_activate_rtcp(), switch_rtp_set_local_address(), switch_rtp_set_remote_address(), switch_stun_host_lookup(), and switch_stun_lookup().

841 {
842  return fspr_sockaddr_info_get(sa, hostname, family, port, flags, pool);
843 }
switch_memory_pool_t * pool

◆ switch_sockaddr_ip_get()

switch_status_t switch_sockaddr_ip_get ( char **  addr,
switch_sockaddr_t sa 
)

Definition at line 946 of file switch_apr.c.

947 {
948  return fspr_sockaddr_ip_get(addr, sa);
949 }

◆ switch_sockaddr_new()

switch_status_t switch_sockaddr_new ( switch_sockaddr_t **  sa,
const char *  ip,
switch_port_t  port,
switch_memory_pool_t pool 
)

Definition at line 845 of file switch_apr.c.

References pool, switch_assert, switch_goto_status, SWITCH_STATUS_GENERR, and SWITCH_STATUS_SUCCESS.

Referenced by test_port().

846 {
848  fspr_sockaddr_t *new_sa;
849  int family;
850 
851  if (!sa || !pool || !ip) {
853  }
854 
855  new_sa = fspr_pcalloc(pool, sizeof(fspr_sockaddr_t));
856  switch_assert(new_sa);
857 
858  new_sa->pool = pool;
859 
860 #if APR_HAVE_IPV6
861  if (strchr(ip, ':')) {
862  struct sockaddr_in6 sa6 = { 0 };
863 
864  family = APR_INET6;
865  inet_pton(family, ip, &(sa6.sin6_addr));
866  memcpy(&new_sa->sa, &sa6, sizeof(struct sockaddr_in6));
867  } else
868 #endif
869  {
870  struct sockaddr_in sa4 = { 0 };
871 
872  family = APR_INET;
873  inet_pton(family, ip, &(sa4.sin_addr));
874  memcpy(&new_sa->sa, &sa4, sizeof(struct sockaddr_in));
875  }
876 
877  new_sa->hostname = fspr_pstrdup(pool, ip);
878  new_sa->family = family;
879  new_sa->sa.sin.sin_family = family;
880  if (port) {
881  /* XXX IPv6: assumes sin_port and sin6_port at same offset */
882  new_sa->sa.sin.sin_port = htons(port);
883  new_sa->port = port;
884  }
885 
886  if (family == APR_INET) {
887  new_sa->salen = sizeof(struct sockaddr_in);
888  new_sa->addr_str_len = 16;
889  new_sa->ipaddr_ptr = &(new_sa->sa.sin.sin_addr);
890  new_sa->ipaddr_len = sizeof(struct in_addr);
891  }
892 #if APR_HAVE_IPV6
893  else if (family == APR_INET6) {
894  new_sa->salen = sizeof(struct sockaddr_in6);
895  new_sa->addr_str_len = 46;
896  new_sa->ipaddr_ptr = &(new_sa->sa.sin6.sin6_addr);
897  new_sa->ipaddr_len = sizeof(struct in6_addr);
898  }
899 #endif
900 
901  *sa = new_sa;
902 
903 end:
904  return status;
905 }
switch_memory_pool_t * pool
char * ip
Definition: switch_msrp.c:60
switch_status_t
Common return values.
#define switch_goto_status(_status, _label)
Definition: switch_utils.h:287
#define switch_assert(expr)

◆ switch_socket_accept()

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

Parameters
new_sockA 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.
sockThe socket we are listening on.
poolThe pool for the new socket.

Definition at line 752 of file switch_apr.c.

Referenced by msrp_listener().

753 {
754  return fspr_socket_accept(new_sock, sock, pool);
755 }
switch_memory_pool_t * pool

◆ switch_socket_atmark()

switch_status_t switch_socket_atmark ( switch_socket_t sock,
int *  atmark 
)

Definition at line 1016 of file switch_apr.c.

1017 {
1018  return fspr_socket_atmark(sock, atmark);
1019 }

◆ switch_socket_bind()

switch_status_t switch_socket_bind ( switch_socket_t sock,
switch_sockaddr_t sa 
)

Bind the socket to its associated port

Parameters
sockThe socket to bind
saThe socket address to bind to
Remarks
This may be where we will find out if there is any other process using the selected port.

Definition at line 742 of file switch_apr.c.

Referenced by enable_local_rtcp_socket(), init_nat_monitor(), msock_init(), switch_ivr_activate_unicast(), switch_rtp_set_local_address(), switch_stun_lookup(), and test_port().

743 {
744  return fspr_socket_bind(sock, sa);
745 }

◆ switch_socket_close()

switch_status_t switch_socket_close ( switch_socket_t sock)

◆ switch_socket_connect()

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.

Parameters
sockThe socket we wish to use for our side of the connection
saThe address of the machine we wish to connect to.

Definition at line 757 of file switch_apr.c.

Referenced by msrp_worker().

758 {
759  return fspr_socket_connect(sock, sa);
760 }

◆ switch_socket_create()

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.

Parameters
new_sockThe new socket that has been set up.
familyThe address family of the socket (e.g., SWITCH_INET).
typeThe type of the socket (e.g., SOCK_STREAM).
protocolThe protocol of the socket (e.g., SWITCH_PROTO_TCP).
poolThe pool to use

Definition at line 727 of file switch_apr.c.

Referenced by enable_local_rtcp_socket(), enable_remote_rtcp_socket(), init_nat_monitor(), msock_init(), msrp_worker(), switch_ivr_activate_unicast(), switch_rtp_set_local_address(), switch_rtp_set_remote_address(), switch_stun_lookup(), and test_port().

728 {
729  return fspr_socket_create(new_sock, family, type, protocol, pool);
730 }
switch_memory_pool_t * pool

◆ switch_socket_fd_get()

int switch_socket_fd_get ( switch_socket_t sock)

Get socket fd for the switch socket passed

Parameters
sockThe socket we wish to have fd

Definition at line 996 of file switch_apr.c.

997 {
998  return fspr_socket_fd_get(sock);
999 }

◆ switch_socket_listen()

switch_status_t switch_socket_listen ( switch_socket_t sock,
int32_t  backlog 
)

Listen to a bound socket for connections.

Parameters
sockThe socket to listen on
backlogThe 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 747 of file switch_apr.c.

Referenced by msock_init().

748 {
749  return fspr_socket_listen(sock, backlog);
750 }

◆ switch_socket_opt_set()

switch_status_t switch_socket_opt_set ( switch_socket_t sock,
int32_t  opt,
int32_t  on 
)

Setup socket options for the specified socket

Parameters
sockThe socket to set up.
optThe 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
onValue for the option.

Definition at line 907 of file switch_apr.c.

References SWITCH_SO_TCP_KEEPIDLE, SWITCH_SO_TCP_KEEPINTVL, SWITCH_STATUS_FALSE, SWITCH_STATUS_NOTIMPL, and SWITCH_STATUS_SUCCESS.

Referenced by do_flush(), enable_local_rtcp_socket(), init_nat_monitor(), msock_init(), msrp_listener(), msrp_worker(), switch_rtp_clear_flag(), switch_rtp_set_flag(), switch_rtp_set_local_address(), switch_rtp_udptl_mode(), and switch_stun_lookup().

908 {
909  if (opt == SWITCH_SO_TCP_KEEPIDLE) {
910 #if defined(TCP_KEEPIDLE)
911  int r = -10;
912  r = setsockopt(sock->socketdes, SOL_TCP, TCP_KEEPIDLE, (void *)&on, sizeof(on));
914 #else
915  return SWITCH_STATUS_NOTIMPL;
916 #endif
917  }
918 
919  if (opt == SWITCH_SO_TCP_KEEPINTVL) {
920 #if defined(TCP_KEEPINTVL)
921  int r = -10;
922  r = setsockopt(sock->socketdes, SOL_TCP, TCP_KEEPINTVL, (void *)&on, sizeof(on));
924 #else
925  return SWITCH_STATUS_NOTIMPL;
926 #endif
927  }
928 
929  return fspr_socket_opt_set(sock, opt, on);
930 }
#define SWITCH_SO_TCP_KEEPIDLE
Definition: switch_apr.h:1000
#define SWITCH_SO_TCP_KEEPINTVL
Definition: switch_apr.h:1001

◆ switch_socket_recv()

switch_status_t switch_socket_recv ( switch_socket_t sock,
char *  buf,
switch_size_t len 
)

Read data from a network.

Parameters
sockThe socket to read the data from.
bufThe buffer to store the data in.
lenOn entry, the number of bytes to receive; on exit, the number of bytes received.
Remarks
This functions acts like a blocking read by default.  To change
this behavior, use fspr_socket_timeout_set() or the APR_SO_NONBLOCK
socket option.
The number of bytes actually received is stored in argument 3.

It is possible for both bytes to be received and an APR_EOF or other error to be returned.

APR_EINTR is never returned.

Definition at line 805 of file switch_apr.c.

References SWITCH_STATUS_BREAK.

Referenced by msrp_socket_recv(), and unicast_thread_run().

806 {
807  int r;
808 
809  r = fspr_socket_recv(sock, buf, len);
810 
811  if (r == 35 || r == 730035) {
813  }
814 
815  return (switch_status_t)r;
816 }
switch_byte_t switch_byte_t * buf
switch_status_t
Common return values.

◆ switch_socket_recvfrom()

switch_status_t switch_socket_recvfrom ( switch_sockaddr_t from,
switch_socket_t sock,
int32_t  flags,
char *  buf,
size_t *  len 
)
Parameters
fromThe fspr_sockaddr_t to fill in the recipient info
sockThe socket to use
flagsThe flags to use
bufThe buffer to use
lenThe length of the available buffer

Definition at line 1021 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().

1022 {
1023  int r = SWITCH_STATUS_GENERR;
1024 
1025  if (from && sock && (r = fspr_socket_recvfrom(from, sock, flags, buf, len)) == APR_SUCCESS) {
1026  from->port = ntohs(from->sa.sin.sin_port);
1027  /* from->ipaddr_ptr = &(from->sa.sin.sin_addr);
1028  * from->ipaddr_ptr = inet_ntoa(from->sa.sin.sin_addr);
1029  */
1030  }
1031 
1032  if (r == 35 || r == 730035) {
1033  r = SWITCH_STATUS_BREAK;
1034  }
1035 
1036  return (switch_status_t)r;
1037 }
switch_byte_t switch_byte_t * buf
switch_status_t
Common return values.

◆ switch_socket_send()

switch_status_t switch_socket_send ( switch_socket_t sock,
const char *  buf,
switch_size_t len 
)

Send data over a network.

Parameters
sockThe socket to send the data over.
bufThe buffer which contains the data to be sent.
lenOn entry, the number of bytes to send; on exit, the number of bytes sent.
Remarks
This functions acts like a blocking write by default.  To change
this behavior, use fspr_socket_timeout_set() or the APR_SO_NONBLOCK
socket option.

It is possible for both bytes to be sent and an error to be returned.

APR_EINTR is never returned.

Definition at line 762 of file switch_apr.c.

References SWITCH_STATUS_BREAK, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_yield.

Referenced by msrp_socket_send().

763 {
764  int status = SWITCH_STATUS_SUCCESS;
765  switch_size_t req = *len, wrote = 0, need = *len;
766  int to_count = 0;
767 
768  while ((wrote < req && status == SWITCH_STATUS_SUCCESS) || (need == 0 && status == SWITCH_STATUS_BREAK) || status == 730035 || status == 35) {
769  need = req - wrote;
770  status = fspr_socket_send(sock, buf + wrote, &need);
771  if (status == SWITCH_STATUS_BREAK || status == 730035 || status == 35) {
772  if (++to_count > 60000) {
773  status = SWITCH_STATUS_FALSE;
774  break;
775  }
776  switch_yield(10000);
777  } else {
778  to_count = 0;
779  }
780  wrote += need;
781  }
782 
783  *len = wrote;
784  return (switch_status_t)status;
785 }
switch_byte_t switch_byte_t * buf
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:998
uintptr_t switch_size_t
switch_status_t
Common return values.

◆ switch_socket_send_nonblock()

switch_status_t switch_socket_send_nonblock ( switch_socket_t sock,
const char *  buf,
switch_size_t len 
)

Definition at line 787 of file switch_apr.c.

References SWITCH_STATUS_GENERR.

788 {
789  if (!sock || !buf || !len) {
790  return SWITCH_STATUS_GENERR;
791  }
792 
793  return fspr_socket_send(sock, buf, len);
794 }
switch_byte_t switch_byte_t * buf

◆ switch_socket_sendto()

switch_status_t switch_socket_sendto ( switch_socket_t sock,
switch_sockaddr_t where,
int32_t  flags,
const char *  buf,
switch_size_t len 
)
Parameters
sockThe socket to send from
whereThe fspr_sockaddr_t describing where to send the data
flagsThe flags to use
bufThe data to send
lenThe length of the data to send

Definition at line 796 of file switch_apr.c.

References SWITCH_STATUS_GENERR.

Referenced by check_rtcp_and_ice(), do_dtls(), 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_raw(), and switch_stun_lookup().

798 {
799  if (!where || !buf || !len || !*len) {
800  return SWITCH_STATUS_GENERR;
801  }
802  return fspr_socket_sendto(sock, where, flags, buf, len);
803 }
switch_byte_t switch_byte_t * buf

◆ switch_socket_shutdown()

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.

Parameters
sockThe socket to close
howHow 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
See also
switch_shutdown_how_e
Remarks
This does not actually close the socket descriptor, it just controls which calls are still valid on the socket.

Definition at line 732 of file switch_apr.c.

Referenced by close_socket(), switch_ivr_deactivate_unicast(), switch_rtp_kill_socket(), switch_rtp_udptl_mode(), and switch_stun_lookup().

733 {
734  return fspr_socket_shutdown(sock, (fspr_shutdown_how_e) how);
735 }

◆ switch_socket_timeout_get()

switch_status_t switch_socket_timeout_get ( switch_socket_t sock,
switch_interval_time_t t 
)

Query socket timeout for the specified socket

Parameters
sockThe socket to query
tSocket timeout returned from the query.
  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 932 of file switch_apr.c.

933 {
934  fspr_interval_time_t at = 0;
935  switch_status_t status = fspr_socket_timeout_get(sock, &at);
936  *t = at;
937 
938  return status;
939 }
switch_status_t
Common return values.

◆ switch_socket_timeout_set()

switch_status_t switch_socket_timeout_set ( switch_socket_t sock,
switch_interval_time_t  t 
)

Setup socket timeout for the specified socket

Parameters
sockThe socket to set up.
tValue 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 941 of file switch_apr.c.

Referenced by msrp_worker().

942 {
943  return fspr_socket_timeout_set(sock, t);
944 }