Compare commits

...

14 Commits

Author SHA1 Message Date
云风
57f37a55ba Merge pull request #113 from cloudwu/dev
bugfix
2014-05-19 10:53:08 +08:00
Cloud Wu
84e8abc09c update history 2014-05-19 10:51:20 +08:00
云风
dbfa17be09 Merge pull request #112 from zhoukk/master
remove services when launch error.
2014-05-19 10:50:12 +08:00
zhoukk
19729576f6 lua service launch错误时,移除services中记录
lua service launch错误后,没有移除 launcher.lua里services中的服务记录,导致debug_console中的list mem等命令返回数据不正确
2014-05-18 12:36:38 +08:00
Cloud Wu
a5df196e92 use skynet_error for memory dump 2014-05-16 17:36:49 +08:00
Cloud Wu
a2ad158dbc update PTYPE_* macro 2014-05-16 15:01:25 +08:00
Cloud Wu
ff155c623e bugfix: stdin is 0 2014-05-16 14:31:27 +08:00
Cloud Wu
9fe6a0a954 Merge branch 'master' into dev 2014-05-15 19:33:30 +08:00
Cloud Wu
c2ed2f8603 bugfix. the harbor and master service need to rewrite in future 2014-05-15 19:32:54 +08:00
Cloud Wu
a67e561a64 Merge branch 'master' into dev 2014-05-14 11:55:53 +08:00
Cloud Wu
ef2da264f1 bugfix: watchdog socket data 2014-05-14 11:55:40 +08:00
Cloud Wu
b397c70c34 remove unused pingqueue 2014-05-13 17:00:43 +08:00
Cloud Wu
02f2f88b6d Fix issue #109 2014-05-13 13:35:37 +08:00
Cloud Wu
29917efad7 add MAX_SLOT_SIZE limit 2014-05-13 11:09:15 +08:00
10 changed files with 54 additions and 34 deletions

View File

@@ -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)
-----------

View File

@@ -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)

View File

@@ -47,6 +47,9 @@ struct remote_message_header {
uint32_t session;
};
// 12 is sizeof(struct remote_message_header)
#define HEADER_COOKIE_LENGTH 12
struct harbor {
struct skynet_context *ctx;
char * local_addr;
@@ -502,23 +505,23 @@ _mainloop(struct skynet_context * context, void * ud, int type, int session, uin
case PTYPE_HARBOR: {
// remote message in
const char * cookie = msg;
cookie += sz - 12;
cookie += sz - HEADER_COOKIE_LENGTH;
struct remote_message_header header;
_message_to_header((const uint32_t *)cookie, &header);
if (header.source == 0) {
if (header.destination < REMOTE_MAX) {
// 1 byte harbor id (0~255)
// update remote harbor address
char ip [sz - 11];
memcpy(ip, msg, sz-12);
ip[sz-11] = '\0';
char ip [sz - HEADER_COOKIE_LENGTH + 1];
memcpy(ip, msg, sz-HEADER_COOKIE_LENGTH);
ip[sz-HEADER_COOKIE_LENGTH] = '\0';
_update_remote_address(h, header.destination, ip);
} else {
// update global name
if (sz - 12 > GLOBALNAME_LENGTH) {
char name[sz-11];
memcpy(name, msg, sz-12);
name[sz-11] = '\0';
if (sz - HEADER_COOKIE_LENGTH > GLOBALNAME_LENGTH) {
char name[sz-HEADER_COOKIE_LENGTH+1];
memcpy(name, msg, sz-HEADER_COOKIE_LENGTH);
name[sz-HEADER_COOKIE_LENGTH] = '\0';
skynet_error(context, "Global name is too long %s", name);
}
_update_remote_name(h, msg, header.destination);
@@ -527,7 +530,7 @@ _mainloop(struct skynet_context * context, void * ud, int type, int session, uin
uint32_t destination = header.destination;
int type = (destination >> HANDLE_REMOTE_SHIFT) | PTYPE_TAG_DONTCOPY;
destination = (destination & HANDLE_MASK) | ((uint32_t)h->id << HANDLE_REMOTE_SHIFT);
skynet_send(context, header.source, destination, type, (int)header.session, (void *)msg, sz-12);
skynet_send(context, header.source, destination, type, (int)header.session, (void *)msg, sz-HEADER_COOKIE_LENGTH);
return 1;
}
return 0;

View File

@@ -85,7 +85,7 @@ function MSG.data(fd, msg, sz)
if agent then
skynet.redirect(agent, c.client, "client", 0, msg, sz)
else
skynet.send(watchdog, "lua", "socket", "data", netpack.tostring(msg, sz))
skynet.send(watchdog, "lua", "socket", "data", fd, netpack.tostring(msg, sz))
end
end

View File

@@ -88,7 +88,7 @@ function command.ERROR(address)
skynet.redirect(reply.address , 0, "response", reply.session, "")
instance[address] = nil
end
services[address] = nil
return NORET
end

View File

@@ -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;
}
@@ -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);
@@ -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 *

View File

@@ -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

View File

@@ -9,6 +9,7 @@
#include <string.h>
#define DEFAULT_SLOT_SIZE 4
#define MAX_SLOT_SIZE 0x40000000
struct handle_name {
char * name;
@@ -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++) {

View File

@@ -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
@@ -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;
@@ -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;

View File

@@ -1,12 +0,0 @@
local skynet = require "skynet"
local mqueue = require "mqueue"
skynet.start(function()
local id = 0
local pingserver = skynet.newservice "pingserver"
mqueue.register(function(str)
id = id + 1
str = string.format("id = %d , %s",id, str)
return skynet.call(pingserver, "lua", "PING", str)
end)
end)