Commit fdf36fd4 authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

added get_addr in endpoint

parent 532e5885
...@@ -102,6 +102,18 @@ public: ...@@ -102,6 +102,18 @@ public:
return m_addr == HG_ADDR_NULL; return m_addr == HG_ADDR_NULL;
} }
/**
* @brief Returns the underlying Mercury address.
*
* @param copy If set to true, a copy of the address will be made.
* (the user will be responsible for calling margo_addr_free on this
* address) Otherwise, the hg_addr_t returned is the one managed by
* the endpoint instance and will be deleted when this enpoint is destroyed.
*
* @return The underlying hg_addr_t.
*/
hg_addr_t get_addr(bool copy=false) const;
template<typename S> template<typename S>
friend S& ::operator<<(S& s, const endpoint& e); friend S& ::operator<<(S& s, const endpoint& e);
}; };
......
...@@ -78,7 +78,17 @@ endpoint::operator std::string() const { ...@@ -78,7 +78,17 @@ endpoint::operator std::string() const {
ret = margo_addr_to_string(m_engine->m_mid, &result[0], &size, m_addr); ret = margo_addr_to_string(m_engine->m_mid, &result[0], &size, m_addr);
MARGO_ASSERT(ret, margo_addr_to_string); MARGO_ASSERT(ret, margo_addr_to_string);
return std::string(result.data()); return std::string(result.data());
} }
hg_addr_t endpoint::get_addr(bool copy) const {
if(!copy || m_addr == HG_ADDR_NULL) return m_addr;
if(m_engine == nullptr) return HG_ADDR_NULL;
hg_addr_t new_addr;
hg_return_t ret = margo_addr_dup(m_engine->get_margo_instance(), m_addr, &new_addr);
// TODO throw an exception if the call fails
if(ret != HG_SUCCESS) return HG_ADDR_NULL;
return new_addr;
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment