How does work TLS function in Asterisk?

Forexample i created 2 different chan_sip extensions and chan_sip is listening 5061. And TLS port is 5062.
When sip user agents send to packet with TLS or without TLS. How does behave chan_sip module? Chan_sip module listens 2 different ports?(Encrypted trafic:5062, unencrypted traffic:5061).
If encrypted user agent sends to packet chan_sip module so how does prosess is managed? I mean chan_sip ask to asterik “solve this messages for me” than asterisk replies chan_sip module? Asterisk uses another module for solving encrypted message?Or chan_sip module directly contact with another module(SRTP module or like this…)

What problem are you trying to solve.

Asterisk listens on both the secure and insecure ports, using standard socket operations that open a new socket for each accepted connection… Requests are then passed into code shared across all transports. If possible, replies are sent over the connection on which the request was received, as are in dialogue requests in the reverse direction.

For any more detail, you should use developer resources. This is an end user forum.