| 451 | | struct PINT_Request_state *req; |
| 452 | | int32_t rqdepth; |
| 453 | | gossip_debug(GOSSIP_REQUEST_DEBUG,"PINT_New_request_state\n"); |
| 454 | | if (!(req = (struct PINT_Request_state *)malloc(sizeof(struct PINT_Request_state)))) |
| 455 | | { |
| 456 | | gossip_lerr("PINT_New_request_state failed to malloc req !!!!!!!\n"); |
| | 451 | return PINT_new_request_states(request, 1); |
| | 452 | } |
| | 453 | |
| | 454 | struct PINT_Request_state *PINT_new_request_states(PINT_Request *request, int n) |
| | 455 | { |
| | 456 | struct PINT_Request_state *reqs; |
| | 457 | int rqdepth, i; |
| | 458 | |
| | 459 | gossip_debug(GOSSIP_REQUEST_DEBUG, "%s n=%d\n", __func__, n); |
| | 460 | |
| | 461 | /* we assume null request is a contiguous byte range depth 1 */ |
| | 462 | if (request) |
| | 463 | { |
| | 464 | rqdepth = request->depth; |
| | 465 | } |
| | 466 | else |
| | 467 | { |
| | 468 | rqdepth = 1; |
| | 469 | } |
| | 470 | |
| | 471 | reqs = malloc(n * (sizeof(*reqs) + rqdepth * sizeof(*reqs->cur))); |
| | 472 | if (!reqs) |
| | 473 | { |
| | 474 | gossip_lerr("%s: malloc failed\n", __func__); |
| 459 | | req->lvl = 0; |
| 460 | | req->bytes = 0; |
| 461 | | req->type_offset = 0; |
| 462 | | req->target_offset = 0; |
| 463 | | req->final_offset = request->aggregate_size; |
| 464 | | req->eof_flag = 0; |
| 465 | | /* we assume null request is a contiguous byte range depth 1 */ |
| 466 | | if (request) |
| 467 | | { |
| 468 | | rqdepth = request->depth; |
| 469 | | } |
| 470 | | else |
| 471 | | { |
| 472 | | rqdepth = 1; |
| 473 | | } |
| 474 | | if (!(req->cur = (struct PINT_reqstack *)malloc(rqdepth * |
| 475 | | sizeof(struct PINT_reqstack)))) |
| 476 | | { |
| 477 | | gossip_lerr("PINT_New_request_state failed to malloc rqstack !!!!!!\n"); |
| 478 | | return NULL; |
| 479 | | } |
| 480 | | req->cur[req->lvl].maxel = 1; /* transfer one instance of request */ |
| 481 | | req->cur[req->lvl].el = 0; |
| 482 | | req->cur[req->lvl].rq = request; |
| 483 | | req->cur[req->lvl].rqbase = request; |
| 484 | | req->cur[req->lvl].blk = 0; |
| 485 | | req->cur[req->lvl].chunk_offset = 0; /* transfer from inital file offset */ |
| 486 | | return req; |
| | 477 | |
| | 478 | for (i=0; i<n; i++) |
| | 479 | { |
| | 480 | reqs[i].cur = (void *) &reqs[n]; |
| | 481 | reqs[i].cur += i * rqdepth; |
| | 482 | |
| | 483 | reqs[i].lvl = 0; |
| | 484 | reqs[i].bytes = 0; |
| | 485 | reqs[i].type_offset = 0; |
| | 486 | reqs[i].target_offset = 0; |
| | 487 | reqs[i].final_offset = request->aggregate_size; |
| | 488 | reqs[i].eof_flag = 0; |
| | 489 | |
| | 490 | reqs[i].cur[0].maxel = 1; /* transfer one instance of request */ |
| | 491 | reqs[i].cur[0].el = 0; |
| | 492 | reqs[i].cur[0].rq = request; |
| | 493 | reqs[i].cur[0].rqbase = request; |
| | 494 | reqs[i].cur[0].blk = 0; |
| | 495 | reqs[i].cur[0].chunk_offset = 0; /* transfer from inital file offset */ |
| | 496 | } |
| | 497 | |
| | 498 | return reqs; |