2004-07-01 18:49:54 +04:00
|
|
|
/*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
/** @file:
|
|
|
|
*
|
|
|
|
* Contains the data structure which describes each connection
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _MCA_OOB_TCP_PEER_H_
|
|
|
|
#define _MCA_OOB_TCP_PEER_H_
|
|
|
|
|
|
|
|
#include "mca/ns/ns.h"
|
|
|
|
#include "class/ompi_list.h"
|
2004-07-01 21:45:34 +04:00
|
|
|
#include "class/ompi_rb_tree.h"
|
2004-07-01 18:49:54 +04:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include "threads/mutex.h"
|
2004-07-01 21:45:34 +04:00
|
|
|
#include <string.h>
|
2004-07-15 23:08:54 +04:00
|
|
|
#include "mca/oob/tcp/oob_tcp.h"
|
|
|
|
#include "mca/oob/tcp/oob_tcp_msg.h"
|
2004-07-01 18:49:54 +04:00
|
|
|
/**
|
|
|
|
* the state of the connection
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
MCA_OOB_TCP_CLOSED,
|
|
|
|
MCA_OOB_TCP_CONNECTING,
|
|
|
|
MCA_OOB_TCP_CONNECT_ACK,
|
|
|
|
MCA_OOB_TCP_CONNECTED,
|
|
|
|
MCA_OOB_TCP_FAILED
|
|
|
|
} mca_oob_tcp_state_t;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2004-08-03 01:24:00 +04:00
|
|
|
* This structure describes a peer
|
2004-07-01 18:49:54 +04:00
|
|
|
*/
|
|
|
|
struct mca_oob_tcp_peer_t {
|
2004-07-13 02:46:57 +04:00
|
|
|
ompi_list_item_t super; /**< allow this to be on a list */
|
|
|
|
ompi_process_name_t peer_name; /**< the name of the peer */
|
|
|
|
mca_oob_tcp_state_t peer_state; /**< the state of the connection */
|
|
|
|
int peer_retries; /**< number of times connection attempt has failed */
|
|
|
|
struct sockaddr_in peer_addr; /**< the address of the peer process */
|
|
|
|
int peer_sd; /**< socket descriptor of the connection */
|
|
|
|
ompi_event_t peer_send_event; /**< registration with event thread for send events */
|
|
|
|
ompi_event_t peer_recv_event; /**< registration with event thread for recv events */
|
2004-08-28 05:15:19 +04:00
|
|
|
ompi_event_t peer_timer_event; /**< used for timer callback */
|
2004-08-03 01:24:00 +04:00
|
|
|
ompi_mutex_t peer_lock; /**< protect critical data structures */
|
2004-07-13 02:46:57 +04:00
|
|
|
ompi_list_t peer_send_queue; /**< list of messages to send */
|
|
|
|
mca_oob_tcp_msg_t *peer_send_msg; /**< current send in progress */
|
|
|
|
mca_oob_tcp_msg_t *peer_recv_msg; /**< current recv in progress */
|
2004-07-01 18:49:54 +04:00
|
|
|
};
|
2004-08-10 03:07:53 +04:00
|
|
|
/**
|
|
|
|
* Convenience Typedef
|
|
|
|
*/
|
2004-07-01 18:49:54 +04:00
|
|
|
typedef struct mca_oob_tcp_peer_t mca_oob_tcp_peer_t;
|
2004-07-01 21:45:34 +04:00
|
|
|
|
2004-08-03 01:24:00 +04:00
|
|
|
/*
|
|
|
|
* Class declaration.
|
|
|
|
*/
|
|
|
|
|
|
|
|
OBJ_CLASS_DECLARATION(mca_oob_tcp_peer_t);
|
|
|
|
|
2004-07-14 01:03:03 +04:00
|
|
|
/**
|
|
|
|
* Get a new peer data structure
|
2004-07-15 17:51:40 +04:00
|
|
|
*/
|
2004-07-13 02:46:57 +04:00
|
|
|
#define MCA_OOB_TCP_PEER_ALLOC(peer, rc) \
|
|
|
|
{ \
|
|
|
|
ompi_list_item_t* item; \
|
2004-08-02 04:24:22 +04:00
|
|
|
OMPI_FREE_LIST_GET(&mca_oob_tcp_component.tcp_peer_free, item, rc); \
|
2004-07-13 02:46:57 +04:00
|
|
|
peer = (mca_oob_tcp_peer_t*)item; \
|
|
|
|
}
|
2004-07-14 01:03:03 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a peer data structure
|
|
|
|
*/
|
2004-07-13 02:46:57 +04:00
|
|
|
#define MCA_OOB_TCP_PEER_RETURN(peer) \
|
|
|
|
{ \
|
2004-08-02 04:24:22 +04:00
|
|
|
OMPI_FREE_LIST_RETURN(&mca_oob_tcp_component.tcp_peer_free, (ompi_list_item_t*)peer); \
|
2004-07-13 02:46:57 +04:00
|
|
|
}
|
|
|
|
|
2004-07-01 21:45:34 +04:00
|
|
|
#if defined(c_plusplus) || defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
2004-07-13 02:46:57 +04:00
|
|
|
* Lookup a peer in the cache - if it doesn't exists
|
|
|
|
* create one and cache it.
|
2004-07-01 18:49:54 +04:00
|
|
|
*
|
|
|
|
* @param peer_name the name of the peer
|
2004-07-15 23:08:54 +04:00
|
|
|
* @param get_lock get the lock on the tcp struct. This should always be true
|
|
|
|
* unless the caller already owns the lock.
|
2004-07-14 01:03:03 +04:00
|
|
|
* @retval pointer to the peer's (possibly newly created) struture
|
2004-07-01 18:49:54 +04:00
|
|
|
* @retval NULL if there was a problem
|
|
|
|
*/
|
2004-08-13 02:41:42 +04:00
|
|
|
mca_oob_tcp_peer_t *mca_oob_tcp_peer_lookup(ompi_process_name_t* peer_name, bool get_lock);
|
2004-07-01 18:49:54 +04:00
|
|
|
|
|
|
|
/**
|
2004-07-13 02:46:57 +04:00
|
|
|
* Start sending a message to the specified peer. The routine
|
|
|
|
* can return before the send completes.
|
2004-07-01 18:49:54 +04:00
|
|
|
*
|
2004-07-13 02:46:57 +04:00
|
|
|
* @param peer The peer process.
|
|
|
|
* @param msg The message to send.
|
|
|
|
* @retval OMPI_SUCCESS or error code on failure.
|
2004-07-01 18:49:54 +04:00
|
|
|
*/
|
2004-07-13 02:46:57 +04:00
|
|
|
int mca_oob_tcp_peer_send(mca_oob_tcp_peer_t* peer, mca_oob_tcp_msg_t* msg);
|
|
|
|
|
2004-08-03 01:24:00 +04:00
|
|
|
/**
|
|
|
|
* Connection request for this peer. Check the status of our connection
|
|
|
|
* before accepting the peers.
|
|
|
|
*
|
|
|
|
* @param peer The peer process.
|
|
|
|
* @param sd Incoming connection request.
|
|
|
|
*/
|
|
|
|
bool mca_oob_tcp_peer_accept(mca_oob_tcp_peer_t* peer, int sd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cleanup/close the connection to the peer.
|
|
|
|
*
|
|
|
|
* @param peer The peer process.
|
|
|
|
*/
|
|
|
|
void mca_oob_tcp_peer_close(mca_oob_tcp_peer_t* peer);
|
|
|
|
|
2004-08-16 23:39:54 +04:00
|
|
|
/**
|
|
|
|
* Attempt to resolve peer address.
|
|
|
|
*/
|
|
|
|
int mca_oob_tcp_peer_name_lookup(mca_oob_tcp_peer_t* peer);
|
|
|
|
|
2004-07-01 21:45:34 +04:00
|
|
|
#if defined(c_plusplus) || defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-07-01 18:49:54 +04:00
|
|
|
#endif /* _MCA_OOB_TCP_PEER_H */
|
|
|
|
|