mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 02:53:09 +00:00
use skynet malloc api directly
This commit is contained in:
@@ -39,7 +39,7 @@ messagepool_free(struct messagepool *pool) {
|
|||||||
while(p) {
|
while(p) {
|
||||||
struct messagepool_list *tmp = p;
|
struct messagepool_list *tmp = p;
|
||||||
p=p->next;
|
p=p->next;
|
||||||
free(tmp);
|
skynet_free(tmp);
|
||||||
}
|
}
|
||||||
pool->pool = NULL;
|
pool->pool = NULL;
|
||||||
pool->freelist = NULL;
|
pool->freelist = NULL;
|
||||||
@@ -54,7 +54,7 @@ _return_message(struct databuffer *db, struct messagepool *mp) {
|
|||||||
} else {
|
} else {
|
||||||
db->head = m->next;
|
db->head = m->next;
|
||||||
}
|
}
|
||||||
free(m->buffer);
|
skynet_free(m->buffer);
|
||||||
m->buffer = NULL;
|
m->buffer = NULL;
|
||||||
m->size = 0;
|
m->size = 0;
|
||||||
m->next = mp->freelist;
|
m->next = mp->freelist;
|
||||||
@@ -95,7 +95,7 @@ databuffer_push(struct databuffer *db, struct messagepool *mp, void *data, int s
|
|||||||
m = mp->freelist;
|
m = mp->freelist;
|
||||||
mp->freelist = m->next;
|
mp->freelist = m->next;
|
||||||
} else {
|
} else {
|
||||||
struct messagepool_list * mpl = malloc(sizeof(*mpl));
|
struct messagepool_list * mpl = skynet_malloc(sizeof(*mpl));
|
||||||
struct message * temp = mpl->pool;
|
struct message * temp = mpl->pool;
|
||||||
int i;
|
int i;
|
||||||
for (i=1;i<MESSAGEPOOL;i++) {
|
for (i=1;i<MESSAGEPOOL;i++) {
|
||||||
|
|||||||
@@ -29,19 +29,19 @@ hashid_init(struct hashid *hi, int max) {
|
|||||||
hi->hashmod = hashcap - 1;
|
hi->hashmod = hashcap - 1;
|
||||||
hi->cap = max;
|
hi->cap = max;
|
||||||
hi->count = 0;
|
hi->count = 0;
|
||||||
hi->id = malloc(max * sizeof(struct hashid_node));
|
hi->id = skynet_malloc(max * sizeof(struct hashid_node));
|
||||||
for (i=0;i<max;i++) {
|
for (i=0;i<max;i++) {
|
||||||
hi->id[i].id = -1;
|
hi->id[i].id = -1;
|
||||||
hi->id[i].next = NULL;
|
hi->id[i].next = NULL;
|
||||||
}
|
}
|
||||||
hi->hash = malloc(hashcap * sizeof(struct hashid_node *));
|
hi->hash = skynet_malloc(hashcap * sizeof(struct hashid_node *));
|
||||||
memset(hi->hash, 0, hashcap * sizeof(struct hashid_node *));
|
memset(hi->hash, 0, hashcap * sizeof(struct hashid_node *));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
hashid_clear(struct hashid *hi) {
|
hashid_clear(struct hashid *hi) {
|
||||||
free(hi->id);
|
skynet_free(hi->id);
|
||||||
free(hi->hash);
|
skynet_free(hi->hash);
|
||||||
hi->id = NULL;
|
hi->id = NULL;
|
||||||
hi->hash = NULL;
|
hi->hash = NULL;
|
||||||
hi->hashmod = 1;
|
hi->hashmod = 1;
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ struct gate {
|
|||||||
|
|
||||||
struct gate *
|
struct gate *
|
||||||
gate_create(void) {
|
gate_create(void) {
|
||||||
struct gate * g = malloc(sizeof(*g));
|
struct gate * g = skynet_malloc(sizeof(*g));
|
||||||
memset(g,0,sizeof(*g));
|
memset(g,0,sizeof(*g));
|
||||||
g->listen_id = -1;
|
g->listen_id = -1;
|
||||||
return g;
|
return g;
|
||||||
@@ -57,8 +57,8 @@ gate_release(struct gate *g) {
|
|||||||
}
|
}
|
||||||
messagepool_free(&g->mp);
|
messagepool_free(&g->mp);
|
||||||
hashid_clear(&g->hash);
|
hashid_clear(&g->hash);
|
||||||
free(g->conn);
|
skynet_free(g->conn);
|
||||||
free(g);
|
skynet_free(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -164,17 +164,17 @@ static void
|
|||||||
_forward(struct gate *g, struct connection * c, int size) {
|
_forward(struct gate *g, struct connection * c, int size) {
|
||||||
struct skynet_context * ctx = g->ctx;
|
struct skynet_context * ctx = g->ctx;
|
||||||
if (g->broker) {
|
if (g->broker) {
|
||||||
void * temp = malloc(size);
|
void * temp = skynet_malloc(size);
|
||||||
databuffer_read(&c->buffer,&g->mp,temp, size);
|
databuffer_read(&c->buffer,&g->mp,temp, size);
|
||||||
skynet_send(ctx, 0, g->broker, g->client_tag | PTYPE_TAG_DONTCOPY, 0, temp, size);
|
skynet_send(ctx, 0, g->broker, g->client_tag | PTYPE_TAG_DONTCOPY, 0, temp, size);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (c->agent) {
|
if (c->agent) {
|
||||||
void * temp = malloc(size);
|
void * temp = skynet_malloc(size);
|
||||||
databuffer_read(&c->buffer,&g->mp,temp, size);
|
databuffer_read(&c->buffer,&g->mp,temp, size);
|
||||||
skynet_send(ctx, c->client, c->agent, g->client_tag | PTYPE_TAG_DONTCOPY, 0 , temp, size);
|
skynet_send(ctx, c->client, c->agent, g->client_tag | PTYPE_TAG_DONTCOPY, 0 , temp, size);
|
||||||
} else if (g->watchdog) {
|
} else if (g->watchdog) {
|
||||||
char * tmp = malloc(size + 32);
|
char * tmp = skynet_malloc(size + 32);
|
||||||
int n = snprintf(tmp,32,"%d data ",c->id);
|
int n = snprintf(tmp,32,"%d data ",c->id);
|
||||||
databuffer_read(&c->buffer,&g->mp,tmp+n,size);
|
databuffer_read(&c->buffer,&g->mp,tmp+n,size);
|
||||||
skynet_send(ctx, 0, g->watchdog, PTYPE_TEXT | PTYPE_TAG_DONTCOPY, 0, tmp, size + n);
|
skynet_send(ctx, 0, g->watchdog, PTYPE_TEXT | PTYPE_TAG_DONTCOPY, 0, tmp, size + n);
|
||||||
@@ -215,7 +215,7 @@ dispatch_socket_message(struct gate *g, const struct skynet_socket_message * mes
|
|||||||
} else {
|
} else {
|
||||||
skynet_error(ctx, "Drop unknown connection %d message", message->id);
|
skynet_error(ctx, "Drop unknown connection %d message", message->id);
|
||||||
skynet_socket_close(ctx, message->id);
|
skynet_socket_close(ctx, message->id);
|
||||||
free(message->buffer);
|
skynet_free(message->buffer);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -369,7 +369,7 @@ gate_init(struct gate *g , struct skynet_context * ctx, char * parm) {
|
|||||||
g->ctx = ctx;
|
g->ctx = ctx;
|
||||||
|
|
||||||
hashid_init(&g->hash, max);
|
hashid_init(&g->hash, max);
|
||||||
g->conn = malloc(max * sizeof(struct connection));
|
g->conn = skynet_malloc(max * sizeof(struct connection));
|
||||||
memset(g->conn, 0, max *sizeof(struct connection));
|
memset(g->conn, 0, max *sizeof(struct connection));
|
||||||
g->max_connection = max;
|
g->max_connection = max;
|
||||||
int i;
|
int i;
|
||||||
|
|||||||
@@ -66,12 +66,12 @@ _push_queue(struct msg_queue * queue, const void * buffer, size_t sz, struct rem
|
|||||||
// If there is only 1 free slot which is reserved to distinguish full/empty
|
// If there is only 1 free slot which is reserved to distinguish full/empty
|
||||||
// of circular buffer, expand it.
|
// of circular buffer, expand it.
|
||||||
if (((queue->tail + 1) % queue->size) == queue->head) {
|
if (((queue->tail + 1) % queue->size) == queue->head) {
|
||||||
struct msg * new_buffer = malloc(queue->size * 2 * sizeof(struct msg));
|
struct msg * new_buffer = skynet_malloc(queue->size * 2 * sizeof(struct msg));
|
||||||
int i;
|
int i;
|
||||||
for (i=0;i<queue->size-1;i++) {
|
for (i=0;i<queue->size-1;i++) {
|
||||||
new_buffer[i] = queue->data[(i+queue->head) % queue->size];
|
new_buffer[i] = queue->data[(i+queue->head) % queue->size];
|
||||||
}
|
}
|
||||||
free(queue->data);
|
skynet_free(queue->data);
|
||||||
queue->data = new_buffer;
|
queue->data = new_buffer;
|
||||||
queue->head = 0;
|
queue->head = 0;
|
||||||
queue->tail = queue->size - 1;
|
queue->tail = queue->size - 1;
|
||||||
@@ -80,7 +80,7 @@ _push_queue(struct msg_queue * queue, const void * buffer, size_t sz, struct rem
|
|||||||
struct msg * slot = &queue->data[queue->tail];
|
struct msg * slot = &queue->data[queue->tail];
|
||||||
queue->tail = (queue->tail + 1) % queue->size;
|
queue->tail = (queue->tail + 1) % queue->size;
|
||||||
|
|
||||||
slot->buffer = malloc(sz + sizeof(*header));
|
slot->buffer = skynet_malloc(sz + sizeof(*header));
|
||||||
memcpy(slot->buffer, buffer, sz);
|
memcpy(slot->buffer, buffer, sz);
|
||||||
memcpy(slot->buffer + sz, header, sizeof(*header));
|
memcpy(slot->buffer + sz, header, sizeof(*header));
|
||||||
slot->size = sz + sizeof(*header);
|
slot->size = sz + sizeof(*header);
|
||||||
@@ -98,11 +98,11 @@ _pop_queue(struct msg_queue * queue) {
|
|||||||
|
|
||||||
static struct msg_queue *
|
static struct msg_queue *
|
||||||
_new_queue() {
|
_new_queue() {
|
||||||
struct msg_queue * queue = malloc(sizeof(*queue));
|
struct msg_queue * queue = skynet_malloc(sizeof(*queue));
|
||||||
queue->size = DEFAULT_QUEUE_SIZE;
|
queue->size = DEFAULT_QUEUE_SIZE;
|
||||||
queue->head = 0;
|
queue->head = 0;
|
||||||
queue->tail = 0;
|
queue->tail = 0;
|
||||||
queue->data = malloc(DEFAULT_QUEUE_SIZE * sizeof(struct msg));
|
queue->data = skynet_malloc(DEFAULT_QUEUE_SIZE * sizeof(struct msg));
|
||||||
|
|
||||||
return queue;
|
return queue;
|
||||||
}
|
}
|
||||||
@@ -113,11 +113,11 @@ _release_queue(struct msg_queue *queue) {
|
|||||||
return;
|
return;
|
||||||
struct msg * m = _pop_queue(queue);
|
struct msg * m = _pop_queue(queue);
|
||||||
while (m) {
|
while (m) {
|
||||||
free(m->buffer);
|
skynet_free(m->buffer);
|
||||||
m = _pop_queue(queue);
|
m = _pop_queue(queue);
|
||||||
}
|
}
|
||||||
free(queue->data);
|
skynet_free(queue->data);
|
||||||
free(queue);
|
skynet_free(queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct keyvalue *
|
static struct keyvalue *
|
||||||
@@ -148,7 +148,7 @@ _hash_erase(struct hashmap * hash, char name[GLOBALNAME_LENGTH) {
|
|||||||
if (node->hash == h && strncmp(node->key, name, GLOBALNAME_LENGTH) == 0) {
|
if (node->hash == h && strncmp(node->key, name, GLOBALNAME_LENGTH) == 0) {
|
||||||
_release_queue(node->queue);
|
_release_queue(node->queue);
|
||||||
*ptr->next = node->next;
|
*ptr->next = node->next;
|
||||||
free(node);
|
skynet_free(node);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*ptr = &(node->next);
|
*ptr = &(node->next);
|
||||||
@@ -161,7 +161,7 @@ _hash_insert(struct hashmap * hash, const char name[GLOBALNAME_LENGTH]) {
|
|||||||
uint32_t *ptr = (uint32_t *)name;
|
uint32_t *ptr = (uint32_t *)name;
|
||||||
uint32_t h = ptr[0] ^ ptr[1] ^ ptr[2] ^ ptr[3];
|
uint32_t h = ptr[0] ^ ptr[1] ^ ptr[2] ^ ptr[3];
|
||||||
struct keyvalue ** pkv = &hash->node[h % HASH_SIZE];
|
struct keyvalue ** pkv = &hash->node[h % HASH_SIZE];
|
||||||
struct keyvalue * node = malloc(sizeof(*node));
|
struct keyvalue * node = skynet_malloc(sizeof(*node));
|
||||||
memcpy(node->key, name, GLOBALNAME_LENGTH);
|
memcpy(node->key, name, GLOBALNAME_LENGTH);
|
||||||
node->next = *pkv;
|
node->next = *pkv;
|
||||||
node->queue = NULL;
|
node->queue = NULL;
|
||||||
@@ -174,7 +174,7 @@ _hash_insert(struct hashmap * hash, const char name[GLOBALNAME_LENGTH]) {
|
|||||||
|
|
||||||
static struct hashmap *
|
static struct hashmap *
|
||||||
_hash_new() {
|
_hash_new() {
|
||||||
struct hashmap * h = malloc(sizeof(struct hashmap));
|
struct hashmap * h = skynet_malloc(sizeof(struct hashmap));
|
||||||
memset(h,0,sizeof(*h));
|
memset(h,0,sizeof(*h));
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
@@ -187,18 +187,18 @@ _hash_delete(struct hashmap *hash) {
|
|||||||
while (node) {
|
while (node) {
|
||||||
struct keyvalue * next = node->next;
|
struct keyvalue * next = node->next;
|
||||||
_release_queue(node->queue);
|
_release_queue(node->queue);
|
||||||
free(node);
|
skynet_free(node);
|
||||||
node = next;
|
node = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(hash);
|
skynet_free(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////
|
///////////////
|
||||||
|
|
||||||
struct harbor *
|
struct harbor *
|
||||||
harbor_create(void) {
|
harbor_create(void) {
|
||||||
struct harbor * h = malloc(sizeof(*h));
|
struct harbor * h = skynet_malloc(sizeof(*h));
|
||||||
h->ctx = NULL;
|
h->ctx = NULL;
|
||||||
h->id = 0;
|
h->id = 0;
|
||||||
h->master_fd = -1;
|
h->master_fd = -1;
|
||||||
@@ -219,17 +219,17 @@ harbor_release(struct harbor *h) {
|
|||||||
if (h->master_fd >= 0) {
|
if (h->master_fd >= 0) {
|
||||||
skynet_socket_close(ctx, h->master_fd);
|
skynet_socket_close(ctx, h->master_fd);
|
||||||
}
|
}
|
||||||
free(h->master_addr);
|
skynet_free(h->master_addr);
|
||||||
free(h->local_addr);
|
skynet_free(h->local_addr);
|
||||||
int i;
|
int i;
|
||||||
for (i=0;i<REMOTE_MAX;i++) {
|
for (i=0;i<REMOTE_MAX;i++) {
|
||||||
if (h->remote_fd[i] >= 0) {
|
if (h->remote_fd[i] >= 0) {
|
||||||
skynet_socket_close(ctx, h->remote_fd[i]);
|
skynet_socket_close(ctx, h->remote_fd[i]);
|
||||||
free(h->remote_addr[i]);
|
skynet_free(h->remote_addr[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_hash_delete(h->map);
|
_hash_delete(h->map);
|
||||||
free(h);
|
skynet_free(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -288,7 +288,7 @@ _message_to_header(const uint32_t *message, struct remote_message_header *header
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
_send_package(struct skynet_context *ctx, int fd, const void * buffer, size_t sz) {
|
_send_package(struct skynet_context *ctx, int fd, const void * buffer, size_t sz) {
|
||||||
uint8_t * sendbuf = malloc(sz+4);
|
uint8_t * sendbuf = skynet_malloc(sz+4);
|
||||||
to_bigendian(sendbuf, sz);
|
to_bigendian(sendbuf, sz);
|
||||||
memcpy(sendbuf+4, buffer, sz);
|
memcpy(sendbuf+4, buffer, sz);
|
||||||
|
|
||||||
@@ -300,7 +300,7 @@ _send_package(struct skynet_context *ctx, int fd, const void * buffer, size_t sz
|
|||||||
static void
|
static void
|
||||||
_send_remote(struct skynet_context * ctx, int fd, const char * buffer, size_t sz, struct remote_message_header * cookie) {
|
_send_remote(struct skynet_context * ctx, int fd, const char * buffer, size_t sz, struct remote_message_header * cookie) {
|
||||||
uint32_t sz_header = sz+sizeof(*cookie);
|
uint32_t sz_header = sz+sizeof(*cookie);
|
||||||
uint8_t * sendbuf = malloc(sz_header+4);
|
uint8_t * sendbuf = skynet_malloc(sz_header+4);
|
||||||
to_bigendian(sendbuf, sz_header);
|
to_bigendian(sendbuf, sz_header);
|
||||||
memcpy(sendbuf+4, buffer, sz);
|
memcpy(sendbuf+4, buffer, sz);
|
||||||
_header_to_message(cookie, sendbuf+4+sz);
|
_header_to_message(cookie, sendbuf+4+sz);
|
||||||
@@ -319,7 +319,7 @@ _update_remote_address(struct harbor *h, int harbor_id, const char * ipaddr) {
|
|||||||
struct skynet_context * context = h->ctx;
|
struct skynet_context * context = h->ctx;
|
||||||
if (h->remote_fd[harbor_id] >=0) {
|
if (h->remote_fd[harbor_id] >=0) {
|
||||||
skynet_socket_close(context, h->remote_fd[harbor_id]);
|
skynet_socket_close(context, h->remote_fd[harbor_id]);
|
||||||
free(h->remote_addr[harbor_id]);
|
skynet_free(h->remote_addr[harbor_id]);
|
||||||
h->remote_addr[harbor_id] = NULL;
|
h->remote_addr[harbor_id] = NULL;
|
||||||
}
|
}
|
||||||
h->remote_fd[harbor_id] = _connect_to(h, ipaddr, false);
|
h->remote_fd[harbor_id] = _connect_to(h, ipaddr, false);
|
||||||
@@ -484,7 +484,7 @@ _mainloop(struct skynet_context * context, void * ud, int type, int session, uin
|
|||||||
const struct skynet_socket_message * message = msg;
|
const struct skynet_socket_message * message = msg;
|
||||||
switch(message->type) {
|
switch(message->type) {
|
||||||
case SKYNET_SOCKET_TYPE_DATA:
|
case SKYNET_SOCKET_TYPE_DATA:
|
||||||
free(message->buffer);
|
skynet_free(message->buffer);
|
||||||
skynet_error(context, "recv invalid socket message (size=%d)", message->ud);
|
skynet_error(context, "recv invalid socket message (size=%d)", message->ud);
|
||||||
break;
|
break;
|
||||||
case SKYNET_SOCKET_TYPE_ACCEPT:
|
case SKYNET_SOCKET_TYPE_ACCEPT:
|
||||||
@@ -552,7 +552,7 @@ _mainloop(struct skynet_context * context, void * ud, int type, int session, uin
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free((void *)rmsg->message);
|
skynet_free((void *)rmsg->message);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ struct logger {
|
|||||||
|
|
||||||
struct logger *
|
struct logger *
|
||||||
logger_create(void) {
|
logger_create(void) {
|
||||||
struct logger * inst = malloc(sizeof(*inst));
|
struct logger * inst = skynet_malloc(sizeof(*inst));
|
||||||
inst->handle = NULL;
|
inst->handle = NULL;
|
||||||
inst->close = 0;
|
inst->close = 0;
|
||||||
return inst;
|
return inst;
|
||||||
@@ -22,7 +22,7 @@ logger_release(struct logger * inst) {
|
|||||||
if (inst->close) {
|
if (inst->close) {
|
||||||
fclose(inst->handle);
|
fclose(inst->handle);
|
||||||
}
|
}
|
||||||
free(inst);
|
skynet_free(inst);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ struct master {
|
|||||||
|
|
||||||
struct master *
|
struct master *
|
||||||
master_create() {
|
master_create() {
|
||||||
struct master *m = malloc(sizeof(*m));
|
struct master *m = skynet_malloc(sizeof(*m));
|
||||||
int i;
|
int i;
|
||||||
for (i=0;i<REMOTE_MAX;i++) {
|
for (i=0;i<REMOTE_MAX;i++) {
|
||||||
m->remote_fd[i] = -1;
|
m->remote_fd[i] = -1;
|
||||||
@@ -53,17 +53,17 @@ master_release(struct master * m) {
|
|||||||
assert(ctx);
|
assert(ctx);
|
||||||
skynet_socket_close(ctx, fd);
|
skynet_socket_close(ctx, fd);
|
||||||
}
|
}
|
||||||
free(m->remote_addr[i]);
|
skynet_free(m->remote_addr[i]);
|
||||||
}
|
}
|
||||||
for (i=0;i<HASH_SIZE;i++) {
|
for (i=0;i<HASH_SIZE;i++) {
|
||||||
struct name * node = m->map.node[i];
|
struct name * node = m->map.node[i];
|
||||||
while (node) {
|
while (node) {
|
||||||
struct name * next = node->next;
|
struct name * next = node->next;
|
||||||
free(node);
|
skynet_free(node);
|
||||||
node = next;
|
node = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(m);
|
skynet_free(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct name *
|
static struct name *
|
||||||
@@ -85,7 +85,7 @@ _insert_name(struct master *m, char name[GLOBALNAME_LENGTH]) {
|
|||||||
uint32_t *ptr = (uint32_t *)name;
|
uint32_t *ptr = (uint32_t *)name;
|
||||||
uint32_t h = ptr[0] ^ ptr[1] ^ ptr[2] ^ ptr[3];
|
uint32_t h = ptr[0] ^ ptr[1] ^ ptr[2] ^ ptr[3];
|
||||||
struct name **pname = &m->map.node[h % HASH_SIZE];
|
struct name **pname = &m->map.node[h % HASH_SIZE];
|
||||||
struct name * node = malloc(sizeof(*node));
|
struct name * node = skynet_malloc(sizeof(*node));
|
||||||
memcpy(node->key, name, GLOBALNAME_LENGTH);
|
memcpy(node->key, name, GLOBALNAME_LENGTH);
|
||||||
node->next = *pname;
|
node->next = *pname;
|
||||||
node->hash = h;
|
node->hash = h;
|
||||||
@@ -133,7 +133,7 @@ to_bigendian(uint8_t *buffer, uint32_t n) {
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
_send_to(struct master *m, int id, const void * buf, int sz, uint32_t handle) {
|
_send_to(struct master *m, int id, const void * buf, int sz, uint32_t handle) {
|
||||||
uint8_t * buffer= (uint8_t *)malloc(4 + sz + 12);
|
uint8_t * buffer= (uint8_t *)skynet_malloc(4 + sz + 12);
|
||||||
to_bigendian(buffer, sz+12);
|
to_bigendian(buffer, sz+12);
|
||||||
memcpy(buffer+4, buf, sz);
|
memcpy(buffer+4, buf, sz);
|
||||||
to_bigendian(buffer+4+sz, 0);
|
to_bigendian(buffer+4+sz, 0);
|
||||||
@@ -196,8 +196,8 @@ _update_address(struct master *m, int harbor_id, const char * buffer, size_t sz)
|
|||||||
if (m->remote_fd[harbor_id] >= 0) {
|
if (m->remote_fd[harbor_id] >= 0) {
|
||||||
close_harbor(m, harbor_id);
|
close_harbor(m, harbor_id);
|
||||||
}
|
}
|
||||||
free(m->remote_addr[harbor_id]);
|
skynet_free(m->remote_addr[harbor_id]);
|
||||||
char * addr = malloc(sz+1);
|
char * addr = skynet_malloc(sz+1);
|
||||||
memcpy(addr, buffer, sz);
|
memcpy(addr, buffer, sz);
|
||||||
addr[sz] = '\0';
|
addr[sz] = '\0';
|
||||||
m->remote_addr[harbor_id] = addr;
|
m->remote_addr[harbor_id] = addr;
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ _launch(struct skynet_context * context, void *ud, int type, int session, uint32
|
|||||||
int
|
int
|
||||||
snlua_init(struct snlua *l, struct skynet_context *ctx, const char * args) {
|
snlua_init(struct snlua *l, struct skynet_context *ctx, const char * args) {
|
||||||
int sz = strlen(args);
|
int sz = strlen(args);
|
||||||
char * tmp = malloc(sz+1);
|
char * tmp = skynet_malloc(sz+1);
|
||||||
memcpy(tmp, args, sz+1);
|
memcpy(tmp, args, sz+1);
|
||||||
skynet_callback(ctx, l , _launch);
|
skynet_callback(ctx, l , _launch);
|
||||||
const char * self = skynet_command(ctx, "REG", NULL);
|
const char * self = skynet_command(ctx, "REG", NULL);
|
||||||
@@ -265,7 +265,7 @@ snlua_init(struct snlua *l, struct skynet_context *ctx, const char * args) {
|
|||||||
|
|
||||||
struct snlua *
|
struct snlua *
|
||||||
snlua_create(void) {
|
snlua_create(void) {
|
||||||
struct snlua * l = malloc(sizeof(*l));
|
struct snlua * l = skynet_malloc(sizeof(*l));
|
||||||
memset(l,0,sizeof(*l));
|
memset(l,0,sizeof(*l));
|
||||||
l->L = lua_newstate(skynet_lalloc, NULL);
|
l->L = lua_newstate(skynet_lalloc, NULL);
|
||||||
l->init = _init;
|
l->init = _init;
|
||||||
@@ -275,5 +275,5 @@ snlua_create(void) {
|
|||||||
void
|
void
|
||||||
snlua_release(struct snlua *l) {
|
snlua_release(struct snlua *l) {
|
||||||
lua_close(l->L);
|
lua_close(l->L);
|
||||||
free(l);
|
skynet_free(l);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// include skynet.h first for malloc hook
|
|
||||||
#include "skynet.h"
|
#include "skynet.h"
|
||||||
#include "skynet_env.h"
|
#include "skynet_env.h"
|
||||||
|
|
||||||
@@ -49,7 +48,7 @@ skynet_setenv(const char *key, const char *value) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
skynet_env_init() {
|
skynet_env_init() {
|
||||||
E = malloc(sizeof(*E));
|
E = skynet_malloc(sizeof(*E));
|
||||||
E->lock = 0;
|
E->lock = 0;
|
||||||
E->L = luaL_newstate();
|
E->L = luaL_newstate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,14 +34,14 @@ skynet_error(struct skynet_context * context, const char *msg, ...) {
|
|||||||
int max_size = LOG_MESSAGE_SIZE;
|
int max_size = LOG_MESSAGE_SIZE;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
max_size *= 2;
|
max_size *= 2;
|
||||||
data = malloc(max_size);
|
data = skynet_malloc(max_size);
|
||||||
va_start(ap,msg);
|
va_start(ap,msg);
|
||||||
len = vsnprintf(data, max_size, msg, ap);
|
len = vsnprintf(data, max_size, msg, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
if (len < max_size) {
|
if (len < max_size) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
free(data);
|
skynet_free(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// include skynet.h first for malloc hook
|
|
||||||
#include "skynet.h"
|
#include "skynet.h"
|
||||||
|
|
||||||
#include "skynet_handle.h"
|
#include "skynet_handle.h"
|
||||||
@@ -54,14 +53,14 @@ skynet_handle_register(struct skynet_context *ctx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert((s->slot_size*2 - 1) <= HANDLE_MASK);
|
assert((s->slot_size*2 - 1) <= HANDLE_MASK);
|
||||||
struct skynet_context ** new_slot = malloc(s->slot_size * 2 * sizeof(struct skynet_context *));
|
struct skynet_context ** new_slot = skynet_malloc(s->slot_size * 2 * sizeof(struct skynet_context *));
|
||||||
memset(new_slot, 0, s->slot_size * 2 * sizeof(struct skynet_context *));
|
memset(new_slot, 0, s->slot_size * 2 * sizeof(struct skynet_context *));
|
||||||
for (i=0;i<s->slot_size;i++) {
|
for (i=0;i<s->slot_size;i++) {
|
||||||
int hash = skynet_context_handle(s->slot[i]) & (s->slot_size * 2 - 1);
|
int hash = skynet_context_handle(s->slot[i]) & (s->slot_size * 2 - 1);
|
||||||
assert(new_slot[hash] == NULL);
|
assert(new_slot[hash] == NULL);
|
||||||
new_slot[hash] = s->slot[i];
|
new_slot[hash] = s->slot[i];
|
||||||
}
|
}
|
||||||
free(s->slot);
|
skynet_free(s->slot);
|
||||||
s->slot = new_slot;
|
s->slot = new_slot;
|
||||||
s->slot_size *= 2;
|
s->slot_size *= 2;
|
||||||
}
|
}
|
||||||
@@ -83,7 +82,7 @@ skynet_handle_retire(uint32_t handle) {
|
|||||||
int j=0, n=s->name_count;
|
int j=0, n=s->name_count;
|
||||||
for (i=0; i<n; ++i) {
|
for (i=0; i<n; ++i) {
|
||||||
if (s->name[i].handle == handle) {
|
if (s->name[i].handle == handle) {
|
||||||
free(s->name[i].name);
|
skynet_free(s->name[i].name);
|
||||||
continue;
|
continue;
|
||||||
} else if (i!=j) {
|
} else if (i!=j) {
|
||||||
s->name[j] = s->name[i];
|
s->name[j] = s->name[i];
|
||||||
@@ -169,7 +168,7 @@ static void
|
|||||||
_insert_name_before(struct handle_storage *s, char *name, uint32_t handle, int before) {
|
_insert_name_before(struct handle_storage *s, char *name, uint32_t handle, int before) {
|
||||||
if (s->name_count >= s->name_cap) {
|
if (s->name_count >= s->name_cap) {
|
||||||
s->name_cap *= 2;
|
s->name_cap *= 2;
|
||||||
struct handle_name * n = malloc(s->name_cap * sizeof(struct handle_name));
|
struct handle_name * n = skynet_malloc(s->name_cap * sizeof(struct handle_name));
|
||||||
int i;
|
int i;
|
||||||
for (i=0;i<before;i++) {
|
for (i=0;i<before;i++) {
|
||||||
n[i] = s->name[i];
|
n[i] = s->name[i];
|
||||||
@@ -177,7 +176,7 @@ _insert_name_before(struct handle_storage *s, char *name, uint32_t handle, int b
|
|||||||
for (i=before;i<s->name_count;i++) {
|
for (i=before;i<s->name_count;i++) {
|
||||||
n[i+1] = s->name[i];
|
n[i+1] = s->name[i];
|
||||||
}
|
}
|
||||||
free(s->name);
|
skynet_free(s->name);
|
||||||
s->name = n;
|
s->name = n;
|
||||||
} else {
|
} else {
|
||||||
int i;
|
int i;
|
||||||
@@ -228,9 +227,9 @@ skynet_handle_namehandle(uint32_t handle, const char *name) {
|
|||||||
void
|
void
|
||||||
skynet_handle_init(int harbor) {
|
skynet_handle_init(int harbor) {
|
||||||
assert(H==NULL);
|
assert(H==NULL);
|
||||||
struct handle_storage * s = malloc(sizeof(*H));
|
struct handle_storage * s = skynet_malloc(sizeof(*H));
|
||||||
s->slot_size = DEFAULT_SLOT_SIZE;
|
s->slot_size = DEFAULT_SLOT_SIZE;
|
||||||
s->slot = malloc(s->slot_size * sizeof(struct skynet_context *));
|
s->slot = skynet_malloc(s->slot_size * sizeof(struct skynet_context *));
|
||||||
memset(s->slot, 0, s->slot_size * sizeof(struct skynet_context *));
|
memset(s->slot, 0, s->slot_size * sizeof(struct skynet_context *));
|
||||||
|
|
||||||
rwlock_init(&s->lock);
|
rwlock_init(&s->lock);
|
||||||
@@ -239,7 +238,7 @@ skynet_handle_init(int harbor) {
|
|||||||
s->handle_index = 1;
|
s->handle_index = 1;
|
||||||
s->name_cap = 2;
|
s->name_cap = 2;
|
||||||
s->name_count = 0;
|
s->name_count = 0;
|
||||||
s->name = malloc(s->name_cap * sizeof(struct handle_name));
|
s->name = skynet_malloc(s->name_cap * sizeof(struct handle_name));
|
||||||
|
|
||||||
H = s;
|
H = s;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// include skynet.h first for malloc hook
|
|
||||||
#include "skynet.h"
|
#include "skynet.h"
|
||||||
|
|
||||||
#include "skynet_imp.h"
|
#include "skynet_imp.h"
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// include skynet.h first for malloc hook
|
|
||||||
#include "skynet.h"
|
#include "skynet.h"
|
||||||
|
|
||||||
#include "skynet_module.h"
|
#include "skynet_module.h"
|
||||||
@@ -153,7 +152,7 @@ skynet_module_instance_release(struct skynet_module *m, void *inst) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
skynet_module_init(const char *path) {
|
skynet_module_init(const char *path) {
|
||||||
struct modules *m = malloc(sizeof(*m));
|
struct modules *m = skynet_malloc(sizeof(*m));
|
||||||
m->count = 0;
|
m->count = 0;
|
||||||
m->path = skynet_strdup(path);
|
m->path = skynet_strdup(path);
|
||||||
m->lock = 0;
|
m->lock = 0;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// include skynet.h first for malloc hook
|
|
||||||
#include "skynet.h"
|
#include "skynet.h"
|
||||||
|
|
||||||
#include "skynet_monitor.h"
|
#include "skynet_monitor.h"
|
||||||
@@ -17,14 +16,14 @@ struct skynet_monitor {
|
|||||||
|
|
||||||
struct skynet_monitor *
|
struct skynet_monitor *
|
||||||
skynet_monitor_new() {
|
skynet_monitor_new() {
|
||||||
struct skynet_monitor * ret = malloc(sizeof(*ret));
|
struct skynet_monitor * ret = skynet_malloc(sizeof(*ret));
|
||||||
memset(ret, 0, sizeof(*ret));
|
memset(ret, 0, sizeof(*ret));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
skynet_monitor_delete(struct skynet_monitor *sm) {
|
skynet_monitor_delete(struct skynet_monitor *sm) {
|
||||||
free(sm);
|
skynet_free(sm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ skynet_globalmq_pop() {
|
|||||||
|
|
||||||
struct message_queue *
|
struct message_queue *
|
||||||
skynet_mq_create(uint32_t handle) {
|
skynet_mq_create(uint32_t handle) {
|
||||||
struct message_queue *q = malloc(sizeof(*q));
|
struct message_queue *q = skynet_malloc(sizeof(*q));
|
||||||
q->handle = handle;
|
q->handle = handle;
|
||||||
q->cap = DEFAULT_QUEUE_SIZE;
|
q->cap = DEFAULT_QUEUE_SIZE;
|
||||||
q->head = 0;
|
q->head = 0;
|
||||||
@@ -92,15 +92,15 @@ skynet_mq_create(uint32_t handle) {
|
|||||||
q->in_global = MQ_IN_GLOBAL;
|
q->in_global = MQ_IN_GLOBAL;
|
||||||
q->release = 0;
|
q->release = 0;
|
||||||
q->lock_session = 0;
|
q->lock_session = 0;
|
||||||
q->queue = malloc(sizeof(struct skynet_message) * q->cap);
|
q->queue = skynet_malloc(sizeof(struct skynet_message) * q->cap);
|
||||||
|
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_release(struct message_queue *q) {
|
_release(struct message_queue *q) {
|
||||||
free(q->queue);
|
skynet_free(q->queue);
|
||||||
free(q);
|
skynet_free(q);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t
|
uint32_t
|
||||||
@@ -148,7 +148,7 @@ skynet_mq_pop(struct message_queue *q, struct skynet_message *message) {
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
expand_queue(struct message_queue *q) {
|
expand_queue(struct message_queue *q) {
|
||||||
struct skynet_message *new_queue = malloc(sizeof(struct skynet_message) * q->cap * 2);
|
struct skynet_message *new_queue = skynet_malloc(sizeof(struct skynet_message) * q->cap * 2);
|
||||||
int i;
|
int i;
|
||||||
for (i=0;i<q->cap;i++) {
|
for (i=0;i<q->cap;i++) {
|
||||||
new_queue[i] = q->queue[(q->head + i) % q->cap];
|
new_queue[i] = q->queue[(q->head + i) % q->cap];
|
||||||
@@ -157,7 +157,7 @@ expand_queue(struct message_queue *q) {
|
|||||||
q->tail = q->cap;
|
q->tail = q->cap;
|
||||||
q->cap *= 2;
|
q->cap *= 2;
|
||||||
|
|
||||||
free(q->queue);
|
skynet_free(q->queue);
|
||||||
q->queue = new_queue;
|
q->queue = new_queue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,10 +239,10 @@ skynet_mq_unlock(struct message_queue *q) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
skynet_mq_init() {
|
skynet_mq_init() {
|
||||||
struct global_queue *q = malloc(sizeof(*q));
|
struct global_queue *q = skynet_malloc(sizeof(*q));
|
||||||
memset(q,0,sizeof(*q));
|
memset(q,0,sizeof(*q));
|
||||||
q->queue = malloc(MAX_GLOBAL_MQ * sizeof(struct message_queue *));
|
q->queue = skynet_malloc(MAX_GLOBAL_MQ * sizeof(struct message_queue *));
|
||||||
q->flag = malloc(MAX_GLOBAL_MQ * sizeof(bool));
|
q->flag = skynet_malloc(MAX_GLOBAL_MQ * sizeof(bool));
|
||||||
memset(q->flag, 0, sizeof(bool) * MAX_GLOBAL_MQ);
|
memset(q->flag, 0, sizeof(bool) * MAX_GLOBAL_MQ);
|
||||||
Q=q;
|
Q=q;
|
||||||
}
|
}
|
||||||
@@ -286,7 +286,7 @@ _drop_queue(struct message_queue *q) {
|
|||||||
int s = 0;
|
int s = 0;
|
||||||
while(!skynet_mq_pop(q, &msg)) {
|
while(!skynet_mq_pop(q, &msg)) {
|
||||||
++s;
|
++s;
|
||||||
free(msg.data);
|
skynet_free(msg.data);
|
||||||
}
|
}
|
||||||
_release(q);
|
_release(q);
|
||||||
return s;
|
return s;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// include skynet.h first for malloc hook
|
|
||||||
#include "skynet.h"
|
#include "skynet.h"
|
||||||
|
|
||||||
#include "skynet_server.h"
|
#include "skynet_server.h"
|
||||||
@@ -97,7 +96,7 @@ skynet_context_new(const char * name, const char *param) {
|
|||||||
void *inst = skynet_module_instance_create(mod);
|
void *inst = skynet_module_instance_create(mod);
|
||||||
if (inst == NULL)
|
if (inst == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
struct skynet_context * ctx = malloc(sizeof(*ctx));
|
struct skynet_context * ctx = skynet_malloc(sizeof(*ctx));
|
||||||
CHECKCALLING_INIT(ctx)
|
CHECKCALLING_INIT(ctx)
|
||||||
|
|
||||||
ctx->mod = mod;
|
ctx->mod = mod;
|
||||||
@@ -152,7 +151,7 @@ static void
|
|||||||
_delete_context(struct skynet_context *ctx) {
|
_delete_context(struct skynet_context *ctx) {
|
||||||
skynet_module_instance_release(ctx->mod, ctx->instance);
|
skynet_module_instance_release(ctx->mod, ctx->instance);
|
||||||
skynet_mq_mark_release(ctx->queue);
|
skynet_mq_mark_release(ctx->queue);
|
||||||
free(ctx);
|
skynet_free(ctx);
|
||||||
_context_dec();
|
_context_dec();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,7 +203,7 @@ _dispatch_message(struct skynet_context *ctx, struct skynet_message *msg) {
|
|||||||
int type = msg->sz >> HANDLE_REMOTE_SHIFT;
|
int type = msg->sz >> HANDLE_REMOTE_SHIFT;
|
||||||
size_t sz = msg->sz & HANDLE_MASK;
|
size_t sz = msg->sz & HANDLE_MASK;
|
||||||
if (!ctx->cb(ctx, ctx->cb_ud, type, msg->session, msg->source, msg->data, sz)) {
|
if (!ctx->cb(ctx, ctx->cb_ud, type, msg->session, msg->source, msg->data, sz)) {
|
||||||
free(msg->data);
|
skynet_free(msg->data);
|
||||||
}
|
}
|
||||||
handle_tls = 0xffffffff;
|
handle_tls = 0xffffffff;
|
||||||
CHECKCALLING_END(ctx)
|
CHECKCALLING_END(ctx)
|
||||||
@@ -236,7 +235,7 @@ skynet_context_message_dispatch(struct skynet_monitor *sm) {
|
|||||||
skynet_monitor_trigger(sm, msg.source , handle);
|
skynet_monitor_trigger(sm, msg.source , handle);
|
||||||
|
|
||||||
if (ctx->cb == NULL) {
|
if (ctx->cb == NULL) {
|
||||||
free(msg.data);
|
skynet_free(msg.data);
|
||||||
skynet_error(NULL, "Drop message from %x to %x without callback , size = %d",msg.source, handle, (int)msg.sz);
|
skynet_error(NULL, "Drop message from %x to %x without callback , size = %d",msg.source, handle, (int)msg.sz);
|
||||||
} else {
|
} else {
|
||||||
_dispatch_message(ctx, &msg);
|
_dispatch_message(ctx, &msg);
|
||||||
@@ -323,7 +322,7 @@ skynet_command(struct skynet_context * context, const char * cmd , const char *
|
|||||||
return skynet_handle_namehandle(context->handle, param + 1);
|
return skynet_handle_namehandle(context->handle, param + 1);
|
||||||
} else {
|
} else {
|
||||||
assert(context->handle!=0);
|
assert(context->handle!=0);
|
||||||
struct remote_name *rname = malloc(sizeof(*rname));
|
struct remote_name *rname = skynet_malloc(sizeof(*rname));
|
||||||
_copy_name(rname->name, param);
|
_copy_name(rname->name, param);
|
||||||
rname->handle = context->handle;
|
rname->handle = context->handle;
|
||||||
skynet_harbor_register(rname);
|
skynet_harbor_register(rname);
|
||||||
@@ -355,7 +354,7 @@ skynet_command(struct skynet_context * context, const char * cmd , const char *
|
|||||||
if (name[0] == '.') {
|
if (name[0] == '.') {
|
||||||
return skynet_handle_namehandle(handle_id, name + 1);
|
return skynet_handle_namehandle(handle_id, name + 1);
|
||||||
} else {
|
} else {
|
||||||
struct remote_name *rname = malloc(sizeof(*rname));
|
struct remote_name *rname = skynet_malloc(sizeof(*rname));
|
||||||
_copy_name(rname->name, name);
|
_copy_name(rname->name, name);
|
||||||
rname->handle = handle_id;
|
rname->handle = handle_id;
|
||||||
skynet_harbor_register(rname);
|
skynet_harbor_register(rname);
|
||||||
@@ -491,7 +490,7 @@ _filter_args(struct skynet_context * context, int type, int *session, void ** da
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (needcopy && *data) {
|
if (needcopy && *data) {
|
||||||
char * msg = malloc(*sz+1);
|
char * msg = skynet_malloc(*sz+1);
|
||||||
memcpy(msg, *data, *sz);
|
memcpy(msg, *data, *sz);
|
||||||
msg[*sz] = '\0';
|
msg[*sz] = '\0';
|
||||||
*data = msg;
|
*data = msg;
|
||||||
@@ -513,7 +512,7 @@ skynet_send(struct skynet_context * context, uint32_t source, uint32_t destinati
|
|||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
if (skynet_harbor_message_isremote(destination)) {
|
if (skynet_harbor_message_isremote(destination)) {
|
||||||
struct remote_message * rmsg = malloc(sizeof(*rmsg));
|
struct remote_message * rmsg = skynet_malloc(sizeof(*rmsg));
|
||||||
rmsg->destination.handle = destination;
|
rmsg->destination.handle = destination;
|
||||||
rmsg->message = data;
|
rmsg->message = data;
|
||||||
rmsg->sz = sz;
|
rmsg->sz = sz;
|
||||||
@@ -526,7 +525,7 @@ skynet_send(struct skynet_context * context, uint32_t source, uint32_t destinati
|
|||||||
smsg.sz = sz;
|
smsg.sz = sz;
|
||||||
|
|
||||||
if (skynet_context_push(destination, &smsg)) {
|
if (skynet_context_push(destination, &smsg)) {
|
||||||
free(data);
|
skynet_free(data);
|
||||||
skynet_error(NULL, "Drop message from %x to %x (type=%d)(size=%d)", source, destination, type&0xff, (int)(sz & HANDLE_MASK));
|
skynet_error(NULL, "Drop message from %x to %x (type=%d)(size=%d)", source, destination, type&0xff, (int)(sz & HANDLE_MASK));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -544,7 +543,7 @@ skynet_sendname(struct skynet_context * context, const char * addr , int type, i
|
|||||||
des = skynet_handle_findname(addr + 1);
|
des = skynet_handle_findname(addr + 1);
|
||||||
if (des == 0) {
|
if (des == 0) {
|
||||||
if (type & PTYPE_TAG_DONTCOPY) {
|
if (type & PTYPE_TAG_DONTCOPY) {
|
||||||
free(data);
|
skynet_free(data);
|
||||||
}
|
}
|
||||||
skynet_error(context, "Drop message to %s", addr);
|
skynet_error(context, "Drop message to %s", addr);
|
||||||
return session;
|
return session;
|
||||||
@@ -552,7 +551,7 @@ skynet_sendname(struct skynet_context * context, const char * addr , int type, i
|
|||||||
} else {
|
} else {
|
||||||
_filter_args(context, type, &session, (void **)&data, &sz);
|
_filter_args(context, type, &session, (void **)&data, &sz);
|
||||||
|
|
||||||
struct remote_message * rmsg = malloc(sizeof(*rmsg));
|
struct remote_message * rmsg = skynet_malloc(sizeof(*rmsg));
|
||||||
_copy_name(rmsg->destination.name, addr);
|
_copy_name(rmsg->destination.name, addr);
|
||||||
rmsg->destination.handle = 0;
|
rmsg->destination.handle = 0;
|
||||||
rmsg->message = data;
|
rmsg->message = data;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// include skynet.h first for malloc hook
|
|
||||||
#include "skynet.h"
|
#include "skynet.h"
|
||||||
|
|
||||||
#include "skynet_socket.h"
|
#include "skynet_socket.h"
|
||||||
@@ -43,7 +42,7 @@ forward_message(int type, bool padding, struct socket_message * result) {
|
|||||||
sz += 1;
|
sz += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sm = (struct skynet_socket_message *)malloc(sz);
|
sm = (struct skynet_socket_message *)skynet_malloc(sz);
|
||||||
sm->type = type;
|
sm->type = type;
|
||||||
sm->id = result->id;
|
sm->id = result->id;
|
||||||
sm->ud = result->ud;
|
sm->ud = result->ud;
|
||||||
@@ -63,7 +62,7 @@ forward_message(int type, bool padding, struct socket_message * result) {
|
|||||||
if (skynet_context_push((uint32_t)result->opaque, &message)) {
|
if (skynet_context_push((uint32_t)result->opaque, &message)) {
|
||||||
// todo: report somewhere to close socket
|
// todo: report somewhere to close socket
|
||||||
// don't call skynet_socket_close here (It will block mainloop)
|
// don't call skynet_socket_close here (It will block mainloop)
|
||||||
free(sm);
|
skynet_free(sm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +105,7 @@ int
|
|||||||
skynet_socket_send(struct skynet_context *ctx, int id, void *buffer, int sz) {
|
skynet_socket_send(struct skynet_context *ctx, int id, void *buffer, int sz) {
|
||||||
int64_t wsz = socket_server_send(SOCKET_SERVER, id, buffer, sz);
|
int64_t wsz = socket_server_send(SOCKET_SERVER, id, buffer, sz);
|
||||||
if (wsz < 0) {
|
if (wsz < 0) {
|
||||||
free(buffer);
|
skynet_free(buffer);
|
||||||
return -1;
|
return -1;
|
||||||
} else if (wsz > 1024 * 1024) {
|
} else if (wsz > 1024 * 1024) {
|
||||||
int kb4 = wsz / 1024 / 4;
|
int kb4 = wsz / 1024 / 4;
|
||||||
|
|||||||
@@ -72,8 +72,8 @@ free_monitor(struct monitor *m) {
|
|||||||
}
|
}
|
||||||
pthread_mutex_destroy(&m->mutex);
|
pthread_mutex_destroy(&m->mutex);
|
||||||
pthread_cond_destroy(&m->cond);
|
pthread_cond_destroy(&m->cond);
|
||||||
free(m->m);
|
skynet_free(m->m);
|
||||||
free(m);
|
skynet_free(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
@@ -140,12 +140,12 @@ static void
|
|||||||
_start(int thread) {
|
_start(int thread) {
|
||||||
pthread_t pid[thread+3];
|
pthread_t pid[thread+3];
|
||||||
|
|
||||||
struct monitor *m = malloc(sizeof(*m));
|
struct monitor *m = skynet_malloc(sizeof(*m));
|
||||||
memset(m, 0, sizeof(*m));
|
memset(m, 0, sizeof(*m));
|
||||||
m->count = thread;
|
m->count = thread;
|
||||||
m->sleep = 0;
|
m->sleep = 0;
|
||||||
|
|
||||||
m->m = malloc(thread * sizeof(struct skynet_monitor *));
|
m->m = skynet_malloc(thread * sizeof(struct skynet_monitor *));
|
||||||
int i;
|
int i;
|
||||||
for (i=0;i<thread;i++) {
|
for (i=0;i<thread;i++) {
|
||||||
m->m[i] = skynet_monitor_new();
|
m->m[i] = skynet_monitor_new();
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// include skynet.h first for malloc hook
|
|
||||||
#include "skynet.h"
|
#include "skynet.h"
|
||||||
|
|
||||||
#include "skynet_timer.h"
|
#include "skynet_timer.h"
|
||||||
@@ -93,7 +92,7 @@ add_node(struct timer *T,struct timer_node *node)
|
|||||||
static void
|
static void
|
||||||
timer_add(struct timer *T,void *arg,size_t sz,int time)
|
timer_add(struct timer *T,void *arg,size_t sz,int time)
|
||||||
{
|
{
|
||||||
struct timer_node *node = (struct timer_node *)malloc(sizeof(*node)+sz);
|
struct timer_node *node = (struct timer_node *)skynet_malloc(sizeof(*node)+sz);
|
||||||
memcpy(node+1,arg,sz);
|
memcpy(node+1,arg,sz);
|
||||||
|
|
||||||
while (__sync_lock_test_and_set(&T->lock,1)) {};
|
while (__sync_lock_test_and_set(&T->lock,1)) {};
|
||||||
@@ -147,7 +146,7 @@ timer_execute(struct timer *T) {
|
|||||||
|
|
||||||
struct timer_node * temp = current;
|
struct timer_node * temp = current;
|
||||||
current=current->next;
|
current=current->next;
|
||||||
free(temp);
|
skynet_free(temp);
|
||||||
} while (current);
|
} while (current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,7 +169,7 @@ timer_update(struct timer *T)
|
|||||||
static struct timer *
|
static struct timer *
|
||||||
timer_create_timer()
|
timer_create_timer()
|
||||||
{
|
{
|
||||||
struct timer *r=(struct timer *)malloc(sizeof(struct timer));
|
struct timer *r=(struct timer *)skynet_malloc(sizeof(struct timer));
|
||||||
memset(r,0,sizeof(*r));
|
memset(r,0,sizeof(*r));
|
||||||
|
|
||||||
int i,j;
|
int i,j;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// include skynet.h first for malloc hook
|
|
||||||
#include "skynet.h"
|
#include "skynet.h"
|
||||||
|
|
||||||
#include "socket_server.h"
|
#include "socket_server.h"
|
||||||
@@ -128,8 +127,8 @@ union sockaddr_all {
|
|||||||
struct sockaddr_in6 v6;
|
struct sockaddr_in6 v6;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MALLOC malloc
|
#define MALLOC skynet_malloc
|
||||||
#define FREE free
|
#define FREE skynet_free
|
||||||
|
|
||||||
static void
|
static void
|
||||||
socket_keepalive(int fd) {
|
socket_keepalive(int fd) {
|
||||||
|
|||||||
Reference in New Issue
Block a user