static void recover_from_log(void) { read_head(); install_trans(); // if committed, copy from log to disk log.lh.n = 0; write_head(); // clear the log }
int ana_head(struct sbpfs_head* head, char* data) { char* ip; int port; char* headmethod; char* blocknumc; char* offsetc; char* lengthc; blocknumc = get_head_entry_value(head, "Arg0"); offsetc = get_head_entry_value(head, "Arg1"); lengthc = get_head_entry_value(head, "Arg2"); u64_t blocknum = atoll(blocknumc); req_len = atoll(lengthc); u64_t req_offset = atoll(offsetc); if ((headmethod = get_head_entry_value(head, "method")) == NULL) { perror("fail to ananlyse! \n"); return -1; } else if (strcmp(headmethod, "READ") == 0) { int succeed=readblock(blocknum, req_offset, req_len); sbphead = read_head(databuf, req_len,succeed); build_headr(&send_buf, &sbphead); } else if (strcmp(headmethod, "WRITE") == 0) { int succeed = writeblock(blocknum, req_offset, req_len, data); sbphead = write_head(databuf, req_len,succeed); build_headw(&send_buf, &sbphead); reportwrite(ip, blocknum, port, succeed); } return 0; }
int req_put(int sockfd, struct message_s *msg) { char *filepath = payload_malloc(sockfd, msg, true); char *repopath = make_path(filepath); printf("client put %s\n", repopath); int saveto_fd = open(repopath, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR); free(filepath); free(repopath); if (saveto_fd == -1) { perror("cannot open file to write"); close_serving_thread(sockfd); } /* always says that you can upload */ write_head(sockfd, TYPE_PUT_REP, 1, 0); /* receive DATA_FILE */ struct message_s recv_msg; read_head(sockfd, &recv_msg); off_t size = payload_size(&recv_msg); int ret = transfer_file_copy(saveto_fd, sockfd, size, NULL); close(saveto_fd); if (ret == -1) close_serving_thread(sockfd); return 0; }
static void recover_from_log(void) { read_head(); cprintf("recovery: n=%d\n", log.lh.n); install_trans(); log.lh.n = 0; write_head(); }
int ft_file_to_array(t_map *map, char *file) { int fd; fd = open(file, O_RDONLY); map->map = (char *) malloc(sizeof(char) * map->stats[2]); if (read_head(fd, map) < 0) return (-1); if (read(fd, map->map, map->stats[2]) < 0) return (-2); return (1); }
void LoginConn::on_connect() { m_dispatcher.register_message_callback((int)M2L::LOOKUP, bind(&LoginConn::handle_lookup, this, std::placeholders::_1)); g_login_handler = this; register_msgsvr(); read_head(); }
int Session::on_read_event() { int ret; while (true) { if (!m_has_head) { ret = read_head(); if (ret < 0) { return -1; } if (ret == SESSION_RET_NO_DATA) { return 0; } if (m_msg_type == MSG_HEART_BEAT) { if (g_is_master) { update_active_time(); } else { struct commu_msg msg; msg.ip = get_cli_addr(); msg.msg = MSG_HEART_BEAT; notify_master(msg); } continue; } m_has_head = true; m_buff = (u_char *)glb_mempool()->get(m_msg_len); } int n_read = readn(m_sockfd, &m_buff[m_n_read], m_msg_len - m_n_read); if (n_read < 0) { logerr("socket broken\n"); m_msg_len = 0; m_has_head = false; return -1; } m_n_read += n_read; if (m_n_read == m_msg_len) { write_msg(m_buff, m_msg_len); reset_buffer(); } } return 0; }
void CTcpSocketBase::handler_read_body(const boost::system::error_code& error, std::size_t bytes_transferred,int offset) { if (!error) { int curr_offset = offset + (int)bytes_transferred; if (curr_offset < (int)msgRecv.bodylen()) { read_body(curr_offset); }else { msgParse(msgRecv.head(),msgRecv.alllen()); read_head(0); } }else { delete_self(error); } }
void CTcpSocketBase::handler_read_head(const boost::system::error_code& error, std::size_t bytes_transferred,int offset){ if (!error) { int curr_offset = offset + (int)bytes_transferred; if (curr_offset < (int)msgRecv.headlen()) { read_head(curr_offset); }else { read_body(0); } } else { //g_logger.info("read_head socket = [%08x] error = [%s]",this,error.message().c_str()); delete_self(error); } }
void handle_client_fd(pConnInfo conn_info) { if(setjmp(conn_info->jmp_buff)) { --conn_info->request_id; return; } else if(conn_info->status == CS_ACCEPT) { read_head(conn_info); } apply_next_router(conn_info); fclose(conn_info->input_file);//if we don't close file, will cause memory leak close(conn_info->clientfd); uws_free(conn_info->request_header->url); uws_free(conn_info->request_header->path); uws_free(conn_info->request_header->request_params); free_header_params(conn_info->request_header); uws_free(conn_info->request_header); uws_free(conn_info->response_header); }
/* * Read in a midi file from the specified open file pointer, fp * and return an mtree structure tree representing the file. * * Arguments: * fp - Input file pointer */ struct rootElement * midi_read(FILE *fp) { struct midistate mState; struct midistate *msp; struct rootElement *root; struct element *el; int i; msp = &mState; msp->fp = fp; msp->tempo_map = md_tempomap_new(); msp->notes = g_ptr_array_new(); msp->port = 0; root = read_head(msp); md_add(MD_CONTAINER(root), NULL); /* Leave room for the tempo map */ for (i = 0; i < root->tracks; i++) { el = MD_ELEMENT(read_track(msp)); /* If format 1 then the first track is really the tempo map */ if (root->format == 1 && i == 0 && MD_CONTAINER(el)->elements->len == 0) { /* It will be added after the loop */ md_free(el); continue; } md_add(MD_CONTAINER(root), el); } g_ptr_array_index(MD_CONTAINER(root)->elements, 0) = msp->tempo_map; msp->tempo_map = NULL; g_ptr_array_free(msp->notes, 1); return root; }
static int Demux( demux_t* p_demux ) { const char* psz_name; int i_type; demux_sys_t* p_sys = p_demux->p_sys; input_item_t* p_input = GetCurrentItem( p_demux ); input_item_node_t* p_node = input_item_node_Create( p_input ); p_sys->psz_prefix = FindPrefix( p_demux ); do { i_type = xml_ReaderNextNode( p_sys->p_reader, &psz_name ); if ( i_type == XML_READER_STARTELEM && !strcasecmp( psz_name, "head" ) ) read_head( p_demux, p_input ); else if ( i_type == XML_READER_STARTELEM && !strcasecmp( psz_name, "body" ) ) read_body( p_demux, p_node ); } while (i_type != XML_READER_ENDELEM || strcasecmp( psz_name, "smil" ) ); input_item_node_PostAndDelete( p_node ); input_item_Release( p_input ); return 0; }
int decodeMP3 (struct mpstr *mp, char *in, int isize, char *out, int osize, int *done) { int len; gmp = mp; if (osize < 4608) { fprintf (stderr, "To less out space\n"); return MP3_ERR; } if (in) { if (addbuf (mp, in, isize) == NULL) { return MP3_ERR; } } /* First decode header */ if (mp->framesize == 0) { if (mp->bsize < 4) { return MP3_NEED_MORE; } read_head (mp); decode_header (&mp->fr, mp->header); mp->framesize = mp->fr.framesize; } if (mp->fr.framesize > mp->bsize) return MP3_NEED_MORE; wordpointer = mp->bsspace[mp->bsnum] + 512; mp->bsnum = (mp->bsnum + 1) & 0x1; bitindex = 0; len = 0; while (len < mp->framesize) { int nlen; int blen = mp->tail->size - mp->tail->pos; if ((mp->framesize - len) <= blen) { nlen = mp->framesize - len; } else { nlen = blen; } memcpy (wordpointer + len, mp->tail->pnt + mp->tail->pos, nlen); len += nlen; mp->tail->pos += nlen; mp->bsize -= nlen; if (mp->tail->pos == mp->tail->size) { remove_buf (mp); } } *done = 0; if (mp->fr.error_protection) getbits (16); switch (mp->fr.lay) { case 3: do_layer3 (&mp->fr, (unsigned char *) out, done); break; } mp->fsizeold = mp->framesize; mp->framesize = 0; return MP3_OK; }
int decodeMP3(struct mpstr *mp, char *in, int isize, char *out, int osize, int *done) { int len; if(osize < 4608) { #ifndef BE_QUIET fprintf(stderr,"To less out space\n"); #endif return MP3_ERR; } if(in) { if(addbuf(mp, in, isize) == NULL) { return MP3_ERR; } } /* First decode header */ if(mp->framesize == 0) { if(mp->bsize < 4) { return MP3_NEED_MORE; } read_head(mp); if(mp->tail) mp->ndatabegin = mp->tail->pos - 4; if (decode_header(mp, &mp->fr,mp->header) <= 0 ) return MP3_ERR; mp->framesize = mp->fr.framesize; } /* printf(" fr.framesize = %i \n",mp->fr.framesize); printf(" bsize = %i \n",mp->bsize); */ if(mp->fr.framesize > mp->bsize) { return MP3_NEED_MORE; } mp->psd.wordpointer = mp->bsspace[mp->bsnum] + 512; mp->bsnum = (mp->bsnum + 1) & 0x1; mp->psd.bitindex = 0; len = 0; while(len < mp->framesize) { int nlen; int blen = mp->tail->size - mp->tail->pos; if( (mp->framesize - len) <= blen) { nlen = mp->framesize-len; } else { nlen = blen; } memcpy(mp->psd.wordpointer+len,mp->tail->pnt+mp->tail->pos,nlen); len += nlen; mp->tail->pos += nlen; mp->bsize -= nlen; if(mp->tail->pos == mp->tail->size) { remove_buf(mp); } } *done = 0; if(mp->fr.error_protection) getbits(&mp->psd, 16); // FOR mpglib.dll: see if error and return it if ((&mp->fr)->do_layer(&mp->psd, mp, &mp->fr, (unsigned char*) out, done) < 0) return MP3_ERR; mp->fsizeold = mp->framesize; mp->framesize = 0; return MP3_OK; }
void read_head_C(int threadfd, struct message_s *msg) { if (read_head(threadfd, msg) == -1) close_serving_thread(threadfd); }
void CTcpSocketBase::start(){ read_head(0); }