Skip to content

Commit

Permalink
Block 5 sec when gather candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
sepfy committed Sep 14, 2023
1 parent 77aff6b commit f67472f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ static int agent_create_bind_addr(Agent *agent, Address *serv_addr) {
StunMessage recv_msg;
UdpSocket udp_socket;
udp_socket_open(&udp_socket);
// blocking 5s
udp_blocking_timeout(&udp_socket, 5000);

memset(&send_msg, 0, sizeof(send_msg));

Expand Down Expand Up @@ -74,7 +76,8 @@ static int agent_create_turn_addr(Agent *agent, Address *serv_addr, const char *
StunMessage recv_msg;
UdpSocket udp_socket;
udp_socket_open(&udp_socket);

// blocking 5s
udp_blocking_timeout(&udp_socket, 5000);
memset(&send_msg, 0, sizeof(send_msg));
stun_msg_create(&send_msg, STUN_METHOD_ALLOCATE);
stun_msg_write_attr(&send_msg, STUN_ATTR_REQUESTED_TRANSPORT, sizeof(attr), (char*)&attr); // UDP
Expand All @@ -92,11 +95,10 @@ static int agent_create_turn_addr(Agent *agent, Address *serv_addr, const char *
memset(&recv_msg, 0, sizeof(recv_msg));
ret = udp_socket_recvfrom(&udp_socket, serv_addr, recv_msg.buf, sizeof(recv_msg.buf));

if (ret == -1) {
LOGD("Failed to receive STUN Binding Response.");
if (ret <= 0) {
LOGE("Failed to receive STUN Binding Response.");
break;
}

stun_parse_msg_buf(&recv_msg);

if (recv_msg.stunclass == STUN_CLASS_ERROR && recv_msg.stunmethod == STUN_METHOD_ALLOCATE) {
Expand Down

0 comments on commit f67472f

Please sign in to comment.