mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 02:53:09 +00:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
57f37a55ba | ||
|
|
84e8abc09c | ||
|
|
dbfa17be09 | ||
|
|
19729576f6 | ||
|
|
a5df196e92 | ||
|
|
a2ad158dbc | ||
|
|
ff155c623e | ||
|
|
9fe6a0a954 | ||
|
|
c2ed2f8603 | ||
|
|
a67e561a64 | ||
|
|
ef2da264f1 | ||
|
|
b397c70c34 | ||
|
|
02f2f88b6d | ||
|
|
29917efad7 |
@@ -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)
|
||||
-----------
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 *
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user