这个函数不用goto怎么改
程序代码:
static char mysh_recv_data(char data[], char endata[], unsigned *size, unsigned (*recv)(void *, unsigned), unsigned (*send)(const void *, unsigned)) { unsigned sz, len, n; unsigned need, max_size; char *p, *e, *begin, c; len = sz = 0; begin = endata; max_size = MYSH_EN_DATA_BLOCK_SIZE; goto lab_skip_get_header; while(1) { /* lab_get_header */ begin = endata; c = mysh_send_cmd(C_RETRY, send); if (c != C_RETRY) break; c = mysh_recv_cmd(C_DATAB, recv); if (c == C_STOP) break; if (c != C_DATAB) continue; lab_skip_get_header: need = max_size - len; p = endata + len; n = recv(p, need); if (n < 1) goto lab_skip_get_header; len = len + n; e = p + n; lab_try_find_data_end: while(p < e && mysh_is_endata_char(*p)) ++p; c = *p; if (p >= e) goto lab_skip_get_header; if (c == C_END) goto lab_finded_data; if (c == C_STOP) goto lab_return_value; while(p < e) { c = *p++; if (c == C_STOP) goto lab_return_value; if (c != C_DATAB) continue; begin = p; goto lab_try_find_data_end; } /* we re-need a C_DATAB header */ continue; lab_finded_data: n = (p - begin); sz = mysh_data_decode(data, begin, n); /* we re-need a C_DATAB header */ if (n < 1) continue; c = mysh_send_cmd(C_OK, send); if (c == C_OK) c = C_DATAB; break; } lab_return_value: *size = sz; return c; }
[ 本帖最后由 皮天佑 于 2015-7-4 17:02 编辑 ]