Skip to content

Commit

Permalink
Merge pull request #113 from cloudwu/dev
Browse files Browse the repository at this point in the history
bugfix
  • Loading branch information
cloudwu committed May 19, 2014
2 parents dbfa17b + 84e8abc commit 57f37a5
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 23 deletions.
7 changes: 7 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
v0.2.1 (2014-5-19)
-----------
* Bugfix: check all the events already read after socket close
* Bugfix: socket data in gate service
* Bugfix: boundary problem in harbor service
* Bugfix: stdin handle is 0

v0.2.0 (2014-5-12)
-----------

Expand Down
2 changes: 1 addition & 1 deletion lualib/socket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function socket.bind(os_fd)
end

function socket.stdin()
return socket.bind(1)
return socket.bind(0)
end

function socket.start(id, func)
Expand Down
12 changes: 6 additions & 6 deletions skynet-src/malloc_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ mallctl_int64(const char* name, size_t* newval) {
} else {
je_mallctl(name, &v, &len, NULL, 0);
}
// printf("name: %s, value: %zd\n", name, v);
// skynet_error(NULL, "name: %s, value: %zd\n", name, v);
return v;
}

Expand All @@ -117,9 +117,9 @@ mallctl_opt(const char* name, int* newval) {
if(newval) {
int ret = je_mallctl(name, &v, &len, newval, sizeof(int));
if(ret == 0) {
printf("set new value(%d) for (%s) succeed\n", *newval, name);
skynet_error(NULL, "set new value(%d) for (%s) succeed\n", *newval, name);
} else {
printf("set new value(%d) for (%s) failed: error -> %d\n", *newval, name, ret);
skynet_error(NULL, "set new value(%d) for (%s) failed: error -> %d\n", *newval, name, ret);
}
} else {
je_mallctl(name, &v, &len, NULL, 0);
Expand Down Expand Up @@ -196,15 +196,15 @@ void
dump_c_mem() {
int i;
size_t total = 0;
printf("dump all service mem:\n");
skynet_error(NULL, "dump all service mem:");
for(i=0; i<SLOT_SIZE; i++) {
mem_data* data = &mem_stats[i];
if(data->handle != 0 && data->allocated != 0) {
total += data->allocated;
printf("0x%x -> %zdkb\n", data->handle, data->allocated >> 10);
skynet_error(NULL, "0x%x -> %zdkb", data->handle, data->allocated >> 10);
}
}
printf("+total: %zdkb\n",total >> 10);
skynet_error(NULL, "+total: %zdkb",total >> 10);
}

char *
Expand Down
5 changes: 3 additions & 2 deletions skynet-src/skynet.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
#define PTYPE_SYSTEM 4
#define PTYPE_HARBOR 5
#define PTYPE_SOCKET 6
// read lualib/skynet.lua lualib/simplemonitor.lua
// read lualib/skynet.lua examples/simplemonitor.lua
#define PTYPE_ERROR 7
// read lualib/skynet.lua lualib/mqueue.lua
// read lualib/skynet.lua lualib/mqueue.lua lualib/snax.lua
#define PTYPE_RESERVED_QUEUE 8
#define PTYPE_RESERVED_DEBUG 9
#define PTYPE_RESERVED_LUA 10
#define PTYPE_RESERVED_SNAX 11

#define PTYPE_TAG_DONTCOPY 0x10000
#define PTYPE_TAG_ALLOCSESSION 0x20000
Expand Down
2 changes: 2 additions & 0 deletions skynet-src/skynet_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string.h>

#define DEFAULT_SLOT_SIZE 4
#define MAX_SLOT_SIZE 0x40000000

struct handle_name {
char * name;
Expand Down Expand Up @@ -168,6 +169,7 @@ static void
_insert_name_before(struct handle_storage *s, char *name, uint32_t handle, int before) {
if (s->name_count >= s->name_cap) {
s->name_cap *= 2;
assert(s->name_cap <= MAX_SLOT_SIZE);
struct handle_name * n = skynet_malloc(s->name_cap * sizeof(struct handle_name));
int i;
for (i=0;i<before;i++) {
Expand Down
23 changes: 21 additions & 2 deletions skynet-src/socket_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,22 @@ report_accept(struct socket_server *ss, struct socket *s, struct socket_message
return 1;
}

static inline void
clear_closed_event(struct socket_server *ss, struct socket_message * result, int type) {
if (type == SOCKET_CLOSE || type == SOCKET_ERROR) {
int id = result->id;
int i;
for (i=ss->event_index; i<ss->event_n; i++) {
struct event *e = &ss->ev[i];
struct socket *s = e->s;
if (s) {
if (s->type == SOCKET_TYPE_INVALID && s->id == id) {
e->s = NULL;
}
}
}
}
}

// return type
int
Expand All @@ -823,9 +839,10 @@ socket_server_poll(struct socket_server *ss, struct socket_message * result, int
if (ss->checkctrl) {
if (has_cmd(ss)) {
int type = ctrl_cmd(ss, result);
if (type != -1)
if (type != -1) {
clear_closed_event(ss, result, type);
return type;
else
} else
continue;
} else {
ss->checkctrl = 0;
Expand Down Expand Up @@ -865,12 +882,14 @@ socket_server_poll(struct socket_server *ss, struct socket_message * result, int
int type = send_buffer(ss, s, result);
if (type == -1)
break;
clear_closed_event(ss, result, type);
return type;
}
if (e->read) {
int type = forward_message(ss, s, result);
if (type == -1)
break;
clear_closed_event(ss, result, type);
return type;
}
break;
Expand Down
12 changes: 0 additions & 12 deletions test/pingqueue.lua

This file was deleted.

0 comments on commit 57f37a5

Please sign in to comment.