2004-07-01 18:49:54 +04:00
|
|
|
#include "mca/oob/tcp/oob_tcp.h"
|
|
|
|
|
|
|
|
/*
|
2004-07-14 01:03:03 +04:00
|
|
|
* Similiar to unix readv(2)
|
2004-07-01 18:49:54 +04:00
|
|
|
*
|
2004-08-05 03:42:51 +04:00
|
|
|
* @param peer (IN) Opaque name of peer process or MCA_OOB_NAME_ANY for wildcard receive.
|
2004-07-01 18:49:54 +04:00
|
|
|
* @param msg (IN) Array of iovecs describing user buffers and lengths.
|
|
|
|
* @param types (IN) Parallel array to iovecs describing data type of each iovec element.
|
|
|
|
* @param count (IN) Number of elements in iovec array.
|
2004-08-03 01:24:00 +04:00
|
|
|
* @param tag (IN) User supplied tag for matching send/recv.
|
2004-07-15 23:08:54 +04:00
|
|
|
* @param flags (IN) May be MCA_OOB_PEEK to return up to the number of bytes provided in the
|
2004-07-01 18:49:54 +04:00
|
|
|
* iovec array without removing the message from the queue.
|
|
|
|
* @return OMPI error code (<0) on error or number of bytes actually received.
|
|
|
|
*/
|
2004-08-03 01:24:00 +04:00
|
|
|
int mca_oob_tcp_recv(
|
|
|
|
ompi_process_name_t* peer,
|
|
|
|
const struct iovec *iov,
|
|
|
|
int count,
|
|
|
|
int tag,
|
|
|
|
int flags)
|
2004-07-01 18:49:54 +04:00
|
|
|
{
|
2004-08-03 01:24:00 +04:00
|
|
|
mca_oob_tcp_msg_t *msg;
|
|
|
|
int i, rc, size = 0;
|
|
|
|
|
2004-07-15 23:08:54 +04:00
|
|
|
/* lock the tcp struct */
|
2004-08-03 01:24:00 +04:00
|
|
|
OMPI_THREAD_LOCK(&mca_oob_tcp_component.tcp_match_lock);
|
|
|
|
|
|
|
|
/* check to see if a matching receive is on the list */
|
|
|
|
msg = mca_oob_tcp_msg_match_recv(peer, tag);
|
|
|
|
if(NULL != msg) {
|
|
|
|
|
|
|
|
/* if we are just doing peek, return bytes without dequeing message */
|
2004-08-04 03:39:46 +04:00
|
|
|
if(msg->msg_rc < 0) {
|
|
|
|
OMPI_THREAD_UNLOCK(&mca_oob_tcp_component.tcp_match_lock);
|
2004-08-03 01:24:00 +04:00
|
|
|
return msg->msg_rc;
|
2004-08-04 03:39:46 +04:00
|
|
|
}
|
2004-08-03 01:24:00 +04:00
|
|
|
|
|
|
|
rc = mca_oob_tcp_msg_copy(msg, iov, count);
|
|
|
|
if(rc >= 0 && MCA_OOB_TRUNC & flags) {
|
|
|
|
rc = 0;
|
|
|
|
for(i=0; i<msg->msg_rwcnt; i++)
|
|
|
|
rc += msg->msg_rwiov[i].iov_len;
|
|
|
|
}
|
|
|
|
if(MCA_OOB_PEEK & flags) {
|
2004-08-03 02:16:35 +04:00
|
|
|
OMPI_THREAD_UNLOCK(&mca_oob_tcp_component.tcp_match_lock);
|
2004-08-03 01:24:00 +04:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* otherwise dequeue the message and return to free list */
|
|
|
|
ompi_list_remove_item(&mca_oob_tcp_component.tcp_msg_recv, (ompi_list_item_t *) msg);
|
|
|
|
MCA_OOB_TCP_MSG_RETURN(msg);
|
2004-08-03 02:16:35 +04:00
|
|
|
OMPI_THREAD_UNLOCK(&mca_oob_tcp_component.tcp_match_lock);
|
2004-08-03 01:24:00 +04:00
|
|
|
return rc;
|
2004-07-15 23:08:54 +04:00
|
|
|
}
|
2004-08-03 01:24:00 +04:00
|
|
|
|
|
|
|
/* the message has not already been received. So we add it to the receive queue */
|
|
|
|
MCA_OOB_TCP_MSG_ALLOC(msg, rc);
|
2004-07-15 23:08:54 +04:00
|
|
|
if(NULL == msg) {
|
2004-08-03 02:16:35 +04:00
|
|
|
OMPI_THREAD_UNLOCK(&mca_oob_tcp_component.tcp_match_lock);
|
2004-08-03 01:24:00 +04:00
|
|
|
return rc;
|
2004-07-15 23:08:54 +04:00
|
|
|
}
|
2004-08-03 01:24:00 +04:00
|
|
|
|
|
|
|
/* determine overall size of user supplied buffer */
|
|
|
|
for(i = 0; i < count; i++) {
|
|
|
|
size += iov[i].iov_len;
|
|
|
|
}
|
|
|
|
|
2004-07-15 23:08:54 +04:00
|
|
|
/* fill in the struct */
|
2004-08-03 01:24:00 +04:00
|
|
|
msg->msg_type = MCA_OOB_TCP_POSTED;
|
|
|
|
msg->msg_rc = 0;
|
|
|
|
msg->msg_flags = flags;
|
|
|
|
msg->msg_uiov = iov;
|
|
|
|
msg->msg_ucnt = count;
|
2004-07-15 23:08:54 +04:00
|
|
|
msg->msg_cbfunc = NULL;
|
2004-08-03 01:24:00 +04:00
|
|
|
msg->msg_cbdata = NULL;
|
2004-07-15 23:08:54 +04:00
|
|
|
msg->msg_complete = false;
|
2004-08-03 01:24:00 +04:00
|
|
|
msg->msg_peer = *peer;
|
2004-08-04 18:33:02 +04:00
|
|
|
msg->msg_rwbuf = NULL;
|
|
|
|
msg->msg_rwiov = NULL;
|
2004-08-03 01:24:00 +04:00
|
|
|
ompi_list_append(&mca_oob_tcp_component.tcp_msg_post, (ompi_list_item_t *) msg);
|
2004-08-03 02:16:35 +04:00
|
|
|
OMPI_THREAD_UNLOCK(&mca_oob_tcp_component.tcp_match_lock);
|
2004-08-03 01:24:00 +04:00
|
|
|
|
|
|
|
/* wait for the receive to complete */
|
|
|
|
mca_oob_tcp_msg_wait(msg, &rc);
|
|
|
|
MCA_OOB_TCP_MSG_RETURN(msg);
|
|
|
|
return rc;
|
2004-07-01 18:49:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Non-blocking version of mca_oob_recv().
|
|
|
|
*
|
2004-08-05 03:42:51 +04:00
|
|
|
* @param peer (IN) Opaque name of peer process or MCA_OOB_NAME_ANY for wildcard receive.
|
2004-07-01 18:49:54 +04:00
|
|
|
* @param msg (IN) Array of iovecs describing user buffers and lengths.
|
|
|
|
* @param count (IN) Number of elements in iovec array.
|
2004-08-03 01:24:00 +04:00
|
|
|
* @param tag (IN) User supplied tag for matching send/recv.
|
2004-07-15 23:08:54 +04:00
|
|
|
* @param flags (IN) May be MCA_OOB_PEEK to return up to size bytes of msg w/out removing it from the queue,
|
2004-07-01 18:49:54 +04:00
|
|
|
* @param cbfunc (IN) Callback function on recv completion.
|
|
|
|
* @param cbdata (IN) User data that is passed to callback function.
|
2004-08-03 01:24:00 +04:00
|
|
|
* @return OMPI error code (<0) on error.
|
2004-07-01 18:49:54 +04:00
|
|
|
*/
|
2004-08-03 01:24:00 +04:00
|
|
|
int mca_oob_tcp_recv_nb(
|
|
|
|
ompi_process_name_t* peer,
|
|
|
|
const struct iovec* iov,
|
|
|
|
int count,
|
|
|
|
int tag,
|
|
|
|
int flags,
|
|
|
|
mca_oob_callback_fn_t cbfunc,
|
|
|
|
void* cbdata)
|
2004-07-01 18:49:54 +04:00
|
|
|
{
|
2004-08-03 01:24:00 +04:00
|
|
|
mca_oob_tcp_msg_t *msg;
|
|
|
|
int i, rc, size = 0;
|
|
|
|
|
2004-07-15 23:08:54 +04:00
|
|
|
/* lock the tcp struct */
|
2004-08-03 02:16:35 +04:00
|
|
|
OMPI_THREAD_LOCK(&mca_oob_tcp_component.tcp_match_lock);
|
2004-08-03 01:24:00 +04:00
|
|
|
|
|
|
|
/* check to see if a matching receive is on the list */
|
|
|
|
msg = mca_oob_tcp_msg_match_recv(peer, tag);
|
|
|
|
if(NULL != msg) {
|
|
|
|
|
|
|
|
if(msg->msg_rc < 0)
|
|
|
|
return msg->msg_rc;
|
|
|
|
|
|
|
|
/* if we are just doing peek, return bytes without dequeing message */
|
|
|
|
rc = mca_oob_tcp_msg_copy(msg, iov, count);
|
|
|
|
if(rc >= 0 && MCA_OOB_TRUNC & flags) {
|
|
|
|
rc = 0;
|
|
|
|
for(i=0; i<msg->msg_rwcnt; i++)
|
|
|
|
rc += msg->msg_rwiov[i].iov_len;
|
|
|
|
}
|
|
|
|
if(MCA_OOB_PEEK & flags) {
|
2004-08-03 02:16:35 +04:00
|
|
|
OMPI_THREAD_UNLOCK(&mca_oob_tcp_component.tcp_match_lock);
|
2004-08-03 01:24:00 +04:00
|
|
|
cbfunc(rc, &msg->msg_peer, iov, count, tag, cbdata);
|
|
|
|
return 0;
|
2004-07-15 23:08:54 +04:00
|
|
|
}
|
2004-08-03 01:24:00 +04:00
|
|
|
|
|
|
|
/* otherwise dequeue the message and return to free list */
|
|
|
|
ompi_list_remove_item(&mca_oob_tcp_component.tcp_msg_recv, (ompi_list_item_t *) msg);
|
2004-08-03 02:16:35 +04:00
|
|
|
OMPI_THREAD_UNLOCK(&mca_oob_tcp_component.tcp_match_lock);
|
2004-08-03 01:24:00 +04:00
|
|
|
cbfunc(rc, &msg->msg_peer, iov, count, tag, cbdata);
|
|
|
|
MCA_OOB_TCP_MSG_RETURN(msg);
|
|
|
|
return 0;
|
2004-07-15 23:08:54 +04:00
|
|
|
}
|
2004-08-03 01:24:00 +04:00
|
|
|
|
|
|
|
/* the message has not already been received. So we add it to the receive queue */
|
|
|
|
MCA_OOB_TCP_MSG_ALLOC(msg, rc);
|
2004-07-15 23:08:54 +04:00
|
|
|
if(NULL == msg) {
|
2004-08-03 02:16:35 +04:00
|
|
|
OMPI_THREAD_UNLOCK(&mca_oob_tcp_component.tcp_match_lock);
|
2004-08-03 01:24:00 +04:00
|
|
|
return rc;
|
2004-07-15 23:08:54 +04:00
|
|
|
}
|
2004-08-03 01:24:00 +04:00
|
|
|
|
|
|
|
/* determine overall size of user supplied buffer */
|
|
|
|
for(i = 0; i < count; i++) {
|
|
|
|
size += iov[i].iov_len;
|
|
|
|
}
|
|
|
|
|
2004-07-15 23:08:54 +04:00
|
|
|
/* fill in the struct */
|
2004-08-03 01:24:00 +04:00
|
|
|
msg->msg_type = MCA_OOB_TCP_POSTED;
|
|
|
|
msg->msg_rc = 0;
|
|
|
|
msg->msg_flags = flags;
|
|
|
|
msg->msg_uiov = iov;
|
|
|
|
msg->msg_ucnt = count;
|
2004-07-15 23:08:54 +04:00
|
|
|
msg->msg_cbfunc = cbfunc;
|
|
|
|
msg->msg_cbdata = cbdata;
|
|
|
|
msg->msg_complete = false;
|
2004-08-03 01:24:00 +04:00
|
|
|
msg->msg_peer = *peer;
|
2004-08-04 18:33:02 +04:00
|
|
|
msg->msg_rwbuf = NULL;
|
|
|
|
msg->msg_rwiov = NULL;
|
2004-08-03 01:24:00 +04:00
|
|
|
ompi_list_append(&mca_oob_tcp_component.tcp_msg_post, (ompi_list_item_t *) msg);
|
2004-08-03 02:16:35 +04:00
|
|
|
OMPI_THREAD_UNLOCK(&mca_oob_tcp_component.tcp_match_lock);
|
2004-08-03 01:24:00 +04:00
|
|
|
return 0;
|
2004-07-01 18:49:54 +04:00
|
|
|
}
|
|
|
|
|