翻譯-pjsip開發者指南(五)消息緩衝區

 Chapter 5:Message Buffers

 5.1 Receive Data Buffer
PJSIP收到的SIP消息將以pjsip_rx_data傳遞給PJSIP的軟件組件,而不是普通消息。這個結構體包含了收到消息的所有信息描述。
收到和傳輸數據緩衝區的描述在頭文件 <pjsip/sip_transport.h>。
 5.1.1 Receive Data Buffer Structure

struct pjsip_rx_data
{
// This part contains static info about the buffer.
struct
{
    pj_pool_t *pool; // Pool owned by this buffer
    pjsip_transport *transport; // The transport that received the msg.
    pjsip_rx_data_op_key op_key; // Ioqueue’s operation key
} tp_info;
// This part contains information about the packet
struct
{
    pj_time_val timestamp; // Packet arrival time
    char packet[PJSIP_MAX_PKT_LEN]; // The packet buffer
    pj_uint32_t zero; // Zero padding.
    int len; // Packet length
    pj_sockaddr addr; // Source address
    int addr_len; // Address length.
} pkt_info;
// This part describes the message and message elements after parsing.
struct
{
    char *msg_buf; // Pointer to start of msg in the buf.
    int len; // Message length.
    pjsip_msg *msg; // The parsed message.
// Shortcut to important headers:
    pj_str_t call_id; // Call-ID string.
    pjsip_from_hdr *from; // From header.
    pjsip_to_hdr *to; // To header.
    pjsip_via_hdr *via; // First Via header.
    pjsip_cseq_hdr *cseq; // CSeq header.
    pjsip_max_forwards_hdr *max_fwd; // Max-Forwards header.
    pjsip_route_hdr *route; // First Route header.
    pjsip_rr_hdr *record_route; // First Record-Route header.
    pjsip_ctype_hdr *ctype; // Content-Type header.
    pjsip_clen_hdr *clen; // Content-Length header.
    pjsip_require_hdr *require; // The first Require header.
    pjsip_parser_err_report parse_err; // List of parser errors.
} msg_info;
// This part is updated after the rx_data reaches endpoint.
struct
{
    pj_str_t key; // Transaction key.
void *mod_data[PJSIP_MAX_MODULE]; // Module specific data.
} endpt_info;
};


 5.2 Transmit Data Buffer (pjsip_tx_data)
當PJSIP應用程序想要發送傳出(outgoing)消息時,必須建立一個傳輸數據緩衝區,提供一個內存池,所有消息相關的字段都必須從這裏面分配,傳輸層處理消息需要的引用計數器,鎖保護和其他的消息。

struct pjsip_tx_data
{
    /** This is for transmission queue; it's managed by transports. */
    PJ_DECL_LIST_MEMBER(struct pjsip_tx_data);
    /** Memory pool for this buffer. */
    pj_pool_t *pool;
    /** A name to identify this buffer. */
    char obj_name[PJ_MAX_OBJ_NAME];
    /** Time of the rx request; set by pjsip_endpt_create_response(). */
    pj_time_val rx_timestamp;
    /** The transport manager for this buffer. */
    pjsip_tpmgr *mgr;
    /** Ioqueue asynchronous operation key. */
    pjsip_tx_data_op_key op_key;
    /** Lock object. */
    pj_lock_t *lock;
    /** The message in this buffer. */
    pjsip_msg *msg;
    /** Contigous buffer containing the packet. */
    pjsip_buffer buf;
    /** Reference counter. */
    pj_atomic_t *ref_cnt;
    /** Being processed by transport? */
    int is_pending;
    /** Transport manager internal. */
    void *token;
    void (*cb)(void*, pjsip_tx_data*, pj_ssize_t);
    /** Transport info, only valid during on_tx_request() and on_tx_response() */
    struct {
        pjsip_transport *transport; /**< Transport being used. */
        pj_sockaddr dst_addr; /**< Destination address. */
        int dst_addr_len; /**< Length of address. */
        char dst_name[16]; /**< Destination address. */
        int dst_port; /**< Destination port. */
    } tp_info;
};


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章