[Turn] Exosip2-5.1.0 TCP transmission method use excerpt

1. Random problem with the port used to send messages using TCP
  : The port is not fixed when using exosip2 to actively send TCP messages;
code analysis:
  First, there are two sources of sock for sending data in TCP mode in exoisp2 (eXtl_tcp.c):

"1", the sockets returned by the accept function in the tcp_tl_read_message function, up to 200;

Insert picture description here

This is a passive connection as a server, and the returned port number of the sock binding is set by us with eXosip_listen_addr;

"2", the newly established socket when the TCP connection is initiated actively;

Insert picture description here
Create a new socket in _tcp_tlconnect_socket but there is an if judgment to decide whether to perform port binding, the judgment is as follows:

[External link image transfer failed (img-sZBtuQMl-1564657065526)(en-resource://database/3076:1)]
If there is no port binding, a port number will be randomly selected, which is the problem.

The setting of ai_addr_len in the judgment condition is set in tcp_tl_open, but there is a macro that controls it, which is undefined by default, as follows:

Insert picture description here
So if the macro is turned on, we can use the port number we set to send data, but the function of the macro ENABLE_MAIN_SOCKET is not mentioned, so I don’t know what effect it will have after it is turned on. eXtl_tls.c says to prevent insecure tls connections, and it feels like it has nothing to do with tcp.

Insert picture description here
2. Additional settings
  need to set the sock in eXtl_tcp.c to SO_REUSEADDR, and then add SO_REUSEPORT on this basis, otherwise the sock for sending the message will fail to be created.

setsockopt (sock, SOL_SOCKET, SO_REUSEPORT, (void *) &valopt, sizeof (valopt));
1
3、结果:

Insert picture description here

————————————————
Copyright statement: This article is the original article of the CSDN blogger "King log", and it follows the CC 4.0 BY-SA copyright agreement. Please attach the original source link and the copy statement.
Original link: https://blog.csdn.net/fpgatom/article/details/98090458

Guess you like

Origin blog.csdn.net/gouguofei/article/details/104002934