Fix HG_Reset() to only reset handle addr if it is modified
Same for RPC ID
@@ -388,7 +388,8 @@ hg_core_destroy(
*/
static hg_return_t
hg_core_reset(
- struct hg_handle *hg_handle
+ struct hg_handle *hg_handle,
+ hg_bool_t reset_info
);
/**
@@ -1514,9 +1515,10 @@ done:
/*---------------------------------------------------------------------------*/
static hg_return_t
-hg_core_reset(struct hg_handle *hg_handle)
+hg_core_reset(struct hg_handle *hg_handle, hg_bool_t reset_info)
{
/* Reset source address */
+ if (reset_info) {
if (hg_handle->hg_info.addr != HG_ADDR_NULL
&& hg_handle->hg_info.addr->na_addr != NA_ADDR_NULL) {
NA_Addr_free(hg_handle->hg_info.hg_class->na_class,
@@ -1525,6 +1527,7 @@ hg_core_reset(struct hg_handle *hg_handle)
}
hg_handle->hg_info.id = 0;
hg_handle->hg_info.target_id = 0;
+ }
hg_handle->callback = NULL;
hg_handle->arg = NULL;
hg_handle->cb_type = 0;
@@ -1556,13 +1559,16 @@ hg_core_set_rpc(struct hg_handle *hg_handle, hg_addr_t addr, hg_id_t id)
/* We allow for NULL addr to be passed at creation time, this allows
* for pool of handles to be created and later re-used after a call to
* HG_Core_reset() */
- if (addr != HG_ADDR_NULL) {
+ if (addr != HG_ADDR_NULL && hg_handle->hg_info.addr != addr) {
+ if (hg_handle->hg_info.addr != HG_ADDR_NULL)
+ hg_core_addr_free(hg_handle->hg_info.hg_class,
+ hg_handle->hg_info.addr);
hg_handle->hg_info.addr = addr;
hg_atomic_incr32(&addr->ref_count); /* Increase ref to addr */
}
/* We also allow for NULL RPC id to be passed (same reason as above) */
- if (id) {
+ if (id && hg_handle->hg_info.id != id) {
struct hg_rpc_info *hg_rpc_info;
hg_context_t *context = hg_handle->hg_info.context;
hg_handle->hg_info.id = id;
@@ -2295,7 +2301,7 @@ hg_core_reset_post(struct hg_handle *hg_handle)
if (hg_atomic_decr32(&hg_handle->ref_count))
goto done;
- ret = hg_core_reset(hg_handle);
+ ret = hg_core_reset(hg_handle, HG_TRUE);
if (ret != HG_SUCCESS) {
HG_LOG_ERROR("Cannot reset handle");
goto done;
@@ -3666,12 +3672,13 @@ HG_Core_reset(hg_handle_t handle, hg_addr_t addr, hg_id_t id)
if (hg_atomic_get32(&hg_handle->ref_count) > 1) {
/* Not safe to reset
* TODO could add the ability to defer the reset operation */
- HG_LOG_ERROR("Cannot reset HG handle, handle is still in use");
+ HG_LOG_ERROR("Cannot reset HG handle, handle is still in use, "
+ "refcount: %d", hg_atomic_get32(&hg_handle->ref_count));
ret = HG_PROTOCOL_ERROR;
goto done;
}
- ret = hg_core_reset(hg_handle);
+ ret = hg_core_reset(hg_handle, HG_FALSE);
if (ret != HG_SUCCESS) {
HG_LOG_ERROR("Could not reset HG handle");
goto done;
