2013-03-06 71 views
0

我有这部分代码:如果条件不工作

void query(hash_t* params) { 
record_t* rec; 

// Coordinator, opgroup and Opcode specified by the client 
uint64_t netid = 0; 
uint8_t op_code_group = 0; 
uint8_t op_code = 0; 
char* par; 
now = mdl_now(); 
/* set the start and end time based on query parameters */ 
........... 
// Network id is required 
par = hash_get(params, "netid"); 
........... 
netid = strtoull(par, NULL, 10); 
par = hash_get(params, "opcode_group"); 
........... 
op_code_group = strtoul(par, NULL, 10); 
par = hash_get(params, "opcode"); 
........... 
op_code = strtoul(par, NULL, 10); 
/* seek in the bytestream */ 
mdl_seek(start); 
while((rec = (record_t*) mdl_next(&ts)) != NULL) { 
    ............... 
    // Only print records with the wanted net and opcodes 
    if((netid != 0) && (netid != NTOHLL(rec->net_id))) 
     continue; 
    if((opcode_group != 0) && (op_code_group != ntohl(rec->opcode_group))) 
     continue; 
    if((opcode != 0) && (op_code != ntohl(rec->opcode))) 
     continue; 
    .............. 
    mdl_print("%u %llu %u %u %u %d\n", 
     sec, 
     NTOHLL(rec->net_id), 
     rec->op_code_group, 
     rec->op_code, 
     rec->payloadlength, 
     val); 
    } 
} 

opcode_group,操作码和其它参数传递到通过http请求的查询类。

这是一个问题: 如果我指定一个opcode_group例如= 160,结果不会显示任何东西。相反,如果我指定opcode_group = 0(所有记录),结果会显示所有记录,包括opcode_group = 160的记录。

错误在哪里?非常感谢你。

+0

现在将开始学习如何使用调试器的好时机。 – 2013-03-06 12:23:25

+0

调试器非常善于帮助您查找错误。用它! – 2013-03-06 12:23:30

+0

你可以说我是CentOS的调试器吗?我不知道该怎么做... – sharkbait 2013-03-06 12:24:25

回答

1

我可以看到代码,发现只有在变量所获得的价值 “op_code_group”,而不是 “opcode_group

op_code_group = strtoul(par, NULL, 10); 

我相信乌尔搞乱类似的变量

_EDITED_ _ __ _ __

我相信问题是这部分

if((opcode_group != 0) && (op_code_group != ntohl(rec->opcode_group))) 
    continue;" 

这部分将失败并打印仅当opcode_group == 0

修改这

if((opcode_group == 0) || (op_code_group != ntohl(rec->opcode_group))) 
    continue;" 

猜猜乌尔面临的纪录与netid和op_code相同的probs

+0

在以前的版本中,变量和参数都是opcode_group和opcode。接下来我想这个问题是同名的,所以我改变了op_code_group和op_code中的局部变量。但问题并没有解决。 – sharkbait 2013-03-06 12:34:55

+0

@sharkbait请找到编辑答案 – hazzelnuttie 2013-03-06 12:48:42

+0

不起作用。你的解决方案不再显示任何东西。此外,当我用这个http请求调用类http://131.114.52.207:44444/ztc_config?netid=0&opcode_group=0&opcode=0&start=-20s&end=-1s,应该显示流中的每个记录 – sharkbait 2013-03-06 12:59:08