Changeset 6071
- Timestamp:
- Sep 23, 2019 7:25:41 AM (5 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c
r6009 r6071 292 292 PJMEDIA_TRANSPORT_SO_SNDBUF_SIZE; 293 293 } 294 if (ice_st_cfg.send_buf_size == 0) 295 ice_st_cfg.send_buf_size = PJMEDIA_MAX_MTU; 294 296 295 297 /* Create ICE */ … … 1888 1890 { 1889 1891 struct transport_ice *tp_ice = (struct transport_ice*)tp; 1892 pj_status_t status; 1890 1893 1891 1894 /* Simulate packet lost on TX direction */ … … 1899 1902 } 1900 1903 1901 return pj_ice_strans_sendto(tp_ice->ice_st, 1, 1902 pkt, size, &tp_ice->remote_rtp, 1903 tp_ice->addr_len); 1904 status = pj_ice_strans_sendto2(tp_ice->ice_st, 1, 1905 pkt, size, &tp_ice->remote_rtp, 1906 tp_ice->addr_len); 1907 if (status == PJ_EPENDING) 1908 status = PJ_SUCCESS; 1909 1910 return status; 1904 1911 } 1905 1912 … … 1921 1928 1922 1929 if (tp_ice->comp_cnt > 1 || tp_ice->use_rtcp_mux) { 1930 pj_status_t status; 1923 1931 unsigned comp_id = (tp_ice->use_rtcp_mux? 1: 2); 1932 1924 1933 if (addr == NULL) { 1925 1934 addr = &tp_ice->remote_rtcp; 1926 1935 addr_len = pj_sockaddr_get_len(addr); 1927 1936 } 1928 return pj_ice_strans_sendto(tp_ice->ice_st, comp_id, pkt, size, 1929 addr, addr_len); 1937 1938 status = pj_ice_strans_sendto2(tp_ice->ice_st, comp_id, pkt, size, 1939 addr, addr_len); 1940 if (status == PJ_EPENDING) 1941 status = PJ_SUCCESS; 1942 1943 return status; 1930 1944 } else { 1931 1945 return PJ_SUCCESS; -
pjproject/trunk/pjnath/include/pjnath/ice_session.h
r5339 r6071 935 935 * @param data_len Size of data or packet, in bytes. 936 936 * 937 * @return PJ_SUCCESS if data is sent successfully. 937 * @return If the callback \a on_tx_pkt() is called, this 938 * will contain the return value of the callback. 939 * Otherwise, it will indicate failure with 940 * the appropriate error code. 938 941 */ 939 942 PJ_DECL(pj_status_t) pj_ice_sess_send_data(pj_ice_sess *ice, -
pjproject/trunk/pjnath/include/pjnath/ice_strans.h
r5562 r6071 99 99 * pair. The ICE stream transport may not be able to send data while 100 100 * negotiation is in progress.\n\n 101 * - application sends data by using #pj_ice_strans_sendto (). Incoming101 * - application sends data by using #pj_ice_strans_sendto2(). Incoming 102 102 * data will be reported in \a on_rx_data() callback of the 103 103 * #pj_ice_strans_cb.\n\n … … 114 114 */ 115 115 116 /* Deprecated API pj_ice_strans_sendto() due to its limitations. See 117 * below for more info and refer to 118 * https://trac.pjsip.org/repos/ticket/2229 for more details. 119 */ 120 #ifndef DEPRECATED_FOR_TICKET_2229 121 # define DEPRECATED_FOR_TICKET_2229 0 122 #endif 123 116 124 /** Forward declaration for ICE stream transport. */ 117 125 typedef struct pj_ice_strans pj_ice_strans; … … 160 168 const pj_sockaddr_t *src_addr, 161 169 unsigned src_addr_len); 170 171 /** 172 * This callback is optional and will be called to notify the status of 173 * async send operations. 174 * 175 * @param ice_st The ICE stream transport. 176 * @param sent If value is positive non-zero it indicates the 177 * number of data sent. When the value is negative, 178 * it contains the error code which can be retrieved 179 * by negating the value (i.e. status=-sent). 180 */ 181 void (*on_data_sent)(pj_ice_strans *sock, 182 pj_ssize_t sent); 162 183 163 184 /** … … 416 437 */ 417 438 pj_ice_strans_turn_cfg turn_tp[PJ_ICE_MAX_TURN]; 439 440 /** 441 * Number of send buffers used for pj_ice_strans_sendto2(). If the send 442 * buffers are full, pj_ice_strans_sendto()/sendto2() will return 443 * PJ_EBUSY. 444 * 445 * Set this to 0 to disable buffering (then application will have to 446 * maintain the buffer passed to pj_ice_strans_sendto()/sendto2() 447 * until it has been sent). 448 * 449 * Default: 4 450 */ 451 unsigned num_send_buf; 452 453 /** 454 * Buffer size used for pj_ice_strans_sendto2(). 455 * 456 * Default: 0 (size determined by the size of the first packet sent). 457 */ 458 unsigned send_buf_size; 418 459 419 460 /** … … 905 946 906 947 948 #if !DEPRECATED_FOR_TICKET_2229 907 949 /** 908 950 * Send outgoing packet using this transport. … … 917 959 * address, as negotiated by ICE. 918 960 * 961 * Limitations: 962 * 1. This function cannot inform the app whether the data has been sent, 963 * or currently still pending. 964 * 2. In case that the data is still pending, the application has no way 965 * of knowing the status of the send operation (whether it's a success 966 * or failure). 967 * Due to these limitations, the API is deprecated and will be removed 968 * in the future. 969 * 970 * Note that application shouldn't mix using pj_ice_strans_sendto() and 971 * pj_ice_strans_sendto2() to avoid inconsistent calling of 972 * on_data_sent() callback. 973 * 919 974 * @param ice_st The ICE stream transport. 920 975 * @param comp_id Component ID. … … 924 979 * @param dst_addr_len Length of destination address. 925 980 * 926 * @return PJ_SUCCESS if data is sent successfully. 981 * @return PJ_SUCCESS if data has been sent, or will be sent 982 * later. No callback will be called. 927 983 */ 928 984 PJ_DECL(pj_status_t) pj_ice_strans_sendto(pj_ice_strans *ice_st, … … 932 988 const pj_sockaddr_t *dst_addr, 933 989 int dst_addr_len); 990 #endif 991 992 993 /** 994 * Send outgoing packet using this transport. 995 * Application can send data (normally RTP or RTCP packets) at any time 996 * by calling this function. This function takes a destination 997 * address as one of the arguments, and this destination address should 998 * be taken from the default transport address of the component (that is 999 * the address in SDP c= and m= lines, or in a=rtcp attribute). 1000 * If ICE negotiation is in progress, this function will send the data 1001 * to the destination address. Otherwise if ICE negotiation has completed 1002 * successfully, this function will send the data to the nominated remote 1003 * address, as negotiated by ICE. 1004 * 1005 * Note that application shouldn't mix using pj_ice_strans_sendto() and 1006 * pj_ice_strans_sendto2() to avoid inconsistent calling of 1007 * on_data_sent() callback. 1008 * 1009 * @param ice_st The ICE stream transport. 1010 * @param comp_id Component ID. 1011 * @param data The data or packet to be sent. 1012 * @param data_len Size of data or packet, in bytes. 1013 * @param dst_addr The destination address. 1014 * @param dst_addr_len Length of destination address. 1015 * 1016 * @return PJ_SUCCESS if data has been sent, or 1017 * PJ_EPENDING if data cannot be sent immediately. In 1018 * this case the \a on_data_sent() callback will be 1019 * called when data is actually sent. Any other return 1020 * value indicates error condition. 1021 */ 1022 PJ_DECL(pj_status_t) pj_ice_strans_sendto2(pj_ice_strans *ice_st, 1023 unsigned comp_id, 1024 const void *data, 1025 pj_size_t data_len, 1026 const pj_sockaddr_t *dst_addr, 1027 int dst_addr_len); 934 1028 935 1029 -
pjproject/trunk/pjnath/include/pjnath/turn_session.h
r6004 r6071 234 234 /** 235 235 * This callback will be called by the TURN session whenever it 236 * needs to send outgoing message. Since the TURN session doesn't 237 * have a socket on its own, this callback must be implemented. 236 * needs to send data or outgoing messages. Since the TURN session 237 * doesn't have a socket on its own, this callback must be implemented. 238 * 239 * If the callback \a on_stun_send_pkt() is implemented, outgoing 240 * messages will use that callback instead. 238 241 * 239 242 * @param sess The TURN session. … … 251 254 const pj_sockaddr_t *dst_addr, 252 255 unsigned addr_len); 256 257 /** 258 * This callback will be called by the TURN session whenever it 259 * needs to send outgoing STUN requests/messages for TURN signalling 260 * purposes (data sending will not invoke this callback). If this 261 * callback is not implemented, the callback \a on_send_pkt() 262 * will be called instead. 263 * 264 * @param sess The TURN session. 265 * @param pkt The packet/data to be sent. 266 * @param pkt_len Length of the packet/data. 267 * @param dst_addr Destination address of the packet. 268 * @param addr_len Length of the destination address. 269 * 270 * @return The callback should return the status of the 271 * send operation. 272 */ 273 pj_status_t (*on_stun_send_pkt)(pj_turn_session *sess, 274 const pj_uint8_t *pkt, 275 unsigned pkt_len, 276 const pj_sockaddr_t *dst_addr, 277 unsigned addr_len); 253 278 254 279 /** … … 763 788 * @param addr_len Length of the address. 764 789 * 765 * @return PJ_SUCCESS if the operation has been successful, 766 * or the appropriate error code on failure. 790 * @return If the callback \a on_send_pkt() is called, this 791 * will contain the return value of the callback. 792 * Otherwise, it will indicate failure with 793 * the appropriate error code. 767 794 */ 768 795 PJ_DECL(pj_status_t) pj_turn_session_sendto(pj_turn_session *sess, -
pjproject/trunk/pjnath/include/pjnath/turn_sock.h
r6004 r6071 87 87 const pj_sockaddr_t *peer_addr, 88 88 unsigned addr_len); 89 90 /** 91 * Notifification when asynchronous send operation has completed. 92 * 93 * @param turn_sock The TURN transport. 94 * @param sent If value is positive non-zero it indicates the 95 * number of data sent. When the value is negative, 96 * it contains the error code which can be retrieved 97 * by negating the value (i.e. status=-sent). 98 * 99 * @return Application should normally return PJ_TRUE to let 100 * the TURN transport continue its operation. However 101 * it must return PJ_FALSE if it has destroyed the 102 * TURN transport in this callback. 103 */ 104 pj_bool_t (*on_data_sent)(pj_turn_sock *sock, 105 pj_ssize_t sent); 89 106 90 107 /** … … 575 592 * @param addr_len Length of the address. 576 593 * 577 * @return PJ_SUCCESS if the operation has been successful, 578 * or the appropriate error code on failure. 594 * @return PJ_SUCCESS if data has been sent immediately, or 595 * PJ_EPENDING if data cannot be sent immediately. In 596 * this case the \a on_data_sent() callback will be 597 * called when data is actually sent. Any other return 598 * value indicates error condition. 579 599 */ 580 600 PJ_DECL(pj_status_t) pj_turn_sock_sendto(pj_turn_sock *turn_sock, -
pjproject/trunk/pjnath/src/pjnath/ice_strans.c
r6048 r6071 128 128 const pj_sockaddr_t *peer_addr, 129 129 unsigned addr_len); 130 static pj_bool_t turn_on_data_sent(pj_turn_sock *turn_sock, 131 pj_ssize_t sent); 130 132 static void turn_on_state(pj_turn_sock *turn_sock, pj_turn_state_t old_state, 131 133 pj_turn_state_t new_state); … … 134 136 135 137 /* Forward decls */ 138 static pj_bool_t on_data_sent(pj_ice_strans *ice_st, pj_ssize_t sent); 136 139 static void ice_st_on_destroy(void *obj); 137 140 static void destroy_ice_st(pj_ice_strans *ice_st); … … 179 182 180 183 184 /* Pending send buffer */ 185 typedef struct pending_send 186 { 187 void *buffer; 188 unsigned comp_id; 189 pj_size_t data_len; 190 pj_sockaddr dst_addr; 191 int dst_addr_len; 192 } pending_send; 193 181 194 /** 182 195 * This structure represents the ICE stream transport. … … 185 198 { 186 199 char *obj_name; /**< Log ID. */ 200 pj_pool_factory *pf; /**< Pool factory. */ 187 201 pj_pool_t *pool; /**< Pool used by this object. */ 188 202 void *user_data; /**< Application data. */ … … 198 212 pj_ice_strans_comp **comp; /**< Components array. */ 199 213 214 pj_pool_t *buf_pool; /**< Pool for buffers. */ 215 unsigned num_buf; /**< Number of buffers. */ 216 unsigned buf_idx; /**< Index of buffer. */ 217 unsigned empty_idx; /**< Index of empty buffer. */ 218 unsigned buf_size; /**< Buffer size. */ 219 pending_send *send_buf; /**< Send buffers. */ 220 pj_bool_t is_pending;/**< Any pending send? */ 221 200 222 pj_timer_entry ka_timer; /**< STUN keep-alive timer. */ 201 223 202 224 pj_bool_t destroy_req;/**< Destroy has been called? */ 203 225 pj_bool_t cb_called; /**< Init error callback called?*/ 226 pj_bool_t call_send_cb;/**< Need to call send cb? */ 204 227 }; 205 228 … … 242 265 pj_ice_strans_turn_cfg_default(&cfg->turn); 243 266 pj_ice_sess_options_default(&cfg->opt); 267 268 cfg->num_send_buf = 4; 244 269 } 245 270 … … 368 393 pj_bzero(&turn_sock_cb, sizeof(turn_sock_cb)); 369 394 turn_sock_cb.on_rx_data = &turn_on_rx_data; 395 turn_sock_cb.on_data_sent = &turn_on_data_sent; 370 396 turn_sock_cb.on_state = &turn_on_state; 371 397 … … 786 812 } 787 813 814 static pj_status_t alloc_send_buf(pj_ice_strans *ice_st, unsigned buf_size) 815 { 816 if (buf_size > ice_st->buf_size) { 817 unsigned i; 818 819 if (ice_st->is_pending) { 820 /* The current buffer is insufficient, but still currently used.*/ 821 return PJ_EBUSY; 822 } 823 824 pj_pool_safe_release(&ice_st->buf_pool); 825 826 ice_st->buf_pool = pj_pool_create(ice_st->pf, "ice_buf", 827 (buf_size + sizeof(pending_send)) * 828 ice_st->num_buf, 512, NULL); 829 if (!ice_st->buf_pool) 830 return PJ_ENOMEM; 831 832 ice_st->buf_size = buf_size; 833 ice_st->send_buf = pj_pool_calloc(ice_st->buf_pool, ice_st->num_buf, 834 sizeof(pending_send)); 835 for (i = 0; i < ice_st->num_buf; i++) { 836 ice_st->send_buf[i].buffer = pj_pool_alloc(ice_st->buf_pool, 837 buf_size); 838 } 839 ice_st->buf_idx = ice_st->empty_idx = 0; 840 } 841 842 return PJ_SUCCESS; 843 } 788 844 789 845 /* … … 816 872 ice_st = PJ_POOL_ZALLOC_T(pool, pj_ice_strans); 817 873 ice_st->pool = pool; 874 ice_st->pf = cfg->stun_cfg.pf; 818 875 ice_st->obj_name = pool->obj_name; 819 876 ice_st->user_data = user_data; … … 827 884 if (status != PJ_SUCCESS) { 828 885 pj_pool_release(pool); 886 pj_log_pop_indent(); 887 return status; 888 } 889 890 /* Allocate send buffer */ 891 ice_st->num_buf = cfg->num_send_buf; 892 status = alloc_send_buf(ice_st, cfg->send_buf_size); 893 if (status != PJ_SUCCESS) { 894 destroy_ice_st(ice_st); 829 895 pj_log_pop_indent(); 830 896 return status; … … 902 968 903 969 /* Done */ 904 pj_pool_release(ice_st->pool); 970 pj_pool_safe_release(&ice_st->buf_pool); 971 pj_pool_safe_release(&ice_st->pool); 905 972 } 906 973 … … 1464 1531 1465 1532 /* Protect with group lock, since this may cause race condition with 1466 * pj_ice_strans_sendto ().1533 * pj_ice_strans_sendto2(). 1467 1534 * See ticket #1877. 1468 1535 */ … … 1481 1548 } 1482 1549 1550 static pj_status_t use_buffer( pj_ice_strans *ice_st, 1551 unsigned comp_id, 1552 const void *data, 1553 pj_size_t data_len, 1554 const pj_sockaddr_t *dst_addr, 1555 int dst_addr_len, 1556 void **buffer ) 1557 { 1558 unsigned idx; 1559 pj_status_t status; 1560 1561 /* Allocate send buffer, if necessary. */ 1562 status = alloc_send_buf(ice_st, data_len); 1563 if (status != PJ_SUCCESS) 1564 return status; 1565 1566 if (ice_st->is_pending && ice_st->empty_idx == ice_st->buf_idx) { 1567 /* We don't use buffer or there's no more empty buffer. */ 1568 return PJ_EBUSY; 1569 } 1570 1571 idx = ice_st->empty_idx; 1572 ice_st->empty_idx = (ice_st->empty_idx + 1) % ice_st->num_buf; 1573 ice_st->send_buf[idx].comp_id = comp_id; 1574 ice_st->send_buf[idx].data_len = data_len; 1575 pj_assert(ice_st->buf_size >= data_len); 1576 pj_memcpy(ice_st->send_buf[idx].buffer, data, data_len); 1577 pj_sockaddr_cp(&ice_st->send_buf[idx].dst_addr, dst_addr); 1578 ice_st->send_buf[idx].dst_addr_len = dst_addr_len; 1579 *buffer = ice_st->send_buf[idx].buffer; 1580 1581 if (ice_st->is_pending) { 1582 /* We'll continue later since there's still a pending send. */ 1583 return PJ_EPENDING; 1584 } 1585 1586 ice_st->is_pending = PJ_TRUE; 1587 ice_st->buf_idx = idx; 1588 1589 return PJ_SUCCESS; 1590 } 1591 1483 1592 /* 1484 1593 * Application wants to send outgoing packet. 1485 1594 */ 1486 PJ_DEF(pj_status_t) pj_ice_strans_sendto( pj_ice_strans *ice_st, 1487 unsigned comp_id, 1488 const void *data, 1489 pj_size_t data_len, 1490 const pj_sockaddr_t *dst_addr, 1491 int dst_addr_len) 1595 static pj_status_t send_data(pj_ice_strans *ice_st, 1596 unsigned comp_id, 1597 const void *data, 1598 pj_size_t data_len, 1599 const pj_sockaddr_t *dst_addr, 1600 int dst_addr_len, 1601 pj_bool_t use_buf, 1602 pj_bool_t call_cb) 1492 1603 { 1493 1604 pj_ice_strans_comp *comp; 1494 1605 pj_ice_sess_cand *def_cand; 1606 void *buf = (void *)data; 1495 1607 pj_status_t status; 1496 1608 … … 1501 1613 1502 1614 /* Check that default candidate for the component exists */ 1503 if (comp->default_cand >= comp->cand_cnt) 1504 return PJ_EINVALIDOP; 1615 if (comp->default_cand >= comp->cand_cnt) { 1616 status = PJ_EINVALIDOP; 1617 goto on_return; 1618 } 1505 1619 1506 1620 /* Protect with group lock, since this may cause race condition with … … 1509 1623 */ 1510 1624 pj_grp_lock_acquire(ice_st->grp_lock); 1625 1626 if (use_buf && ice_st->num_buf > 0) { 1627 status = use_buffer(ice_st, comp_id, data, data_len, dst_addr, 1628 dst_addr_len, &buf); 1629 1630 if (status == PJ_EPENDING || status != PJ_SUCCESS) { 1631 pj_grp_lock_release(ice_st->grp_lock); 1632 return status; 1633 } 1634 } 1511 1635 1512 1636 /* If ICE is available, send data with ICE, otherwise send with the … … 1517 1641 */ 1518 1642 if (ice_st->ice && ice_st->state == PJ_ICE_STRANS_STATE_RUNNING) { 1519 status = pj_ice_sess_send_data(ice_st->ice, comp_id, data, data_len);1643 status = pj_ice_sess_send_data(ice_st->ice, comp_id, buf, data_len); 1520 1644 1521 1645 pj_grp_lock_release(ice_st->grp_lock); 1522 1646 1523 return status;1647 goto on_return; 1524 1648 } 1525 1649 1526 1650 pj_grp_lock_release(ice_st->grp_lock); 1527 1651 … … 1542 1666 if (comp->turn[tp_idx].sock == NULL) { 1543 1667 /* TURN socket error */ 1544 return PJ_EINVALIDOP; 1668 status = PJ_EINVALIDOP; 1669 goto on_return; 1545 1670 } 1546 1671 … … 1556 1681 1557 1682 status = pj_turn_sock_sendto(comp->turn[tp_idx].sock, 1558 (const pj_uint8_t*) data,1683 (const pj_uint8_t*)buf, 1559 1684 (unsigned)data_len, 1560 1685 dst_addr, dst_addr_len); 1561 return (status==PJ_SUCCESS||status==PJ_EPENDING) ? 1562 PJ_SUCCESS : status; 1686 goto on_return; 1563 1687 } else { 1564 1688 const pj_sockaddr_t *dest_addr; … … 1573 1697 dst_addr); 1574 1698 if (status != PJ_SUCCESS) 1575 return status;1699 goto on_return; 1576 1700 1577 1701 pj_sockaddr_cp(&comp->dst_addr, dst_addr); … … 1586 1710 } 1587 1711 1588 status = pj_stun_sock_sendto(comp->stun[tp_idx].sock, NULL, data,1712 status = pj_stun_sock_sendto(comp->stun[tp_idx].sock, NULL, buf, 1589 1713 (unsigned)data_len, 0, dest_addr, 1590 1714 dest_addr_len); 1591 return (status==PJ_SUCCESS||status==PJ_EPENDING) ? 1592 PJ_SUCCESS : status; 1715 goto on_return; 1593 1716 } 1594 1717 1595 1718 } else 1596 return PJ_EINVALIDOP; 1597 } 1719 status = PJ_EINVALIDOP; 1720 1721 on_return: 1722 /* We continue later in on_data_sent() callback. */ 1723 if (status == PJ_EPENDING) 1724 return status; 1725 1726 if (call_cb) { 1727 on_data_sent(ice_st, (status == PJ_SUCCESS? data_len: -status)); 1728 } else { 1729 pj_grp_lock_acquire(ice_st->grp_lock); 1730 if (ice_st->num_buf > 0) { 1731 ice_st->buf_idx = (ice_st->buf_idx + 1) % ice_st->num_buf; 1732 pj_assert (ice_st->buf_idx == ice_st->empty_idx); 1733 } 1734 ice_st->is_pending = PJ_FALSE; 1735 pj_grp_lock_release(ice_st->grp_lock); 1736 } 1737 1738 return status; 1739 } 1740 1741 1742 #if !DEPRECATED_FOR_TICKET_2229 1743 /* 1744 * Application wants to send outgoing packet. 1745 */ 1746 PJ_DEF(pj_status_t) pj_ice_strans_sendto( pj_ice_strans *ice_st, 1747 unsigned comp_id, 1748 const void *data, 1749 pj_size_t data_len, 1750 const pj_sockaddr_t *dst_addr, 1751 int dst_addr_len) 1752 { 1753 pj_status_t status; 1754 1755 PJ_LOG(1, (ice_st->obj_name, "pj_ice_strans_sendto() is deprecated. " 1756 "Application is recommended to use " 1757 "pj_ice_strans_sendto2() instead.")); 1758 status = send_data(ice_st, comp_id, data, data_len, dst_addr, 1759 dst_addr_len, PJ_TRUE, PJ_FALSE); 1760 if (status == PJ_EPENDING) 1761 status = PJ_SUCCESS; 1762 1763 return status; 1764 } 1765 #endif 1766 1767 1768 /* 1769 * Application wants to send outgoing packet. 1770 */ 1771 PJ_DEF(pj_status_t) pj_ice_strans_sendto2(pj_ice_strans *ice_st, 1772 unsigned comp_id, 1773 const void *data, 1774 pj_size_t data_len, 1775 const pj_sockaddr_t *dst_addr, 1776 int dst_addr_len) 1777 { 1778 ice_st->call_send_cb = PJ_TRUE; 1779 return send_data(ice_st, comp_id, data, data_len, dst_addr, 1780 dst_addr_len, PJ_TRUE, PJ_FALSE); 1781 } 1782 1598 1783 1599 1784 /* … … 1706 1891 pj_ice_strans_comp *comp; 1707 1892 pj_status_t status; 1893 void *buf = (void *)pkt; 1894 pj_bool_t use_buf = PJ_FALSE; 1708 1895 #if defined(ENABLE_TRACE) && (ENABLE_TRACE != 0) 1709 1896 char daddr[PJ_INET6_ADDRSTRLEN]; … … 1713 1900 1714 1901 PJ_ASSERT_RETURN(comp_id && comp_id <= ice_st->comp_cnt, PJ_EINVAL); 1902 1903 pj_grp_lock_acquire(ice_st->grp_lock); 1904 if (ice_st->num_buf > 0 && 1905 ice_st->send_buf[ice_st->buf_idx].buffer != pkt) 1906 { 1907 use_buf = PJ_TRUE; 1908 status = use_buffer(ice_st, comp_id, pkt, size, dst_addr, 1909 dst_addr_len, &buf); 1910 if (status == PJ_EPENDING || status != PJ_SUCCESS) { 1911 pj_grp_lock_release(ice_st->grp_lock); 1912 return status; 1913 } 1914 } 1915 pj_grp_lock_release(ice_st->grp_lock); 1715 1916 1716 1917 comp = ice_st->comp[comp_id-1]; … … 1726 1927 if (comp->turn[tp_idx].sock) { 1727 1928 status = pj_turn_sock_sendto(comp->turn[tp_idx].sock, 1728 (const pj_uint8_t*) pkt,1929 (const pj_uint8_t*)buf, 1729 1930 (unsigned)size, 1730 1931 dst_addr, dst_addr_len); … … 1742 1943 status = pj_sockaddr_synthesize(pj_AF_INET6(), 1743 1944 &comp->synth_addr, dst_addr); 1744 if (status != PJ_SUCCESS) 1745 return status; 1945 if (status != PJ_SUCCESS) { 1946 goto on_return; 1947 } 1746 1948 1747 1949 pj_sockaddr_cp(&comp->dst_addr, dst_addr); … … 1756 1958 1757 1959 status = pj_stun_sock_sendto(comp->stun[tp_idx].sock, NULL, 1758 pkt, (unsigned)size, 0,1960 buf, (unsigned)size, 0, 1759 1961 dest_addr, dest_addr_len); 1760 1962 } else { … … 1763 1965 } 1764 1966 1765 return (status==PJ_SUCCESS||status==PJ_EPENDING) ? PJ_SUCCESS : status; 1967 on_return: 1968 if (use_buf && status != PJ_EPENDING) { 1969 pj_grp_lock_acquire(ice_st->grp_lock); 1970 if (ice_st->num_buf > 0) { 1971 ice_st->buf_idx = (ice_st->buf_idx + 1) % ice_st->num_buf; 1972 pj_assert(ice_st->buf_idx == ice_st->empty_idx); 1973 } 1974 ice_st->is_pending = PJ_FALSE; 1975 pj_grp_lock_release(ice_st->grp_lock); 1976 } 1977 1978 return status; 1766 1979 } 1767 1980 … … 1784 1997 src_addr, src_addr_len); 1785 1998 } 1999 } 2000 2001 /* Notifification when asynchronous send operation via STUN/TURN 2002 * has completed. 2003 */ 2004 static pj_bool_t on_data_sent(pj_ice_strans *ice_st, pj_ssize_t sent) 2005 { 2006 if (ice_st->destroy_req || !ice_st->is_pending) 2007 return PJ_TRUE; 2008 2009 if (ice_st->call_send_cb && ice_st->cb.on_data_sent) { 2010 (*ice_st->cb.on_data_sent)(ice_st, sent); 2011 } 2012 2013 pj_grp_lock_acquire(ice_st->grp_lock); 2014 2015 if (ice_st->num_buf > 0) 2016 ice_st->buf_idx = (ice_st->buf_idx + 1) % ice_st->num_buf; 2017 2018 if (ice_st->num_buf > 0 && ice_st->buf_idx != ice_st->empty_idx) { 2019 /* There's still more pending send. Send it one by one. */ 2020 pending_send *ps = &ice_st->send_buf[ice_st->buf_idx]; 2021 2022 pj_grp_lock_release(ice_st->grp_lock); 2023 send_data(ice_st, ps->comp_id, ps->buffer, ps->data_len, 2024 &ps->dst_addr, ps->dst_addr_len, PJ_FALSE, PJ_TRUE); 2025 } else { 2026 ice_st->is_pending = PJ_FALSE; 2027 pj_grp_lock_release(ice_st->grp_lock); 2028 } 2029 2030 return PJ_TRUE; 1786 2031 } 1787 2032 … … 1845 2090 pj_ssize_t sent) 1846 2091 { 1847 PJ_UNUSED_ARG(stun_sock); 2092 sock_user_data *data; 2093 1848 2094 PJ_UNUSED_ARG(send_key); 1849 PJ_UNUSED_ARG(sent); 1850 return PJ_TRUE; 2095 2096 data = (sock_user_data *)pj_stun_sock_get_user_data(stun_sock); 2097 if (!data || !data->comp || !data->comp->ice_st) return PJ_TRUE; 2098 2099 return on_data_sent(data->comp->ice_st, sent); 1851 2100 } 1852 2101 … … 2106 2355 } 2107 2356 2357 /* Notifification when asynchronous send operation to the TURN socket 2358 * has completed. 2359 */ 2360 static pj_bool_t turn_on_data_sent(pj_turn_sock *turn_sock, 2361 pj_ssize_t sent) 2362 { 2363 sock_user_data *data; 2364 2365 data = (sock_user_data *)pj_turn_sock_get_user_data(turn_sock); 2366 if (!data || !data->comp || !data->comp->ice_st) return PJ_TRUE; 2367 2368 return on_data_sent(data->comp->ice_st, sent); 2369 } 2108 2370 2109 2371 /* Callback when TURN client state has changed */ -
pjproject/trunk/pjnath/src/pjnath/stun_sock.c
r6045 r6071 638 638 pj_sockaddr_get_len(&stun_sock->srv_addr), 639 639 tdata); 640 if (status != PJ_SUCCESS && status != PJ_EPENDING)640 if (status != PJ_SUCCESS) 641 641 goto on_error; 642 642 -
pjproject/trunk/pjnath/src/pjnath/stun_transaction.c
r5133 r6071 259 259 /* Send message */ 260 260 status = tsx->cb.on_send_msg(tsx, tsx->last_pkt, tsx->last_pkt_size); 261 if (status == PJ_EPENDING || status == PJ_EBUSY) 262 status = PJ_SUCCESS; 261 263 262 264 if (status == PJNATH_ESTUNDESTROYED) { -
pjproject/trunk/pjnath/src/pjnath/turn_session.c
r5987 r6071 1327 1327 1328 1328 sess = (pj_turn_session*) pj_stun_session_get_user_data(stun); 1329 return (*sess->cb.on_send_pkt)(sess, (const pj_uint8_t*)pkt, 1330 (unsigned)pkt_size, 1331 dst_addr, addr_len); 1329 if (*sess->cb.on_stun_send_pkt) { 1330 return (*sess->cb.on_stun_send_pkt)(sess, (const pj_uint8_t*)pkt, 1331 (unsigned)pkt_size, 1332 dst_addr, addr_len); 1333 } else { 1334 return (*sess->cb.on_send_pkt)(sess, (const pj_uint8_t*)pkt, 1335 (unsigned)pkt_size, 1336 dst_addr, addr_len); 1337 } 1332 1338 } 1333 1339 -
pjproject/trunk/pjnath/src/pjnath/turn_sock.c
r6039 r6071 94 94 95 95 pj_ioqueue_op_key_t send_key; 96 pj_ioqueue_op_key_t int_send_key; 97 unsigned pkt_len; 98 unsigned body_len; 96 99 97 100 /* Data connection, when peer_conn_type==PJ_TURN_TP_TCP (RFC 6062) */ … … 109 112 const pj_sockaddr_t *dst_addr, 110 113 unsigned dst_addr_len); 114 static pj_status_t turn_on_stun_send_pkt(pj_turn_session *sess, 115 const pj_uint8_t *pkt, 116 unsigned pkt_len, 117 const pj_sockaddr_t *dst_addr, 118 unsigned dst_addr_len); 111 119 static void turn_on_channel_bound(pj_turn_session *sess, 112 120 const pj_sockaddr_t *peer_addr, … … 136 144 pj_status_t status, 137 145 pj_size_t *remainder); 146 static pj_bool_t on_data_sent(pj_turn_sock *turn_sock, 147 pj_ioqueue_op_key_t *send_key, 148 pj_ssize_t sent); 138 149 static pj_bool_t on_connect_complete(pj_turn_sock *turn_sock, 139 150 pj_status_t status); … … 149 160 pj_status_t status, 150 161 pj_size_t *remainder); 162 static pj_bool_t on_data_sent_asock(pj_activesock_t *asock, 163 pj_ioqueue_op_key_t *send_key, 164 pj_ssize_t sent); 151 165 152 166 /* … … 168 182 pj_status_t status, 169 183 pj_size_t *remainder); 184 static pj_bool_t dataconn_on_data_sent(pj_activesock_t *asock, 185 pj_ioqueue_op_key_t *send_key, 186 pj_ssize_t sent); 170 187 static pj_bool_t dataconn_on_connect_complete(pj_activesock_t *asock, 171 188 pj_status_t status); … … 328 345 pj_bzero(&sess_cb, sizeof(sess_cb)); 329 346 sess_cb.on_send_pkt = &turn_on_send_pkt; 347 sess_cb.on_stun_send_pkt = &turn_on_stun_send_pkt; 330 348 sess_cb.on_channel_bound = &turn_on_channel_bound; 331 349 sess_cb.on_rx_data = &turn_on_rx_data; … … 628 646 return PJ_EINVALIDOP; 629 647 648 /* TURN session may add some headers to the packet, so we need 649 * to store our actual data length to be sent here. 650 */ 651 turn_sock->body_len = pkt_len; 630 652 return pj_turn_session_sendto(turn_sock->sess, pkt, pkt_len, 631 653 addr, addr_len); … … 694 716 /* Init send_key */ 695 717 pj_ioqueue_op_key_init(&turn_sock->send_key, sizeof(turn_sock->send_key)); 718 pj_ioqueue_op_key_init(&turn_sock->int_send_key, 719 sizeof(turn_sock->int_send_key)); 696 720 697 721 /* Send Allocate request */ … … 861 885 } 862 886 887 static pj_bool_t on_data_sent(pj_turn_sock *turn_sock, 888 pj_ioqueue_op_key_t *send_key, 889 pj_ssize_t sent) 890 { 891 unsigned header_len, sent_size; 892 893 /* Don't report to callback if this is internal message. */ 894 if (send_key == &turn_sock->int_send_key) { 895 return PJ_TRUE; 896 } 897 898 if (turn_sock->cb.on_data_sent) { 899 /* Remove the length of packet header from sent size. */ 900 header_len = turn_sock->pkt_len - turn_sock->body_len; 901 sent_size = (sent > header_len)? (sent - header_len) : 0; 902 (*turn_sock->cb.on_data_sent)(turn_sock, sent_size); 903 } 904 905 return PJ_TRUE; 906 } 907 908 909 static pj_bool_t on_data_sent_asock(pj_activesock_t *asock, 910 pj_ioqueue_op_key_t *send_key, 911 pj_ssize_t sent) 912 { 913 pj_turn_sock *turn_sock; 914 915 turn_sock = (pj_turn_sock*)pj_activesock_get_user_data(asock); 916 917 return on_data_sent(turn_sock, send_key, sent); 918 } 919 920 863 921 #if PJ_HAS_SSL_SOCK 864 922 static pj_bool_t on_data_read_ssl_sock(pj_ssl_sock_t *ssl_sock, … … 897 955 } 898 956 899 return PJ_TRUE;957 return on_data_sent(turn_sock, op_key, bytes_sent); 900 958 } 901 959 #endif 902 960 903 /* 904 * Callback from TURN session to send outgoing packet. 905 */ 906 static pj_status_t turn_on_send_pkt(pj_turn_session *sess, 907 const pj_uint8_t *pkt, 908 unsigned pkt_len, 909 const pj_sockaddr_t *dst_addr, 910 unsigned dst_addr_len) 961 962 static pj_status_t send_pkt(pj_turn_session *sess, 963 pj_bool_t internal, 964 const pj_uint8_t *pkt, 965 unsigned pkt_len, 966 const pj_sockaddr_t *dst_addr, 967 unsigned dst_addr_len) 911 968 { 912 969 pj_turn_sock *turn_sock = (pj_turn_sock*) … … 914 971 pj_ssize_t len = pkt_len; 915 972 pj_status_t status = PJ_SUCCESS; 973 pj_ioqueue_key_t *send_key = &turn_sock->send_key; 916 974 917 975 if (turn_sock == NULL || turn_sock->is_destroying) { … … 922 980 } 923 981 982 if (internal) 983 send_key = &turn_sock->int_send_key; 984 turn_sock->pkt_len = pkt_len; 985 924 986 if (turn_sock->conn_type == PJ_TURN_TP_UDP) { 925 987 status = pj_activesock_sendto(turn_sock->active_sock, 926 &turn_sock->send_key, pkt, &len, 0,988 send_key, pkt, &len, 0, 927 989 dst_addr, dst_addr_len); 928 990 } else if (turn_sock->alloc_param.peer_conn_type == PJ_TURN_TP_TCP) { … … 932 994 /* Destination address is TURN server */ 933 995 status = pj_activesock_send(turn_sock->active_sock, 934 &turn_sock->send_key, pkt, &len, 0);996 send_key, pkt, &len, 0); 935 997 } else { 936 998 /* Destination address is peer, lookup data connection */ … … 952 1014 } else if (turn_sock->conn_type == PJ_TURN_TP_TCP) { 953 1015 status = pj_activesock_send(turn_sock->active_sock, 954 &turn_sock->send_key, pkt, &len, 0);1016 send_key, pkt, &len, 0); 955 1017 } 956 1018 #if PJ_HAS_SSL_SOCK 957 1019 else if (turn_sock->conn_type == PJ_TURN_TP_TLS) { 958 1020 status = pj_ssl_sock_send(turn_sock->ssl_sock, 959 &turn_sock->send_key, pkt, &len, 0);1021 send_key, pkt, &len, 0); 960 1022 } 961 1023 #endif … … 969 1031 970 1032 return status; 1033 } 1034 1035 1036 /* 1037 * Callback from TURN session to send outgoing packet. 1038 */ 1039 static pj_status_t turn_on_send_pkt(pj_turn_session *sess, 1040 const pj_uint8_t *pkt, 1041 unsigned pkt_len, 1042 const pj_sockaddr_t *dst_addr, 1043 unsigned dst_addr_len) 1044 { 1045 return send_pkt(sess, PJ_FALSE, pkt, pkt_len, 1046 dst_addr, dst_addr_len); 1047 } 1048 1049 static pj_status_t turn_on_stun_send_pkt(pj_turn_session *sess, 1050 const pj_uint8_t *pkt, 1051 unsigned pkt_len, 1052 const pj_sockaddr_t *dst_addr, 1053 unsigned dst_addr_len) 1054 { 1055 return send_pkt(sess, PJ_TRUE, pkt, pkt_len, 1056 dst_addr, dst_addr_len); 971 1057 } 972 1058 … … 1170 1256 pj_bzero(&asock_cb, sizeof(asock_cb)); 1171 1257 asock_cb.on_data_read = &on_data_read_asock; 1258 asock_cb.on_data_sent = &on_data_sent_asock; 1172 1259 asock_cb.on_connect_complete = &on_connect_complete_asock; 1173 1260 status = pj_activesock_create(turn_sock->pool, sock, … … 1399 1486 } 1400 1487 1488 static pj_bool_t dataconn_on_data_sent(pj_activesock_t *asock, 1489 pj_ioqueue_op_key_t *send_key, 1490 pj_ssize_t sent) 1491 { 1492 tcp_data_conn_t *conn = (tcp_data_conn_t*) 1493 pj_activesock_get_user_data(asock); 1494 pj_turn_sock *turn_sock = conn->turn_sock; 1495 1496 return on_data_sent(turn_sock, send_key, sent); 1497 } 1498 1401 1499 static pj_bool_t dataconn_on_connect_complete(pj_activesock_t *asock, 1402 1500 pj_status_t status) … … 1577 1675 pj_bzero(&asock_cb, sizeof(asock_cb)); 1578 1676 asock_cb.on_data_read = &dataconn_on_data_read; 1677 asock_cb.on_data_sent = &dataconn_on_data_sent; 1579 1678 asock_cb.on_connect_complete = &dataconn_on_connect_complete; 1580 1679 status = pj_activesock_create(pool, sock, -
pjproject/trunk/pjnath/src/pjturn-client/client_main.c
r3553 r6071 479 479 &peer->mapped_addr, 480 480 pj_sockaddr_get_len(&peer->mapped_addr)); 481 if (status != PJ_SUCCESS )481 if (status != PJ_SUCCESS && status != PJ_EPENDING) 482 482 my_perror("turn_udp_sendto() failed", status); 483 483 break; -
pjproject/trunk/pjsip-apps/src/samples/footprint.c
r6035 r6071 223 223 pj_ice_strans_start_ice(NULL, NULL, NULL, 0, NULL); 224 224 pj_ice_strans_stop_ice(NULL); 225 pj_ice_strans_sendto (NULL, 0, NULL, 0, NULL, 0);225 pj_ice_strans_sendto2(NULL, 0, NULL, 0, NULL, 0); 226 226 #endif 227 227 -
pjproject/trunk/pjsip-apps/src/samples/icedemo.c
r4624 r6071 994 994 } 995 995 996 status = pj_ice_strans_sendto (icedemo.icest, comp_id, data, strlen(data),997 &icedemo.rem.def_addr[comp_id-1],998 pj_sockaddr_get_len(&icedemo.rem.def_addr[comp_id-1]));999 if (status != PJ_SUCCESS )996 status = pj_ice_strans_sendto2(icedemo.icest, comp_id, data, strlen(data), 997 &icedemo.rem.def_addr[comp_id-1], 998 pj_sockaddr_get_len(&icedemo.rem.def_addr[comp_id-1])); 999 if (status != PJ_SUCCESS && status != PJ_EPENDING) 1000 1000 icedemo_perror("Error sending data", status); 1001 1001 else 1002 PJ_LOG(3,(THIS_FILE, "Data sent "));1002 PJ_LOG(3,(THIS_FILE, "Data sent/will be sent")); 1003 1003 } 1004 1004
Note: See TracChangeset
for help on using the changeset viewer.