⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tport.docs

📁 this is simple sip stack.
💻 DOCS
字号:
/**@mainpage Transport Module@section tport_meta Module InformationThe @b tport module contains a generic transport interface used by SIP,RTSP, and HTTP protocols. It is an abstraction layer between a protocolstack and a transport protocol implementation. The interface isimplemented via transport objects.@CONTACT Pekka.Pessi@nokia.com@LICENSE LGPL@section tp_primary Master, Primary and Secondary Transport ObjectsA transport object can be used in three roles. Master transport objectrepresents all available transport. It is used to store stack and rootinterface as well as common data such as SigComp state handler. The primarytransport objects represent available transports. The secondary transportsrepresent actual transport connections.A protocol stack first creates a @e master @e transport object and binds anumber of primary transport objects (each representing a transport protocolsuch as UDP, TCP, TLS/TCP, SCTP, etc). The binding process creates a newprimary transport object for each transport supported. If the protocol stackis used as a server, the binding process also creates the necessary serversockets and binds them to the specified server ports.Secondary transport objects are created for each transport-levelconnection. The @b tport module takes care of automatically creating themand discarding them when they are no more used. The secondary transportobjects are required to transmit messages when a connection-orientedtransport protocol is used.A secondary transport object can be created for two reasons. A server mayaccept a new connection from a client, or a client may connect to aserver. When the connection belonging to a secondary transport has beenestablished, the protocol stack can send or receive messages through it.@section tp_init Initializing TransportsWhen the primary transport object is created with tport_tcreate(), theprotocol stack must pass a #tport_stack_class_t structure containingfunction pointers to the new transport object. These function pointersare used to-# create new message objects used to store received messages-# pass received messages to the protocol stack, and-# report transport errors to the protocol stack.The transport protocols are bound to the primary transport objects withthe method tport_tbind(). The protocol stack gives the desired servertransport name (transport name is a structure containing a text-formattedsocket address along with transport name) along with the list oftransport protocols supported by the stack. The function tport_tbind()can be called multiple times, if, for example, the server port(s) used bytransport protocol differ (for example, default TCP port for SIP is 5060,and default TLS port is 5061).@subsection tp_connect Connection-Oriented and Connection-Less TransportsA secondary transport objects is created for each transport-levelconnection. The tport module takes care of automatically creating them,and discarding them when they are no more used. The secondary transportobjects are required to transmit messages when a connection-orientedtransport protocol is used.A secondary transport can be created for two reasons. A server may accepta new connection from a client, or a client may connect to a server. Whenthe connection belonging to a secondary transport has been established,the protocol stack can send or receive messages through it.@par Connection-Oriented and Connection-Less TransportsA transport can be connection-oriented (TCP, SCTP) or connectionless(UDP). A connection-oriented transport needs a connection to beestablished before messages can be sent. It can also send messages onlyto a single destination. For a connectionless transport, a destinationaddress must always be given.A connectionless transport can be used to send messages to severaldistinct destinations. The destination address must be given to thekernel whenever a message is sent using connectionless transport.Note that UDP can be used in connection-oriented manner (client does notuse sendto(), but connect() and then send()), if tport_set_params() iscalled with TPTAG_CONNECT(1) argument.@subsection tp_stream Stream and Datagram TransportsA connection-oriented transport can also be stream-based (TCP, SCTP) orpacket-based (UDP, SCTP). A stream-based transport protocol takes care ofordering the data within a stream, a data chunk sent earlier is alwaysdelivered before chunks sent after it. A packet-based transport deliversdata chunks independent of each other and does not maintain the relativeorder, for instance, if a data chunk is lost by the network and thenretransmitted, application can receive it later than a data chunk thatwas sent after lost one but did not need any retransmissions.@subsection tp_magic Transport Magic Transport magic is a cookie, a piece of data specified by stack that canbe associated with a transport (e.g., a Via header). The protocol stackcan change the type of transport magic by defining the macro#TP_MAGIC_T before including <tport.h>.@section tp_op Transport Operations@subsection tp_send Sending MessagesA message can be sent by the tport_tsend() method. The method can becalled either from the primary or from the secondary transport. If asecondary transport is needed to send the message, it is created andconnected automatically.The transport gets the data to be sent from the message object withmsg_iovec() call. The transport tries to send all the data using onesu_vsend() call. If the call would fail, for instance, because the sendbuffer is too short, the transport object would create a reference to themessage and queue it in its own queue.@subsection tp_recv Receiving MessagesWhen a primary connectionless transport object or a secondary transportobject receives new data, it allocates a new message object. The messageobject is created using the factory function tpac_alloc() provided by theprotocl stack. The incoming data is passed to the message object, data isparsed and when a message is complete, it is passed to the applicationusing the tpac_recv() function provided when the transport was created.@subsection tp_refcnt Reference CountingIn order to destroy unused connections, each secondary transport objectneeds to know if there is a reference to it from the stack. A protocolstack creates a reference to a transport when it receives an incomingrequest and needs to send the response using the same transport, or whenit expects a reply from the server coming on the connection used to sendthe request.@note While the reference counting has been implemented in the tportmodule, the transport objects are not destroyed by timers by default asall the protocol stacks do @b not properly handle the reference counting. Timers are activated when the tag TPTAG_IDLE() is used.@subsection tp_pend Pending RequestsThe protocol stack can mark requests as @e pending using tport_pend()function. The tport_pend() function associates a request message with acallback and a handle to a client object. When a transport error occurs,it is reported to the client object using the associated callbackfunction.When the stack receives a response to the request it has marked aspending, it calls tport_release(). The request can be still consideredpending, if the response was a preliminary one. In this case, the @astill_pending argument is true. The function tport_release() is alsocalled without response message, if the stack is no more interested inthe response, for instance, after a timeout.@subsection tp_queue Send QueueEach stream-based transport also supports send queue. The queue can beused either to queue messages during congestion, or to maintain therelative ordering of responses. Usually, queue is used implicitly for thefirst purpose, e.g., if a transport is busy sending a message it queuesfurther messages when tport_tsend() is called.Explicit queueing is needed when the protocol (like HTTP/1.1) requiresthat the relative order of responses is maintained. When the protocolstack receives a request, it queues an empty response message to thetransport with tport_tqueue(). Such an empty response is marked asincomplete, not ready to send. When application responds to the requestvia tport_tqsend(), the transport object marks the message ready to sendand, if there are no other queued responses before it, sends it.@section tp_debug Logging and Dumping MessagesSeeing message contents and network events is extremely useful whendebugging protocols. There are environment variables that are used toactivate message logging within @b tport module.<dl compact><dt>@b #TPORT_LOG   <dd>if set, tport module prints out the message contents        after parsing<dt>@b #TPORT_DUMP   <dd>contains dump file name - incoming data is written       dump file @e before parsing <dt>@b #TPORT_DEBUG   <dd>integer in range -1..9 controlling amount of       debugging printout from @b tport module. See also #tport_log.</dl> */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -