/* * Sends a data-product to an LDM using the LDM-5 messages COMINGSOON and * BLOCKDATA. * * Arguments: * proxy Pointer to the LDM proxy data-structure. * info Pointer to the data-product's metadata. * datap Pointer to the data-product's data. * Returns: * 0 Success. * LP_UNWANTED Data-product was unwanted. * LP_TIMEDOUT The RPC call timed-out. "log_start()" called. * LP_RPC_ERROR RPC error. "log_start()" called. * LP_LDM_ERROR LDM error. "log_start()" called. */ static LdmProxyStatus my_csbd_5( LdmProxy* const proxy, product* const product) { CLIENT* const clnt = proxy->clnt; LdmProxyStatus status = 0; /* success */ ldm_replyt reply; prod_info* const info = &product->info; memset(&reply, 0, sizeof(ldm_replyt)); status = my_comingsoon_5(proxy, info, DBUFMAX, &reply); if (0 == status) { if (reply.code != OK) { if (reply.code == DONT_SEND) { status = LP_UNWANTED; } else { LOG_START2("send_5: %s: %s", info->ident, s_ldm_errt(reply.code)); status = LP_LDM_ERROR; } } else { size_t unsent = info->sz; char* data = product->data; datapkt pkt; pkt.signaturep = &info->signature; pkt.pktnum = 0; while (unsent > 0) { size_t nsend = DBUFMAX < unsent ? DBUFMAX : unsent; pkt.data.dbuf_len = (u_int)nsend; pkt.data.dbuf_val = data; status = my_blkdata_5(proxy, &pkt, &reply); if (0 != status) { getStatus(proxy, "BLOCKDATA_5", info); break; } else if (reply.code != OK) { LOG_START1("Unexpected reply from LDM: %s", s_ldm_errt(reply.code)); status = LP_LDM_ERROR; break; } pkt.pktnum++; data += nsend; unsent -= nsend; } } /* reply.code == OK */ } /* OK COMINGSOON */ return status; }
/* * Send a product from file-descriptor to clnt using LDM-5 protocol. */ static void send_product_5(CLIENT *clnt, int fd, prod_info *infop) { static ldm_replyt reply; enum clnt_stat rpc_stat; datapkt pkt; ssize_t unsent; ssize_t nread; char buf[DBUFMAX]; rpc_stat = my_comingsoon_5(clnt, infop, DBUFMAX, &reply); if(rpc_stat != RPC_SUCCESS) { uerror("send_product_5: %s %s", infop->ident, clnt_sperrno(rpc_stat)); return; } /* else */ if(reply.code != OK) { if(reply.code == DONT_SEND) uinfo("send_product_5: %s: %s", infop->ident, s_ldm_errt(reply.code)); else uerror("send_product_5: %s: %s", infop->ident, s_ldm_errt(reply.code)); return; } pkt.signaturep = &infop->signature; pkt.pktnum = 0; for(unsent = (ssize_t)infop->sz; unsent > 0; unsent -= nread ) { nread = read(fd, buf, DBUFMAX); if(nread <= 0) { serror("read: %s (seqno %d)", infop->ident, infop->seqno); break; } /* else */ pkt.data.dbuf_len = (u_int)nread; pkt.data.dbuf_val = buf; rpc_stat = my_blkdata_5(clnt, &pkt, &reply); if(rpc_stat != RPC_SUCCESS) break; if(reply.code != OK) break; pkt.pktnum++; } }