1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "orte_config.h"
#include "orte/orte_constants.h"
#include "orte/mca/ns/ns_types.h"
#include "orte/dss/dss.h"
#include "orte/mca/oob/oob.h"
#include "orte/mca/oob/base/base.h"
#include <string.h>
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
/*
* internal struct for non-blocking packed sends
*/
struct mca_oob_send_cbdata {
orte_buffer_t* cbbuf;
struct iovec cbiov;
mca_oob_callback_packed_fn_t cbfunc;
void* cbdata;
};
typedef struct mca_oob_send_cbdata mca_oob_send_cbdata_t;
static void mca_oob_send_callback(
int status,
orte_process_name_t* peer,
struct iovec* msg,
int count,
int tag,
void* cbdata);
/*
* Non-blocking version of mca_oob_send().
*
* @param peer (IN) Opaque name of peer process.
* @param msg (IN) Array of iovecs describing user buffers and lengths.
* @param count (IN) Number of elements in iovec array.
* @param flags (IN) Currently unused.
* @param cbfunc (IN) Callback function on send completion.
* @param cbdata (IN) User data that is passed to callback function.
* @return OMPI error code (<0) on error number of bytes actually sent.
*
*/
int mca_oob_send_nb(orte_process_name_t* peer, struct iovec* msg, int count, int tag,
int flags, mca_oob_callback_fn_t cbfunc, void* cbdata)
{
return(mca_oob.oob_send_nb(peer, msg, count, tag, flags, cbfunc, cbdata));
}
/**
* Non-blocking version of mca_oob_send_packed().
*
* @param peer (IN) Opaque name of peer process.
* @param buffer (IN) Opaque buffer handle.
* @param tag (IN) User defined tag for matching send/recv.
* @param flags (IN) Currently unused.
* @param cbfunc (IN) Callback function on send completion.
* @param cbdata (IN) User data that is passed to callback function.
* @return OMPI error code (<0) on error number of bytes actually sent.
*
* The user supplied callback function is called when the send completes. Note that
* the callback may occur before the call to mca_oob_send returns to the caller,
* if the send completes during the call.
*
*/
int mca_oob_send_packed_nb(
orte_process_name_t* peer,
orte_buffer_t* buffer,
int tag,
int flags,
mca_oob_callback_packed_fn_t cbfunc,
void* cbdata)
{
mca_oob_send_cbdata_t *oob_cbdata;
void *dataptr;
size_t datalen;
int rc;
/* first build iovec from buffer information */
rc = orte_dss.unload(buffer, &dataptr, &datalen);
if (rc != ORTE_SUCCESS) {
return rc;
}
orte_dss.load(buffer, dataptr, datalen);
/* allocate a struct to pass into callback */
if(NULL == (oob_cbdata = malloc(sizeof(mca_oob_send_cbdata_t)))) {
return ORTE_ERR_OUT_OF_RESOURCE;
}
oob_cbdata->cbbuf = buffer;
oob_cbdata->cbfunc = cbfunc;
oob_cbdata->cbdata = cbdata;
oob_cbdata->cbiov.iov_base = dataptr;
oob_cbdata->cbiov.iov_len = datalen;
/* queue up the request */
rc = mca_oob.oob_send_nb(peer, &oob_cbdata->cbiov, 1, tag, flags, mca_oob_send_callback, oob_cbdata);
if(rc < 0) {
free(oob_cbdata);
}
return rc;
}
/**
* Callback function on send completion for buffer PACKED message only.
* i.e. only mca_oob_send_packed_nb and mca_oob_recv_packed_nb USE this.
*
* @param status (IN) Completion status - equivalent to the return value from blocking send/recv.
* @param peer (IN) Opaque name of peer process.
* @param buffer (IN) For sends, this is a pointer to a prepacked buffer
For recvs, OOB creates and returns a buffer
* @param tag (IN) User defined tag for matching send/recv.
* @param cbdata (IN) User data.
*/
static void mca_oob_send_callback(
int status,
orte_process_name_t* peer,
struct iovec* msg,
int count,
int tag,
void* cbdata)
{
/* validate status */
mca_oob_send_cbdata_t *oob_cbdata = cbdata;
if(status < 0) {
oob_cbdata->cbfunc(status, peer, NULL, tag, oob_cbdata->cbdata);
free(oob_cbdata);
return;
}
oob_cbdata->cbfunc(status, peer, oob_cbdata->cbbuf, tag, oob_cbdata->cbdata);
free(oob_cbdata);
}
|