static void data_output_header(int sm_sock_fd) { int type = 0; int size = 0; unsigned int __attribute__ ((unused)) total; while(1){ if(header_read(sm_sock_fd, &type, &size) != 0) break; total = data_output_main(sm_sock_fd, size); if(end_signal) break; if(type == PRN_DATA_NORMAL) break; } /* wait SIGTERM */ while(1){ if(end_signal) break; pause(); } return; }
Response response_read(int fd) { rio_t rio; char buf[MAXLINE]; Rio_readinitb(&rio, fd); ssize_t r = Rio_readlineb(&rio, buf, MAXLINE); if (r == 0) { printf("Received empty response\n"); return NULL; } Response response = malloc(sizeof(struct Response)); sscanf(buf, "%s %d %s", response->version, &response->status_code, response->status_name); header_read(&rio, buf, &response->header); HeaderEntry* content_length_entry = header_find_entry(&response->header, "Content-Length"); int content_length = content_length_entry == NULL ? 0 : atoi(content_length_entry->value); response->content_length = content_length; response->content = malloc(response->content_length * sizeof(char)); char *content = response->content; while (content_length > 0) { r = Rio_readlineb(&rio, content, (size_t) content_length); if (r > 0) { content += r; content_length -= r; } } return response; }
int bbp_decode(uint8_t *in, uint8_t *out) { int b_s_len; uint32_t size, size_c; Block_Coder_Data b; Block_Coder_Data s; assert(in); assert(out); #ifdef BBP_USE_SIMD assert(!((uintptr_t)in % 16)); assert(!((uintptr_t)out % 16)); #endif //determines block_size(s), coder(s), offset(s), b->len_c and b->len header_read(in, &b, &s, &size, &size_c); b_s_len = offset_calc_signal_len(&b); //printf("decode s len: %d\n", b_s_len); if (b_s_len) { s.len = offset_calc_signal_len(&b); s.signal_buf = in+HEADER_SIZE+b.len_c; s.data_buf = malloc(b_s_len); //for decoded signal of b assert(s.data_buf); //offset_calc_signal_len needs offset, block_size and len which are now known s.block_buf = s.signal_buf + RU_N(offset_calc_signal_len(&s), BBP_ALIGNMENT); } b.signal_buf = s.data_buf; b.block_buf = in + HEADER_SIZE; b.data_buf = out; //printf("dec positions: %d %d %d\n", b.block_buf-in, s.block_buf-in, s.signal_buf-in); if (b_s_len) { //printf("decode signal len: %d\n", b_s_len); decode(&s); /*int i; for(i=0;i<b_s_len;i++) printf("%d ", b.signal_buf[i]); printf("\n");*/ } //printf("decode block len: %d\n", b.len); decode(&b); assert(b.cur_data-b.data_buf == size); if (b_s_len) free(s.data_buf); return size; }
Request request_read(int fd) { rio_t rio; char buf[MAXLINE]; Rio_readinitb(&rio, fd); ssize_t r = Rio_readlineb(&rio, buf, MAXLINE); if (r == 0) { printf("Received empty request\n"); return NULL; } Request request = malloc(sizeof(struct Request)); sscanf(buf, "%s %s %s", request->method, request->uri, request->version); header_read(&rio, buf, &request->header); return request; }
static struct sector_header_s * header_get(struct sbd_context *st) { struct sector_header_s *s_header; s_header = sector_alloc(); if (header_read(st, s_header) < 0) { cl_log(LOG_ERR, "Unable to read header from device %d", st->devfd); return NULL; } if (valid_header(s_header) < 0) { cl_log(LOG_ERR, "header on device %d is not valid.", st->devfd); return NULL; } /* cl_log(LOG_INFO, "Found version %d header with %d slots", s_header->version, s_header->slots); */ return s_header; }
void bbp_header_sizes(uint8_t *buf, uint32_t *size, uint32_t *size_c) { Block_Coder_Data b, s; header_read(buf, &b, &s, size, size_c); }