Bug 1290365: add TURN TCP socket to read poll after connect. r=bwc

MozReview-Commit-ID: FLITvQCt9Xq

--HG--
extra : rebase_source : 8346b3b8e1655882584bdf1a60a8af75fc1da1bf
This commit is contained in:
Nils Ohlmeier [:drno] 2016-08-02 10:58:55 -07:00
parent 1bb234e764
commit b3a05a317c
3 changed files with 43 additions and 2 deletions

View File

@ -39,6 +39,7 @@ static char *RCSSTRING __UNUSED__="$Id: ice_socket.c,v 1.2 2008/04/28 17:59:01 e
#include "nr_api.h"
#include "ice_ctx.h"
#include "stun.h"
#include "nr_socket_buffered_stun.h"
#include "nr_socket_multi_tcp.h"
static void nr_ice_socket_readable_cb(NR_SOCKET s, int how, void *cb_arg)
@ -221,12 +222,17 @@ int nr_ice_socket_create(nr_ice_ctx *ctx,nr_ice_component *comp, nr_socket *nsoc
TAILQ_INIT(&sock->candidates);
TAILQ_INIT(&sock->stun_ctxs);
if (sock->type != NR_ICE_SOCKET_TYPE_STREAM_TCP){
if (sock->type == NR_ICE_SOCKET_TYPE_DGRAM){
if((r=nr_socket_getfd(nsock,&fd)))
ABORT(r);
NR_ASYNC_WAIT(fd,NR_ASYNC_WAIT_READ,nr_ice_socket_readable_cb,sock);
}
else {
else if (sock->type == NR_ICE_SOCKET_TYPE_STREAM_TURN) {
/* some OS's (e.g. Linux) don't like to see un-connected TCP sockets in
* the poll socket set. */
nr_socket_buffered_stun_set_readable_cb(nsock,nr_ice_socket_readable_cb,sock);
}
else if (sock->type == NR_ICE_SOCKET_TYPE_STREAM_TCP) {
/* in this case we can't hook up using NR_ASYNC_WAIT, because nr_socket_multi_tcp
consists of multiple nr_sockets and file descriptors. */
if((r=nr_socket_multi_tcp_set_readable_cb(nsock,nr_ice_socket_readable_cb,sock)))

View File

@ -66,6 +66,8 @@ typedef struct nr_socket_buffered_stun_ {
size_t buffer_size;
size_t bytes_needed;
size_t bytes_read;
NR_async_cb readable_cb;
void *readable_cb_arg;
/* Write state */
nr_p_buf_ctx *p_bufs;
@ -104,6 +106,15 @@ static nr_socket_vtbl nr_socket_buffered_stun_vtbl={
nr_socket_buffered_stun_accept
};
void nr_socket_buffered_stun_set_readable_cb(nr_socket *sock,
NR_async_cb readable_cb, void *readable_cb_arg)
{
nr_socket_buffered_stun *buf_sock = (nr_socket_buffered_stun *)sock->obj;
buf_sock->readable_cb = readable_cb;
buf_sock->readable_cb_arg = readable_cb_arg;
}
int nr_socket_buffered_set_connected_to(nr_socket *sock, nr_transport_addr *remote_addr)
{
nr_socket_buffered_stun *buf_sock = (nr_socket_buffered_stun *)sock->obj;
@ -405,14 +416,35 @@ static int nr_socket_buffered_stun_accept(void *obj, nr_transport_addr *addrp, n
static void nr_socket_buffered_stun_connected_cb(NR_SOCKET s, int how, void *arg)
{
nr_socket_buffered_stun *sock = (nr_socket_buffered_stun *)arg;
int r, _status;
assert(!sock->connected);
sock->connected = 1;
// once connected arm for read
if (sock->readable_cb) {
NR_SOCKET fd;
/* don't use |s| directly here because the NAT emulator depends on handing
you its implementation here. */
if ((r=nr_socket_getfd(sock->inner, &fd)))
ABORT(r);
NR_ASYNC_WAIT(fd, NR_ASYNC_WAIT_READ, sock->readable_cb, sock->readable_cb_arg);
}
if (sock->pending) {
r_log(LOG_GENERIC, LOG_INFO, "Invoking writable_cb on connected (%u)", (uint32_t) sock->pending);
nr_socket_buffered_stun_writable_cb(s, how, arg);
}
_status=0;
abort:
if (_status) {
r_log(LOG_GENERIC, LOG_ERR, "Failure in nr_socket_buffered_stun_connected_cb: %d", _status);
}
}
static int nr_socket_buffered_stun_connect(void *obj, nr_transport_addr *addr)

View File

@ -51,6 +51,9 @@ typedef enum {
ICE_TCP_FRAMING
} nr_framing_type;
void nr_socket_buffered_stun_set_readable_cb(nr_socket *sock,
NR_async_cb readable_cb, void *readable_cb_arg);
int nr_socket_buffered_stun_create(nr_socket *inner, int max_pending,
nr_framing_type framing_type, nr_socket **sockp);