// The server uses this for verification. int blk_read_verify(struct blk *blk_to_verify) { if(!win) { rconf_init(&rconf); if(!(win=win_alloc(&rconf))) return -1; } gbuf=blk_to_verify->data; gbuf_end=gbuf+blk_to_verify->length; gcp=gbuf; if(!blk && !(blk=blk_alloc())) return -1; blk->length=0; blk->fingerprint=0; // FIX THIS: blk_read should return 1 when it has a block. // But, if the block is too small (because the end of the file // happened), it returns 0, and blks_generate treats it as having found // a final block. // So, here the return of blk_read is ignored and we look at the // position of gcp instead. blk_read(); if(gcp==gbuf_end && blk->fingerprint==blk_to_verify->fingerprint) return 1; return 0; }
struct game* seal_load_game_config() { GAME = (struct game*)s_malloc(sizeof(struct game)); // lua modules lua_State* L = seal_new_lua(); luaopen_lua_extensions(L); GAME->lstate = L; // load the game settings from config.lua seal_load_file("scripts/config.lua"); lua_getglobal(L, "APP_NAME"); lua_getglobal(L, "WINDOW_WIDTH"); lua_getglobal(L, "WINDOW_HEIGHT"); lua_getglobal(L, "NK_GUI_FONT_PATH"); lua_getglobal(L, "NK_GUI_FONT_SIZE"); struct game_config* config = &GAME->config; config->app_name = lua_tostring(L, 1); config->window_width = lua_tonumber(L, 2); config->window_height = lua_tonumber(L, 3); config->nk_gui_font_path = lua_tostring(L, 4); config->nk_gui_font_size = lua_tonumber(L, 5); lua_pop(L, 5); GAME->window = win_alloc(); return GAME; }
int blks_generate_init(void) { rconf_init(&rconf); if(!(win=win_alloc(&rconf)) || !(gbuf=(char *)malloc_w(rconf.blk_max, __func__))) return -1; gbuf_end=gbuf; gcp=gbuf; return 0; }
END_TEST START_TEST(test_win_alloc_error) { struct rconf rconf; struct win *win; alloc_check_init(); rconf_init(&rconf); alloc_errors=1; fail_unless((win=win_alloc(&rconf))==NULL); tear_down(); }
int backup_phase2_client_burp2(struct asfd *asfd, struct conf *conf, int resume) { int ret=-1; int sigs_end=0; int backup_end=0; int requests_end=0; int blk_requests_end=0; struct win *win=NULL; // Rabin sliding window. struct slist *slist=NULL; struct blist *blist=NULL; struct iobuf *rbuf=NULL; struct iobuf *wbuf=NULL; logp("Phase 2 begin (send backup data)\n"); if(!(slist=slist_alloc()) || !(blist=blist_alloc()) || !(wbuf=iobuf_alloc()) || blks_generate_init(conf) || !(win=win_alloc(&conf->rconf))) goto end; rbuf=asfd->rbuf; if(!resume) { // Only do this bit if the server did not tell us to resume. if(asfd->write_str(asfd, CMD_GEN, "backupphase2") || asfd->read_expect(asfd, CMD_GEN, "ok")) goto end; } else if(conf->send_client_cntr) { // On resume, the server might update the client with the // counters. if(cntr_recv(asfd, conf)) goto end; } while(!backup_end) { if(!wbuf->len) { get_wbuf_from_data(conf, wbuf, slist, blist, blk_requests_end); if(!wbuf->len) { get_wbuf_from_blks(wbuf, slist, requests_end, &sigs_end); } } if(wbuf->len) asfd->append_all_to_write_buffer(asfd, wbuf); if(asfd->as->read_write(asfd->as)) { logp("error in %s\n", __func__); goto end; } if(rbuf->buf && deal_with_read(rbuf, slist, blist, conf, &backup_end, &requests_end, &blk_requests_end)) goto end; if(slist->head // Need to limit how many blocks are allocated at once. && (!blist->head || blist->tail->index - blist->head->index<BLKS_MAX_IN_MEM) ) { if(add_to_blks_list(asfd, conf, slist, blist, win)) goto end; } if(blk_requests_end) { // If got to the end of the file request list // and the last block of the last file, and // the write buffer is empty, we got to the end. if(slist->head==slist->tail) { if(!slist->tail || blist->last_sent==slist->tail->burp2->bend) { if(!wbuf->len) break; } } } } if(asfd->write_str(asfd, CMD_GEN, "backup_end")) goto end; ret=0; end: blk_print_alloc_stats(); //sbuf_print_alloc_stats(); win_free(win); slist_free(&slist); blist_free(&blist); // Write buffer did not allocate 'buf'. wbuf->buf=NULL; iobuf_free(&wbuf); cntr_print_end(conf->cntr); cntr_print(conf->cntr, ACTION_BACKUP); if(ret) logp("Error in backup\n"); logp("End backup\n"); return ret; }