void increment_tcp_counters( rwRec *rwrec, event_metrics_t *metrics) { if (!(rwRecGetFlags(rwrec) & ACK_FLAG)) { metrics->flows_noack++; } if (rwRecGetPkts(rwrec) < SMALL_PKT_CUTOFF) { metrics->flows_small++; } if ((rwRecGetBytes(rwrec) / rwRecGetPkts(rwrec)) > PACKET_PAYLOAD_CUTOFF) { metrics->flows_with_payload++; } if (rwRecGetFlags(rwrec) == RST_FLAG || rwRecGetFlags(rwrec) == (SYN_FLAG | ACK_FLAG) || rwRecGetFlags(rwrec) == (RST_FLAG | ACK_FLAG)) { metrics->flows_backscatter++; } add_count(metrics->tcp_flag_counts, rwRecGetFlags(rwrec), RWSCAN_MAX_FLAGS); }
/* Recall that: * "By contrast, if multiple instances of a standard signal are delivered while that signal is currently blocked, then only one instance is queued." * So the signal count is not necessarily the same as the number of records. */ static void pe_handler(int signum, siginfo_t *info, void * context) { int fd = info->si_fd; pe_event_info_t * ev = find_event_from_fd(&g_groups, fd); assert(ev != NULL); add_count(&ev->output, info->si_code); }
void AntiSem::add_locked(T cur,ulen dcount) { event(AntiSemEvent::Add); Log("#; (#;) += #; by #;",name,count,dcount,GetTaskName(cur)); add_count(dcount); }
void messages_counter::merge( const time_counter_t& second_counter ) { for( time_counter_t::const_iterator it = second_counter.begin(); it != second_counter.end(); ++it ) { const uint32_t message_type = it->first; const uint32_t message_number = it->second; add_count( message_type, message_number ); inc_time( it->first ); } }
int main(int argc, char **argv) { int i, j, fd, curfile, chars, k, in_comment = 0, in_white = 0, calls = 0, in_parens = 0, in_quotes = 0, in_define = 0, in_curly = 0; int maxc[NAME_SIZE], maxf[NAME_SIZE], maxg[NAME_SIZE], mcalls[NAME_SIZE]; qdata **qs; char input[MAX_CHARS]; char curname[ID_SIZE]; FILE *FD = NULL; names_size = NAME_SIZE; names = (char **)calloc(names_size, sizeof(char *)); hnames = (char **)calloc(names_size, sizeof(char *)); nnames = (char **)calloc(names_size, sizeof(char *)); voids = (int *)calloc(names_size, sizeof(int)); files_size = 256; files = (char **)calloc(files_size, sizeof(char *)); headers_size = 32; headers = (char **)calloc(headers_size, sizeof(char *)); counts = (int **)calloc(names_size, sizeof(int *)); lines = (char ***)calloc(names_size, sizeof(char **)); results = (int *)calloc(names_size, sizeof(int)); procs = (int *)calloc(names_size, sizeof(int)); add_header("sndlib.h"); add_header("clm.h"); add_header("vct.h"); add_header("sndlib2xen.h"); add_header("clm2xen.h"); add_header("snd.h"); #if 1 add_header("snd-strings.h"); add_header("sndlib-strings.h"); add_header("clm-strings.h"); #endif add_header("snd-0.h"); add_header("snd-1.h"); add_header("snd-x0.h"); add_header("snd-x1.h"); add_header("snd-g0.h"); add_header("snd-g1.h"); add_header("snd-nogui0.h"); add_header("snd-nogui1.h"); add_header("snd-rec.h"); add_header("xen.h"); add_header("mus-config.h.in"); add_header("libclm.def"); add_header("snd-menu.h"); add_header("snd-file.h"); /* add_file("xen.h"); */ /* add_file("snd.h"); */ add_file("headers.c"); add_file("audio.c"); add_file("io.c"); add_file("sound.c"); add_file("clm.c"); add_file("vct.c"); add_file("cmus.c"); add_file("sndlib2xen.c"); add_file("clm2xen.c"); add_file("midi.c"); add_file("snd-io.c"); add_file("snd-utils.c"); add_file("snd-error.c"); add_file("snd-completion.c"); add_file("snd-menu.c"); add_file("snd-axis.c"); add_file("snd-data.c"); add_file("snd-draw.c"); add_file("snd-fft.c"); add_file("snd-marks.c"); add_file("snd-file.c"); add_file("snd-edits.c"); add_file("snd-chn.c"); add_file("snd-sig.c"); add_file("snd-kbd.c"); add_file("snd-dac.c"); add_file("snd-region.c"); add_file("snd-run.c"); add_file("snd-select.c"); add_file("snd-find.c"); add_file("snd-snd.c"); add_file("snd-help.c"); add_file("snd-main.c"); add_file("snd-print.c"); add_file("snd-trans.c"); add_file("snd-mix.c"); add_file("snd.c"); add_file("snd-rec.c"); add_file("snd-env.c"); add_file("snd-xen.c"); add_file("snd-ladspa.c"); add_file("snd-xutils.c"); add_file("snd-xhelp.c"); add_file("snd-xfind.c"); add_file("snd-xmenu.c"); add_file("snd-xdraw.c"); add_file("snd-xlistener.c"); add_file("snd-listener.c"); add_file("snd-xchn.c"); add_file("snd-xsnd.c"); add_file("snd-xregion.c"); add_file("snd-xdrop.c"); add_file("snd-xmain.c"); add_file("snd-xmix.c"); add_file("snd-xrec.c"); add_file("snd-xenv.c"); add_file("snd-gxutils.c"); add_file("snd-gxbitmaps.c"); add_file("snd-gxcolormaps.c"); add_file("snd-xfft.c"); add_file("snd-xprint.c"); add_file("snd-xfile.c"); add_file("snd-xprefs.c"); add_file("snd-xxen.c"); add_file("snd-gutils.c"); add_file("snd-ghelp.c"); add_file("snd-gfind.c"); add_file("snd-gmenu.c"); add_file("snd-gdraw.c"); add_file("snd-glistener.c"); add_file("snd-gchn.c"); add_file("snd-gsnd.c"); add_file("snd-gregion.c"); add_file("snd-gdrop.c"); add_file("snd-gmain.c"); add_file("snd-gmix.c"); add_file("snd-grec.c"); add_file("snd-genv.c"); add_file("snd-gxutils.c"); add_file("snd-gfft.c"); add_file("snd-gprint.c"); add_file("snd-gfile.c"); add_file("snd-gxen.c"); add_file("snd-gprefs.c"); add_file("snd-prefs.c"); add_file("snd-nogui.c"); add_file("xen.c"); add_file("xm.c"); add_file("gl.c"); add_file("xg.c"); add_file("cmus.c"); add_file("sc.c"); add_file("ffi.lisp"); add_file("sndlib2clm.lisp"); for (i = 0; i < headers_ctr; i++) { k = 0; in_quotes = 0; in_white = 0; in_parens = 0; in_comment = 0; fd = open(headers[i], O_RDONLY, 0); if (fd == -1) fprintf(stderr, "can't find %s\n", headers[i]); else { do { chars = read(fd, input, MAX_CHARS); /* fprintf(stderr,"%s %d ", headers[i], chars); */ for (j = 0; j < chars; j++) { if ((in_comment == 0) && (in_curly == 0)) { if ((isalpha(input[j])) || (isdigit(input[j])) || (input[j] == '_')) { in_white = 0; if (k < ID_SIZE) curname[k++] = input[j]; else fprintf(stderr, "0: curname overflow: %s[%d]: %s%c\n", headers[i], j, curname, input[j]); } else { in_white = 1; if (k < ID_SIZE) curname[k] = 0; else fprintf(stderr, "1: curname overflow: %s[%d]: %s\n", headers[i], j, curname); if ((k > 0) && (in_parens == 0) && (in_quotes == 0)) { int loc; loc = add_name(copy_string(curname), headers[i]); if (loc >= 0) { int start, n, maybe_proc = 1; for (n = 0; n < k; n++) if (isupper(curname[n])) { maybe_proc = 0; break; } if ((maybe_proc) && ((input[j] == '(') || ((input[j] == ' ') && (input[j + 1] == '(')))) procs[loc] = maybe_proc; else procs[loc] = 0; start = j - strlen(curname) - 6; if (start >= 0) { int m; for (m = 0; m < 3; m++) if (strncmp((char *)(input + start + m), "void", 4) == 0) { voids[loc] = 1; break; } } } } /* else if (k > 0) fprintf(stderr,"drop %s %d %d\n",curname,in_parens, in_quotes); */ k = 0; if ((input[j] == '/') && (input[j + 1] == '*')) in_comment = 1; else { if (input[j] == '#') in_define = 1; else { if ((input[j] == '{') && ((j < 6) || (strncmp((input + (j - 5)), "enum", 4) != 0))) in_curly = 1; else { if (input[j] == '(') in_parens++; if (input[j] == ')') in_parens--; if (input[j] == '"') { if (in_quotes == 1) in_quotes = 0; else in_quotes = 1; } } } } } } else /* in comment or curly */ { if ((input[j] == '*') && (input[j + 1] == '/')) in_comment = 0; else { if (input[j] == '}') in_curly = 2; else { if (input[j] == ';') in_curly = 0; } } } } } while (chars == MAX_CHARS); close(fd); } } fprintf(stderr, "%d names ", names_ctr); k = 0; in_comment = 0; in_white = 0; in_define = 0; for (i = 0; i < files_ctr; i++) { k = 0; fd = open(files[i], O_RDONLY, 0); if (fd == -1) fprintf(stderr, "can't find %s\n", files[i]); else { int curly_ctr = 0,cancel_define = 0; in_define = 0; if ((strcmp(files[i], "sndlib2clm.lisp") == 0) || (strcmp(files[i], "ffi.lisp") == 0)) curly_ctr = 1; do { chars = read(fd, input, MAX_CHARS); /* fprintf(stderr,"%s %d\n", files[i], chars); */ for (j = 0; j < chars; j++) { if (in_comment == 0) { if ((isalpha(input[j])) || (isdigit(input[j])) || (input[j] == '_')) { if (k < ID_SIZE) curname[k++] = input[j]; else fprintf(stderr, "2: curname overflow: %s[%d]: %s\n", files[i], j, curname); } else { if ((input[j] == '/') && (input[j + 1] == '*')) in_comment = 1; else { if ((input[j] == '#') && (input[j + 1] == 'd')) { /* int m; fprintf(stderr,"def..."); for (m = j; (m < j + 16) && (m < chars); m++) fprintf(stderr,"%c", input[m]); */ in_define = 1; } else { if ((in_define == 1) && (input[j] == '\n') && (j > 0) && (input[j - 1] != '\\')) { /* fprintf(stderr,"!\n"); */ cancel_define = 1; } } if ((in_define == 0) && (j < (chars - 1)) && ((input[j - 1] != '\'') || (input[j + 1] != '\''))) { if (input[j] == '{') curly_ctr++; else if (input[j] == '}') curly_ctr--; } } if (k > 0) { if (k < ID_SIZE) curname[k] = 0; else fprintf(stderr, "3: curname overflow: %s[%d]: %s\n", files[i], j, curname); if ((k < ID_SIZE) && ((curly_ctr > 0) || (in_define == 1))) { int loc; loc = add_count(curname, i); if (loc >= 0) { if (procs[loc]) results[loc] += get_result(input, j, k); if (lines[loc] == NULL) { lines[loc] = (char **)calloc(MAX_LINES, sizeof(char *)); lines[loc][0] = get_call(input, j, k, curname, chars); } else { int m; for (m = 0; m < MAX_LINES; m++) if (lines[loc][m] == NULL) { lines[loc][m] = get_call(input, j, k, curname, chars); break; } } } } k = 0; } if (cancel_define == 1) { cancel_define = 0; in_define = 0; } } } else { if ((input[j] == '*') && (input[j + 1] == '/')) in_comment = 0; } } } while (chars == MAX_CHARS); close(fd); } } FD = fopen("xref.data","w"); if (!FD) fprintf(stderr, "can't write xref.data?"); else { for (i = 0; i < names_ctr; i++) { maxc[i] = 0; maxf[i] = 0; maxg[i] = 0; for (j = 0; j < files_ctr; j++) if ((counts[i]) && (counts[i][j] > 0)) { maxc[i] += counts[i][j]; maxf[i]++; if ((j == snd_xen_c) || (j == snd_nogui_c)) maxg[i]++; } } for (i = 0; i < names_ctr; i++) { calls = 0; if (counts[i]) for (j = 0; j < files_ctr; j++) calls += counts[i][j]; mcalls[i] = calls; } qs = (qdata **)calloc(NAME_SIZE, sizeof(qdata *)); for (i = 0; i < names_ctr; i++) { qdata *q; q = calloc(1, sizeof(qdata)); qs[i] = q; q->i = i; q->v = voids[i]; q->name = names[i]; q->hname = hnames[i]; q->calls = mcalls[i]; q->results = results[i]; q->proc = procs[i]; } qsort((void *)qs, names_ctr, sizeof(qdata *), greater_compare); for (i = 0; i < names_ctr; i++) { bool menu_case = false, file_case = false, rec_case = false, nonogui_case = false; int menu_count = 0, file_count = 0, rec_count = 0; int nfiles; nfiles = 0; /* try to get rid of a bunch of annoying false positives */ if ((qs[i]->calls == 0) && ((strcmp(qs[i]->hname, "xen.h") == 0) || (strcmp(qs[i]->hname, "mus-config.h.in") == 0) || (qs[i]->name[strlen(qs[i]->name) - 2] == '_') && ((qs[i]->name[strlen(qs[i]->name) - 1] == 't') || (qs[i]->name[strlen(qs[i]->name) - 1] == 'H')))) { } else { fprintf(FD, "\n\n%s: %d [%s]", qs[i]->name, qs[i]->calls, qs[i]->hname); if (qs[i]->v) { fprintf(FD, " (void)"); } else { if ((qs[i]->results == 0) && (qs[i]->proc > 0) && (qs[i]->calls > 0) && (strncmp(qs[i]->name, "set_", 4) != 0) && (strncmp(qs[i]->name, "in_set_", 7) != 0)) fprintf(FD, " (not void but result not used?)"); } menu_case = (strcmp(qs[i]->hname, "snd-menu.h") != 0); file_case = (strcmp(qs[i]->hname, "snd-file.h") != 0); rec_case = (strcmp(qs[i]->hname, "snd-rec.h") != 0); menu_count = 0; file_count = 0; rec_count = 0; nonogui_case = in_nogui_h(qs[i]->name); if ((nonogui_case) && (counts[qs[i]->i])) { /* fprintf(stderr, "%s...", qs[i]->name); */ for (j = 0; j < files_ctr; j++) if ((counts[qs[i]->i][j] > 0) && ((strcmp(files[j], "snd-xen.c") == 0) || ((strcmp(files[j], "snd-nogui.c") != 0) && (strncmp(files[j], "snd-x", 5) != 0) && (strncmp(files[j], "snd-g", 5) != 0)))) { /* fprintf(stderr,"in %s\n", files[j]); */ nonogui_case = false; break; } /* if (nonogui_case) fprintf(stderr, "!\n"); */ } for (j = 0; j < files_ctr; j++) { if ((counts[qs[i]->i]) && (counts[qs[i]->i][j] > 0)) { if (menu_case) { if ((strcmp(files[j], "snd-menu.c") != 0) && (strcmp(files[j], "snd-xmenu.c") != 0) && (strcmp(files[j], "snd-gmenu.c") != 0)) { if (strcmp(files[j], "snd-nogui.c") != 0) menu_case = false; } else menu_count++; } if (file_case) { if ((strcmp(files[j], "snd-file.c") != 0) && (strcmp(files[j], "snd-xfile.c") != 0) && (strcmp(files[j], "snd-gfile.c") != 0)) { if (strcmp(files[j], "snd-nogui.c") != 0) file_case = false; } else file_count++; } if (rec_case) { if ((strcmp(files[j], "snd-rec.c") != 0) && (strcmp(files[j], "snd-xrec.c") != 0) && (strcmp(files[j], "snd-grec.c") != 0)) { if (strcmp(files[j], "snd-nogui.c") != 0) rec_case = false; } else rec_count++; } fprintf(FD,"\n %s: %d", files[j], counts[qs[i]->i][j]); nfiles++; } } if ((menu_case) && (menu_count > 0)) fprintf(FD, "\n->SND-MENU.H\n"); if ((file_case) && (file_count > 0)) fprintf(FD, "\n->SND-FILE.H\n"); if ((rec_case) && (rec_count > 0)) fprintf(FD, "\n->SND-REC.H\n"); if (nonogui_case) fprintf(FD, "\nnot needed in snd-nogui?\n"); { int m; if ((nfiles > 0) && (lines[qs[i]->i])) { fprintf(FD, "\n"); for (m = 0; m < MAX_LINES; m++) { if (lines[qs[i]->i][m] == NULL) break; fprintf(FD, "\n %s", lines[qs[i]->i][m]); } } } if ((nfiles < 2) && (qs[i]->calls > 1) && (islower(qs[i]->name[0])) && (strncmp(qs[i]->name, "snd_K", 5) != 0) && (strncmp(qs[i]->name, "mus_", 4) != 0) && (strncmp(qs[i]->name, "ps_", 3) != 0)) fprintf(FD, "\n----------------- (static?) -----------------------"); else fprintf(FD, "\n----------------"); } } fclose(FD); } return(0); }
/* * @brief listen每次accept一个连接,则创建一个线程收取文件,线程的call_back函数即为handler,参数是accept的fd * @param int fd */ int handler(int fd) { char buffer[NET_BUFFER_LEN], encrypt_buffer[NET_BUFFER_LEN]; char *buf_ptr; int recv_len = 0; int send_len = 0; int total_recv_len = 0; int total_send_len = 0; int prefix_len = SYMBOL_LEN + COMMAND_LEN + DATA_LEN + FILL_LEN; int payload_len = 0; int fill_len = 0; int data_len = 0; int continue_flag = 1; q_node_t *node; pthread_detach(pthread_self()); add_count(); node = get_recv_node(); //while recv_len == -1看起来很奇怪,似乎将while变成if更加合理 //但是如果在recv时候被信号中断等待过程,则需要重新recv 使用while可以在recv到数据或者0的时候立即 //退出并进一步判断,在recv返回-1的时候判断errno选择是退出还是继续recv while ((recv_len = recv(fd, (void*)buffer, sizeof(buffer), 0)) == -1) { if (errno == EINTR) continue; else { write_log("Handler,recv:%s\n", strerror(errno)); goto ret; //or just break, and recv_len = -1,program will goto ret at the if condition down there } } if (recv_len == 0) { write_log("Recv 0:client_closed %s\n", strerror(errno)); goto ret; } total_recv_len = recv_len; if (recv_len < prefix_len) { //刚开始收数据时,缓冲区是空的,而本fd连头部信息都没有收完全. write_log("Bad connection,recv command error![recv_len=%u,prefixlen=%u]\n", recv_len,prefix_len); goto ret; } while (continue_flag) { while (total_recv_len < prefix_len) { while ((recv_len = recv(fd, (void*)(buffer+total_recv_len), sizeof(buffer) - total_recv_len, 0)) == -1) { if (errno == EINTR) continue; else { write_log("Recv error:%s\n", strerror(errno)); goto ret; } } total_recv_len += recv_len; if (recv_len == 0) { write_log("recv 0:%s\n", strerror(errno)); goto ret; } } //暂时只解析头部 #ifdef ENCODE_ des_decrypt_n(des_pass_phrase, (const void*)buffer , (void*)encrypt_buffer, prefix_len/ALIGN_LEN); //32BYTE/8BYTE memcpy(buffer,encrypt_buffer,prefix_len); #endif payload_len = *(int*)(buffer + SYMBOL_LEN + COMMAND_LEN); fill_len = *(int*)(buffer + SYMBOL_LEN + COMMAND_LEN + DATA_LEN); data_len = prefix_len + payload_len + fill_len + DATA_END_LEN; if (data_len > sizeof(buffer)) { write_log("data_len[%u] > buffer size[%lu]!!!\ please enlarge your buffer size\n", data_len, sizeof(buffer)); goto ret; } if ((total_recv_len - prefix_len) < (payload_len + fill_len + DATA_END_LEN)) { while ((recv_len = recv(fd, (void*)buffer+total_recv_len, (sizeof(buffer) - total_recv_len), 0)) < (data_len - total_recv_len)) { if (recv_len == -1) { if (errno == EINTR) continue; write_log("Handler,recv:%s\n", strerror(errno)); goto ret; } else if (recv_len == 0) { write_log("Handler,recv 0 :%s\n", strerror(errno)); goto ret; } else total_recv_len += recv_len; } total_recv_len += recv_len; } if (memcmp(SYMBOL, buffer, SYMBOL_LEN) != 0) { write_log("Bad connection, bad symbol![%s]\n", buffer); goto ret; } if (memcmp(C_GET_LOAD, buffer + SYMBOL_LEN, COMMAND_LEN) == 0) { buf_ptr = buffer; memcpy(buf_ptr, SYMBOL, SYMBOL_LEN); //packet symbol buf_ptr += SYMBOL_LEN; memcpy(buf_ptr, C_SHOW_LOAD, COMMAND_LEN); //ask server's load command buf_ptr += COMMAND_LEN; data_len = sizeof(float); fill_len = ALIGN_LEN - sizeof(float); memcpy(buf_ptr, &data_len, DATA_LEN ); buf_ptr += DATA_LEN; memcpy(buf_ptr, &fill_len, FILL_LEN ); buf_ptr += FILL_LEN; //================getload============ FILE *result; char result_buf[TEXT_LINE_LEN]; result = popen("awk 'BEGIN{\"uptime\"|getline; print $11;}'","r"); fread(result_buf,sizeof(char),sizeof(result_buf),result); pclose(result); float server_load = atof(result_buf); //============================ memcpy(buf_ptr, &server_load, data_len); buf_ptr += data_len; memset(buf_ptr, 0x0, fill_len); buf_ptr += fill_len; memcpy(buf_ptr,DATA_END,DATA_END_LEN); buf_ptr += DATA_END_LEN; #ifdef ENCODE_ des_encrypt_n(des_pass_phrase, (const void*)buffer , (void*)encrypt_buffer, (buf_ptr - buffer)/ALIGN_LEN); //32BYTE/8BYTE memcpy(buffer, encrypt_buffer, sizeof(buffer)); #endif //sent to client send_len = 0; total_send_len = 0; data_len = buf_ptr - buffer; while ((send_len = send(fd, buffer+total_send_len, (data_len-total_send_len), 0) ) < (data_len - total_send_len) ) { if (send_len == -1) { if (errno == EINTR) continue; write_log("Send load: send error:%s\n", strerror(errno)); goto ret; } else total_send_len += send_len; } total_send_len += send_len; goto ret; } if (memcmp(C_SEND_DATA, buffer + SYMBOL_LEN, COMMAND_LEN) == 0) { //解析数据体 #ifdef ENCODE_ des_decrypt_n(des_pass_phrase, (const void*)(buffer+prefix_len), (void*)encrypt_buffer, (data_len - prefix_len)/ALIGN_LEN); //32BYTE/8BYTE memcpy(buffer + prefix_len, encrypt_buffer, data_len - prefix_len); #endif buf_ptr = buffer + prefix_len; store_result_t *t1; store_result_t *tmp; int effctive_size = sizeof(store_result_t) - sizeof((store_result_t*)0); //=========================================== while ((buf_ptr - (buffer + prefix_len)) < payload_len) { t1 = (store_result_t*)buf_ptr; //将这批数据挂在recvlink上 tmp = get_mem(); memcpy(tmp, t1, effctive_size); tmp->next = NULL; buf_ptr += effctive_size; if (node->recv_link == NULL) node->recv_link = tmp; else { tmp->next = node->recv_link; node->recv_link = tmp; } file_recv_node_len[node->number]++ ; } //============================================ buf_ptr += fill_len;//跳到后续数据标识符 //若为其他(应该是"DATA_END") 则可以退出,若为CONTINU,则继续接收 uint32_t packet_len = prefix_len + payload_len + fill_len + DATA_END_LEN; //printf("\t\t%u,%u\n",total_recv_len,packet_len); if (memcmp(buf_ptr, CONTINUE, DATA_END_LEN) == 0) { //有后续数据 buf_ptr += DATA_END_LEN; if ((buf_ptr - buffer) == sizeof(buffer)) { //buffer收满了,则重新收 recv_len = 0; total_recv_len =0; continue_flag = 1; } else if (total_recv_len == packet_len) { //如果接收到了一个完整的数据分段,则重新接收 recv_len = 0; total_recv_len = 0; continue_flag = 1; } else { //如果缓冲区中有后续包的分段,则前移动,因为这些数据没有解密,所以直接移动 memcpy(encrypt_buffer, buf_ptr, total_recv_len - packet_len); memcpy(buffer, encrypt_buffer, total_recv_len - packet_len); recv_len = total_recv_len - packet_len; total_recv_len = recv_len; continue_flag = 1; } } else continue_flag = 0; //no more data transmitted }//send data }//while continue //store_data int status = write_file(node->recv_link, file_recv_node_len[node->number]); if(status == 0) { //echo DATA__OK to client; buf_ptr = buffer; memcpy(buf_ptr, SYMBOL, SYMBOL_LEN); //packet symbol buf_ptr += SYMBOL_LEN; memcpy(buf_ptr, C_DATA_OK, COMMAND_LEN); //ask server's load command buf_ptr += COMMAND_LEN; memset(buf_ptr, 0x0, DATA_LEN + FILL_LEN); buf_ptr += (DATA_LEN + FILL_LEN); memcpy(buf_ptr,DATA_END,DATA_END_LEN); buf_ptr += DATA_END_LEN; #ifdef ENCODE_ des_encrypt_n(des_pass_phrase, (const void*)buffer , (void*)encrypt_buffer, (buf_ptr - buffer)/ALIGN_LEN); //32BYTE/8BYTE memcpy(buffer,encrypt_buffer,sizeof(buffer)); #endif //sent to client send_len = 0; total_send_len = 0; data_len = buf_ptr - buffer; while ((send_len = send(fd, buffer+total_send_len, (data_len-total_send_len), 0)) < (data_len - total_send_len)) { if (send_len == -1) { if (errno == EINTR) continue; write_log("Send load: send error:%s\n", strerror(errno)); goto ret; } else total_send_len += send_len; } total_send_len += send_len; } ret: recycle_recv_node(node); sub_count(); pthread_mutex_lock(&thread_count_mutex); pthread_cond_signal(&thread_count_cond); pthread_mutex_unlock(&thread_count_mutex); close(fd); pthread_exit(0); return 0; }