コード例 #1
0
ファイル: ydb_storage_syncquery.c プロジェクト: xvhfeng/ydb
spx_private void ydb_storage_syncquery_nio_body_reader(int fd,
        struct spx_job_context *jc){/*{{{*/
    spx_nio_reader_body_handler(fd,jc);
    if(ENOENT == jc->err){
        SpxLog1(jc->log,SpxLogWarn,\
                "not find out the sync storages.");
        goto r1;
    }

    if(0 != jc->err){

        SpxLog2(jc->log,SpxLogError,jc->err,\
                "recv the regedit response is fail.");
        goto r1;
    }

    struct spx_msg *ctx = jc->reader_body_ctx;
    if(NULL == ctx){
        SpxLog2(jc->log,SpxLogError,jc->err,\
                "no recved the body ctx.");
        goto r1;
    }

    struct ydb_storage_slave *s = NULL;
     size_t unit_size = YDB_MACHINEID_LEN + SpxIpv4Size
                        + SpxI32Size + SpxI32Size;
     size_t numbs = jc->reader_header->bodylen / unit_size;
     size_t i = 0;
     for( ; i < numbs; i++){
        string_t machineid = spx_msg_unpack_string(ctx,YDB_MACHINEID_LEN,&(jc->err));
        string_t ip = spx_msg_unpack_string(ctx,SpxIpv4Size,&(jc->err));
        i32_t port = spx_msg_unpack_i32(ctx);
        u32_t status = spx_msg_unpack_u32(ctx);
        spx_map_get(g_ydb_storage_slaves,machineid,spx_string_len(machineid),\
                (void **) &s,NULL);
        if(NULL == s){
            s = spx_alloc_alone(sizeof(*s),&(jc->err));
            if(NULL == s){
                continue;
            }
            s->state = status;
            s->machineid = machineid;
            s->host.port = port;
            s->host.ip = ip;
            spx_map_insert(g_ydb_storage_slaves,machineid,spx_string_len(machineid),
                    s,sizeof(s));
        }
        if(port != s->host.port){
            s->host.port = port;
        }
        if(0 != spx_string_casecmp_string(machineid,s->machineid)){
            spx_string_free(s->machineid);
            s->machineid = machineid;
        }
        s->state = status;

     }
r1:
    spx_job_context_clear(jc);
}/*}}}*/
コード例 #2
0
ファイル: spx_message.c プロジェクト: alxbean/dfs
struct spx_msg_header *spx_msg_to_header(struct spx_msg *ctx,err_t *err){/*{{{*/
    struct spx_msg_header *header = NULL;
    if(NULL == ctx){
        *err = EINVAL;
        return NULL;
    }

    header = spx_alloc_alone(sizeof(*header),err);
    if(NULL == header){
        return NULL;
    }
    header->version = spx_msg_unpack_u32(ctx);
    header->protocol = spx_msg_unpack_u32(ctx);
    header->bodylen = spx_msg_unpack_u64(ctx);
    header->offset = spx_msg_unpack_u64(ctx);
    header->is_keepalive = spx_msg_unpack_bool(ctx);
    header->err = spx_msg_unpack_u32(ctx);
    return header;
}/*}}}*/