From 238822faf317fe8d608e8f51785c632b1df4b6de Mon Sep 17 00:00:00 2001 From: Tim Woodall Date: Thu, 2 Sep 2004 14:20:13 +0000 Subject: [PATCH] oops - forgot to check these in This commit was SVN r2448. --- src/mca/oob/tcp/oob_tcp_addr.c | 107 +++++++++++++++++++++++++++++++++ src/mca/oob/tcp/oob_tcp_addr.h | 60 ++++++++++++++++++ src/mca/oob/tcp/oob_tcp_peer.h | 3 +- 3 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 src/mca/oob/tcp/oob_tcp_addr.c create mode 100644 src/mca/oob/tcp/oob_tcp_addr.h diff --git a/src/mca/oob/tcp/oob_tcp_addr.c b/src/mca/oob/tcp/oob_tcp_addr.c new file mode 100644 index 0000000000..34f4f568d9 --- /dev/null +++ b/src/mca/oob/tcp/oob_tcp_addr.c @@ -0,0 +1,107 @@ +#include "ompi_config.h" +#include +#include +#include +#include +#include "include/constants.h" +#include "util/if.h" +#include "oob_tcp.h" +#include "oob_tcp_addr.h" + + +static void mca_oob_tcp_addr_construct(mca_oob_tcp_addr_t* addr) +{ + memset(&addr->addr_name, 0, sizeof(addr->addr_name)); + addr->addr_count = 0; + addr->addr_alloc = 0; + addr->addr_next = 0; + addr->addr_inet = NULL; +} + +static void mca_oob_tcp_addr_destruct(mca_oob_tcp_addr_t* addr) +{ + if(addr->addr_inet != NULL) + free(addr->addr_inet); +} + +OBJ_CLASS_INSTANCE( + mca_oob_tcp_addr_t, + ompi_object_t, + mca_oob_tcp_addr_construct, + mca_oob_tcp_addr_destruct); + + +void mca_oob_tcp_addr_pack(ompi_buffer_t buffer) +{ + uint32_t count = 0; + int i; + + ompi_pack(buffer, &mca_oob_name_self, 1, OMPI_NAME); + for(i=ompi_ifbegin(); i>0; i=ompi_ifnext(i)) { + struct sockaddr_in inaddr; + ompi_ifindextoaddr(i, (struct sockaddr*)&inaddr, sizeof(inaddr)); + if(inaddr.sin_addr.s_addr == inet_addr("127.0.0.1")) + continue; + count++; + } + ompi_pack(buffer, &count, 1, OMPI_INT32); + + for(i=ompi_ifbegin(); i>0; i=ompi_ifnext(i)) { + struct sockaddr_in inaddr; + ompi_ifindextoaddr(i, (struct sockaddr*)&inaddr, sizeof(inaddr)); + if(inaddr.sin_addr.s_addr == inet_addr("127.0.0.1")) + continue; + inaddr.sin_port = mca_oob_tcp_component.tcp_listen_port; + ompi_pack(buffer,&inaddr,sizeof(inaddr),OMPI_BYTE); + } +} + + +mca_oob_tcp_addr_t* mca_oob_tcp_addr_unpack(ompi_buffer_t buffer) +{ + mca_oob_tcp_addr_t* addr = OBJ_NEW(mca_oob_tcp_addr_t); + if(NULL == addr) + return NULL; + + ompi_unpack(buffer, &addr->addr_name, 1, OMPI_NAME); + ompi_unpack(buffer, &addr->addr_count, 1, OMPI_INT32); + if(addr->addr_count != 0) { + addr->addr_inet = malloc(sizeof(struct sockaddr_in) * addr->addr_count); + if(NULL == addr->addr_inet) { + OBJ_RELEASE(addr); + return NULL; + } + addr->addr_alloc = addr->addr_count; + ompi_unpack(buffer, addr->addr_inet, (addr->addr_count * sizeof(struct sockaddr_in)), OMPI_BYTE); + } + return addr; +} + + +int mca_oob_tcp_addr_get_next(mca_oob_tcp_addr_t* addr, struct sockaddr_in* inaddr) +{ + if(addr == NULL || addr->addr_count == 0) + return OMPI_ERROR; + *inaddr = addr->addr_inet[addr->addr_next]; + if(++addr->addr_next >= addr->addr_count) + addr->addr_next = 0; + return OMPI_SUCCESS; +} + + +int mca_oob_tcp_addr_insert(mca_oob_tcp_addr_t* addr, const struct sockaddr_in* inaddr) +{ + if(addr->addr_alloc == 0) { + addr->addr_alloc = 2; + addr->addr_inet = malloc(addr->addr_alloc * sizeof(struct sockaddr_in)); + } else if(addr->addr_count == addr->addr_alloc) { + addr->addr_alloc <<= 1; + addr->addr_inet = realloc(addr->addr_inet, addr->addr_alloc * sizeof(struct sockaddr_in)); + } + if(NULL == addr->addr_inet) + return OMPI_ERR_OUT_OF_RESOURCE; + memcpy(addr->addr_inet+addr->addr_count, inaddr, sizeof(struct sockaddr_in)); + addr->addr_count++; + return OMPI_SUCCESS; +} + diff --git a/src/mca/oob/tcp/oob_tcp_addr.h b/src/mca/oob/tcp/oob_tcp_addr.h new file mode 100644 index 0000000000..a42c04e9a0 --- /dev/null +++ b/src/mca/oob/tcp/oob_tcp_addr.h @@ -0,0 +1,60 @@ +/* + * $HEADER$ + */ +/** @file: + * + * Contains header used by tcp oob. + */ + +#ifndef _MCA_OOB_TCP_ADDR_H_ +#define _MCA_OOB_TCP_ADDR_H_ + +#include "ompi_config.h" +#include +#include +#include "class/ompi_object.h" +#include "util/pack.h" +#include "mca/ns/ns.h" + +/** + * Address info published to registry + */ +struct mca_oob_tcp_addr_t { + ompi_object_t super; + ompi_process_name_t addr_name; + uint32_t addr_count; + uint32_t addr_next; + uint32_t addr_alloc; + struct sockaddr_in* addr_inet; +}; +typedef struct mca_oob_tcp_addr_t mca_oob_tcp_addr_t; + +OBJ_CLASS_DECLARATION(mca_oob_tcp_addr_t); + +/** + * Unpack the contact information posted by the peer. + */ + +mca_oob_tcp_addr_t* mca_oob_tcp_addr_unpack(ompi_buffer_t); + +/** + * Pack this hosts addressing info into a buffer for posting + * into the registry. + */ + +void mca_oob_tcp_addr_pack(ompi_buffer_t); + +/** + * + */ + +int mca_oob_tcp_addr_insert(mca_oob_tcp_addr_t*, const struct sockaddr_in*); + +/** + * + */ + +int mca_oob_tcp_addr_get_next(mca_oob_tcp_addr_t*, struct sockaddr_in*); + +#endif + diff --git a/src/mca/oob/tcp/oob_tcp_peer.h b/src/mca/oob/tcp/oob_tcp_peer.h index 1e1b998285..b3e14145cc 100644 --- a/src/mca/oob/tcp/oob_tcp_peer.h +++ b/src/mca/oob/tcp/oob_tcp_peer.h @@ -126,7 +126,8 @@ void mca_oob_tcp_peer_close(mca_oob_tcp_peer_t* peer); void mca_oob_tcp_peer_resolved(mca_oob_tcp_peer_t* peer, mca_oob_tcp_addr_t* addr); /* - * + * Send the process identifier to the peer - so that + * temporary names can be updated to actuals. */ int mca_oob_tcp_peer_send_ident(mca_oob_tcp_peer_t* peer);