示例#1
0
/*
 * Send a data-product to an LDM using the LDM-6 HEREIS message.
 *
 * Arguments:
 *      proxy           Pointer to the LDM proxy data-structure.
 *      product         Pointer to the data-product to be sent.
 * Return:
 *      0               Success.
 *      LP_TIMEDOUT     RPC timeout. "log_start()" called.
 *      LP_RPC_ERROR    RPC error. "log_start()" called.
 *      LP_LDM_ERROR    LDM error. "log_start()" called.
 */
static LdmProxyStatus
my_hereis_6(
    LdmProxy* const     proxy,
    product* const      product)
{
    LdmProxyStatus      status = 0;     /* success */

    udebug("Sending file via HEREIS_6");

    if (NULL == hereis_6(product, proxy->clnt)) {
        status = getStatus(proxy, "HEREIS_6", &product->info);
    }

    return status;
}
示例#2
0
/*
 * Send a product from file-descriptor to clnt using LDM-6 protocol.
 */
static void
send_product_6(CLIENT *clnt, int fd, prod_info *infop)
{
    unsigned size = infop->sz;

    if (size <= max_hereis) {
        /*
         * The file is small enough to be sent in a single HEREIS message.
         */
        void*   buf = (char*)malloc(size);

        udebug("Sending file via HEREIS");

        if (NULL == buf) {
            serror("Couldn't allocate %u bytes for product data", size);
        }
        else {
            ssize_t nread = read(fd, buf, size);

            if(nread != size) {
                serror("Couldn't read %u bytes of data", size);
            }
            else {
                product product;

                product.info = *infop;
                product.data = buf;

                if (NULL == hereis_6(&product, clnt)) {
                    uerror("%s: HEREIS_6 failure: %s",
                        remote, clnt_errmsg(clnt));
                }
            }

            free(buf);
        }
    }
    else {
        /*
         * The file is so large that it must be sent via COMINGSOON/BLKDATA 
         * messages.
         */
        comingsoon_reply_t* reply;
        comingsoon_args     soonArg;

        udebug("Sending file via COMINGSOON/BLKDATA");

        soonArg.infop = infop;
        soonArg.pktsz = size;
        
        reply = comingsoon_6(&soonArg, clnt);

        if (NULL == reply) {
            uerror("%s: COMINGSOON_6 failure: %s", remote, clnt_errmsg(clnt));
        }
        else {
            if (DONT_SEND == *reply) {
                if (ulogIsVerbose() || ulogIsDebug())
                    uinfo("Downstream LDM says don't send: %s",
                        s_prod_info(NULL, 0, infop, ulogIsDebug()));
            }
            else if (0 != *reply) {
                uwarn("Unexpected reply (%s) from downstream LDM: %s",
                    s_prod_info(NULL, 0, infop, ulogIsDebug()));
            }
            else {
                void*   buf = (char*)malloc(size);

                if (NULL == buf) {
                    serror("Couldn't allocate %u bytes for product data", 
                        size);
                }
                else {
                    ssize_t nread = read(fd, buf, size);

                    if(nread != size) {
                        serror("Couldn't read %u bytes of data", size);
                    }
                    else {
                        datapkt packet;

                        packet.signaturep = (signaturet*)&infop->signature;
                        packet.pktnum = 0;
                        packet.data.dbuf_len = size;
                        packet.data.dbuf_val = buf;

                        if (NULL == blkdata_6(&packet, clnt)) {
                            uerror("%s: BLKDATA_6 failure: %s",
                                remote, clnt_errmsg(clnt));
                        }
                    }

                    free(buf);
                }
            }
        }
    }
}