mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
bugifx : gate alloc uid
This commit is contained in:
27
gate/main.c
27
gate/main.c
@@ -138,27 +138,18 @@ static int
|
|||||||
_gen_id(struct gate * g, int connection_id) {
|
_gen_id(struct gate * g, int connection_id) {
|
||||||
int uid = ++g->id_index;
|
int uid = ++g->id_index;
|
||||||
int i;
|
int i;
|
||||||
for (;;) {
|
for (i=0;i<g->cap;i++) {
|
||||||
for (i=0;i<g->cap;i++) {
|
int hash = (uid + i) & (g->cap - 1);
|
||||||
int hash = (uid + i) & (g->cap - 1);
|
if (g->agent[hash] == NULL) {
|
||||||
if (g->agent[hash] == NULL) {
|
uid = uid + i;
|
||||||
uid = uid + i;
|
|
||||||
struct connection * conn = &g->map[connection_id];
|
|
||||||
conn->uid = uid;
|
|
||||||
g->agent[hash] = conn;
|
|
||||||
return uid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
struct connection ** new_hash = malloc(g->cap * 2 * sizeof(struct connection *));
|
|
||||||
memset(new_hash, 0, sizeof(g->cap * 2 * sizeof(struct connection *)));
|
|
||||||
for (i=0;i<g->max_connection;i++) {
|
|
||||||
struct connection * conn = &g->map[connection_id];
|
struct connection * conn = &g->map[connection_id];
|
||||||
assert(conn->uid == 0);
|
conn->uid = uid;
|
||||||
new_hash[conn->uid & (g->cap * 2 -1)] = conn;
|
g->agent[hash] = conn;
|
||||||
|
g->id_index = uid;
|
||||||
|
return uid;
|
||||||
}
|
}
|
||||||
free(g->agent);
|
|
||||||
g->agent = new_hash;
|
|
||||||
}
|
}
|
||||||
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
Reference in New Issue
Block a user