コード例 #1
0
ファイル: channel_mgr.c プロジェクト: JackieXie168/lagopus
static lagopus_result_t
channel_set_dpid(const char *channel_name, uint64_t dpid) {
  lagopus_result_t ret;
  struct channel *chan = NULL;
  struct channel_list *chan_list = NULL;
  void *valptr = NULL;

  if (dpid == UNUSED_DPID) {
    return LAGOPUS_RESULT_INVALID_ARGS;
  }

  ret = lagopus_hashmap_find(&main_table, (void *)channel_name, (void **)&chan);
  if (chan == NULL) {
    return LAGOPUS_RESULT_NOT_FOUND;
  }

  if (channel_dpid_get(chan) != UNUSED_DPID) {
    return LAGOPUS_RESULT_BUSY;
  }

  ret = channel_dpid_set(chan, dpid);
  if (ret != LAGOPUS_RESULT_OK) {
    return ret;
  }

  ret = lagopus_hashmap_find(&dp_table, (void *)dpid, (void **)&chan_list);
  if (ret == LAGOPUS_RESULT_NOT_FOUND) {
    chan_list = channel_list_alloc();
    if (chan_list == NULL) {
      ret = LAGOPUS_RESULT_NO_MEMORY;
      goto done;
    }
    valptr = chan_list;
    ret = lagopus_hashmap_add(&dp_table, (void *)dpid, (void **)&valptr,
                              false);
    if (ret != LAGOPUS_RESULT_OK) {
      goto done;
    }
  } else if (ret != LAGOPUS_RESULT_OK) {
    goto done;
  }

  channel_id_set(chan, channel_list_channel_id_get(chan_list));
  ret = channel_list_insert(chan_list, chan);

done:

  return ret;
}
コード例 #2
0
ファイル: channel_test.c プロジェクト: tidatida/lagopus
void
test_channel_dpid_get_set(void) {
    uint64_t dpid;
    lagopus_result_t ret;
    struct channel *channel;

    channel = s_create_data_channel();

    /* Call func. */
    ret = channel_dpid_set(channel, 0xbeef);
    TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret,
                              "channel_dpid_set() error.");
    dpid = channel_dpid_get(channel);

    TEST_ASSERT_EQUAL_MESSAGE(dpid, 0xbeef,
                              "dpid error.");

    session_destroy(channel_session_get(channel));
    free(channel);
}
コード例 #3
0
ファイル: channel_mgr.c プロジェクト: JackieXie168/lagopus
static lagopus_result_t
channel_unset_dpid(const char *channel_name) {
  uint64_t dpid;
  lagopus_result_t ret;
  struct channel *chan = NULL;
  struct channel_list *chan_list = NULL;

  ret = lagopus_hashmap_find(&main_table, (void *)channel_name, (void **)&chan);
  if (chan == NULL) {
    return LAGOPUS_RESULT_NOT_FOUND;
  }

  if (channel_is_alive(chan) == true) {
    return LAGOPUS_RESULT_BUSY;
  }

  dpid = channel_dpid_get(chan);
  if (dpid == UNUSED_DPID) {
    return LAGOPUS_RESULT_OK;
  }

  ret = lagopus_hashmap_find(&dp_table, (void *)dpid, (void **)&chan_list);
  if (ret != LAGOPUS_RESULT_OK) {
    return ret;
  }

  ret = channel_list_delete(chan_list, chan);
  if (ret != LAGOPUS_RESULT_OK) {
    return ret;
  }

  ret = channel_dpid_set(chan, UNUSED_DPID);
  if (ret != LAGOPUS_RESULT_OK) {
    return ret;
  }

  return ret;
}