twemproxy源码分析之五:zero copy

先给出msg的数据结构:

 
truct msg {
    TAILQ_ENTRY(msg)     c_tqe;          
    TAILQ_ENTRY(msg)     s_tqe;          
    TAILQ_ENTRY(msg)     m_tqe;          
 
    uint64_t             id;              
    int                  route_idx;      
    struct msg           *peer;          
    struct conn          *owner;          
 
    struct rbnode        tmo_rbe;        
 
    struct mhdr          mhdr;            
    uint32_t             mlen;            
 
    int                  state;          
    uint8_t              *pos;            
    uint8_t              *token;          
 
    msg_parse_t          parser;          
    msg_parse_result_t   result;          
 
    mbuf_copy_t          pre_splitcopy;  
    msg_post_splitcopy_t post_splitcopy;  
    msg_coalesce_t       pre_coalesce;    
    msg_coalesce_t       post_coalesce;  
 
    msg_type_t           type;            
 
    uint8_t              *key_start;      
    uint8_t              *key_end;        
 
    uint32_t             vlen;            
    uint8_t              *end;            
 
    uint8_t              *narg_start;    
    uint8_t              *narg_end;      
    uint32_t             narg;            
    uint32_t             rnarg;          
    uint32_t             rlen;            
    uint32_t             integer;        
 
    struct msg           *frag_owner;    
    uint32_t             nfrag;          
    uint64_t             frag_id;        
 
    err_t                err;            
    unsigned             error:1;        
    unsigned             ferror:1;        
    unsigned             request:1;      
    unsigned             quit:1;          
    unsigned             noreply:1;      
    unsigned             done:1;          
    unsigned             fdone:1;        
    unsigned             first_fragment:1;
    unsigned             last_fragment:1;
    unsigned             swallow:1;      
    unsigned             redis:1;        
 
 
看这三个成员   
    TAILQ_ENTRY(msg)     c_tqe;          
    TAILQ_ENTRY(msg)     s_tqe;          
    TAILQ_ENTRY(msg)     m_tqe;          
c_tqe是用来插入到client类型的conn中的输入或者输出队列中
s_tqe是用来插入到server类型的conn(即连接后端redis server的conn)中的输入或者输出队列中
m_tqe是用来插入到发送对列(一个发送队列对应一个远端或是client或是redisinstance)中的输入或者输出队列中
具体的插入删除过程见上一篇。
posted on 2014-12-10 18:06  junesmile  阅读(315)  评论(0编辑  收藏  举报