mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 02:53:09 +00:00
Increase message size 16M(24bit) limit to 56bit on 64bit arch
This commit is contained in:
@@ -3,12 +3,9 @@ thread = 8
|
|||||||
logger = "userlog"
|
logger = "userlog"
|
||||||
logservice = "snlua"
|
logservice = "snlua"
|
||||||
logpath = "."
|
logpath = "."
|
||||||
harbor = 1
|
harbor = 0
|
||||||
address = "127.0.0.1:2526"
|
|
||||||
master = "127.0.0.1:2013"
|
|
||||||
start = "main" -- main script
|
start = "main" -- main script
|
||||||
bootstrap = "snlua bootstrap" -- The service for bootstrap
|
bootstrap = "snlua bootstrap" -- The service for bootstrap
|
||||||
standalone = "0.0.0.0:2013"
|
|
||||||
luaservice = root.."service/?.lua;"..root.."test/?.lua;"..root.."examples/?.lua"
|
luaservice = root.."service/?.lua;"..root.."test/?.lua;"..root.."examples/?.lua"
|
||||||
lualoader = "lualib/loader.lua"
|
lualoader = "lualib/loader.lua"
|
||||||
-- preload = "./examples/preload.lua" -- run preload.lua before every lua service run
|
-- preload = "./examples/preload.lua" -- run preload.lua before every lua service run
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "skynet.h"
|
#include "skynet.h"
|
||||||
#include "skynet_harbor.h"
|
#include "skynet_harbor.h"
|
||||||
#include "skynet_socket.h"
|
#include "skynet_socket.h"
|
||||||
|
#include "skynet_handle.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
harbor listen the PTYPE_HARBOR (in text)
|
harbor listen the PTYPE_HARBOR (in text)
|
||||||
@@ -323,9 +324,13 @@ forward_local_messsage(struct harbor *h, void *msg, int 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);
|
size_t sz_header = sz+sizeof(*cookie);
|
||||||
|
if (sz_header > UINT32_MAX) {
|
||||||
|
skynet_error(ctx, "remote message from :%08x to :%08x is too large.", cookie->source, cookie->destination);
|
||||||
|
return;
|
||||||
|
}
|
||||||
uint8_t * sendbuf = skynet_malloc(sz_header+4);
|
uint8_t * sendbuf = skynet_malloc(sz_header+4);
|
||||||
to_bigendian(sendbuf, sz_header);
|
to_bigendian(sendbuf, (uint32_t)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);
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ skynet_error(struct skynet_context * context, const char *msg, ...) {
|
|||||||
}
|
}
|
||||||
smsg.session = 0;
|
smsg.session = 0;
|
||||||
smsg.data = data;
|
smsg.data = data;
|
||||||
smsg.sz = len | (PTYPE_TEXT << HANDLE_REMOTE_SHIFT);
|
smsg.sz = len | ((size_t)PTYPE_TEXT << MESSAGE_TYPE_SHIFT);
|
||||||
skynet_context_push(logger, &smsg);
|
skynet_context_push(logger, &smsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "skynet_harbor.h"
|
// reserve high 8 bits for remote id
|
||||||
|
#define HANDLE_MASK 0xffffff
|
||||||
|
#define HANDLE_REMOTE_SHIFT 24
|
||||||
|
|
||||||
struct skynet_context;
|
struct skynet_context;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#include "skynet.h"
|
#include "skynet.h"
|
||||||
#include "skynet_harbor.h"
|
#include "skynet_harbor.h"
|
||||||
#include "skynet_server.h"
|
#include "skynet_server.h"
|
||||||
|
#include "skynet_mq.h"
|
||||||
|
#include "skynet_handle.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -11,8 +13,8 @@ static unsigned int HARBOR = ~0;
|
|||||||
|
|
||||||
void
|
void
|
||||||
skynet_harbor_send(struct remote_message *rmsg, uint32_t source, int session) {
|
skynet_harbor_send(struct remote_message *rmsg, uint32_t source, int session) {
|
||||||
int type = rmsg->sz >> HANDLE_REMOTE_SHIFT;
|
int type = rmsg->sz >> MESSAGE_TYPE_SHIFT;
|
||||||
rmsg->sz &= HANDLE_MASK;
|
rmsg->sz &= MESSAGE_TYPE_MASK;
|
||||||
assert(type != PTYPE_SYSTEM && type != PTYPE_HARBOR && REMOTE);
|
assert(type != PTYPE_SYSTEM && type != PTYPE_HARBOR && REMOTE);
|
||||||
skynet_context_send(REMOTE, rmsg, sizeof(*rmsg) , source, type , session);
|
skynet_context_send(REMOTE, rmsg, sizeof(*rmsg) , source, type , session);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,6 @@
|
|||||||
#define GLOBALNAME_LENGTH 16
|
#define GLOBALNAME_LENGTH 16
|
||||||
#define REMOTE_MAX 256
|
#define REMOTE_MAX 256
|
||||||
|
|
||||||
// reserve high 8 bits for remote id
|
|
||||||
#define HANDLE_MASK 0xffffff
|
|
||||||
#define HANDLE_REMOTE_SHIFT 24
|
|
||||||
|
|
||||||
struct remote_name {
|
struct remote_name {
|
||||||
char name[GLOBALNAME_LENGTH];
|
char name[GLOBALNAME_LENGTH];
|
||||||
uint32_t handle;
|
uint32_t handle;
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ struct skynet_message {
|
|||||||
size_t sz;
|
size_t sz;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// type is encoding in skynet_message.sz high 8bit
|
||||||
|
#define MESSAGE_TYPE_MASK (SIZE_MAX >> 8)
|
||||||
|
#define MESSAGE_TYPE_SHIFT ((sizeof(size_t)-1) * 8)
|
||||||
|
|
||||||
struct message_queue;
|
struct message_queue;
|
||||||
|
|
||||||
void skynet_globalmq_push(struct message_queue * queue);
|
void skynet_globalmq_push(struct message_queue * queue);
|
||||||
|
|||||||
@@ -246,8 +246,8 @@ dispatch_message(struct skynet_context *ctx, struct skynet_message *msg) {
|
|||||||
assert(ctx->init);
|
assert(ctx->init);
|
||||||
CHECKCALLING_BEGIN(ctx)
|
CHECKCALLING_BEGIN(ctx)
|
||||||
pthread_setspecific(G_NODE.handle_key, (void *)(uintptr_t)(ctx->handle));
|
pthread_setspecific(G_NODE.handle_key, (void *)(uintptr_t)(ctx->handle));
|
||||||
int type = msg->sz >> HANDLE_REMOTE_SHIFT;
|
int type = msg->sz >> MESSAGE_TYPE_SHIFT;
|
||||||
size_t sz = msg->sz & HANDLE_MASK;
|
size_t sz = msg->sz & MESSAGE_TYPE_MASK;
|
||||||
if (ctx->logfile) {
|
if (ctx->logfile) {
|
||||||
skynet_log_output(ctx->logfile, msg->source, type, msg->session, msg->data, sz);
|
skynet_log_output(ctx->logfile, msg->source, type, msg->session, msg->data, sz);
|
||||||
}
|
}
|
||||||
@@ -662,13 +662,13 @@ _filter_args(struct skynet_context * context, int type, int *session, void ** da
|
|||||||
*data = msg;
|
*data = msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
*sz |= type << HANDLE_REMOTE_SHIFT;
|
*sz |= (size_t)type << MESSAGE_TYPE_SHIFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
skynet_send(struct skynet_context * context, uint32_t source, uint32_t destination , int type, int session, void * data, size_t sz) {
|
skynet_send(struct skynet_context * context, uint32_t source, uint32_t destination , int type, int session, void * data, size_t sz) {
|
||||||
if ((sz & HANDLE_MASK) != sz) {
|
if ((sz & MESSAGE_TYPE_MASK) != sz) {
|
||||||
skynet_error(context, "The message to %x is too large (sz = %lu)", destination, sz);
|
skynet_error(context, "The message to %x is too large", destination);
|
||||||
skynet_free(data);
|
skynet_free(data);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -751,7 +751,7 @@ skynet_context_send(struct skynet_context * ctx, void * msg, size_t sz, uint32_t
|
|||||||
smsg.source = source;
|
smsg.source = source;
|
||||||
smsg.session = session;
|
smsg.session = session;
|
||||||
smsg.data = msg;
|
smsg.data = msg;
|
||||||
smsg.sz = sz | type << HANDLE_REMOTE_SHIFT;
|
smsg.sz = sz | (size_t)type << MESSAGE_TYPE_SHIFT;
|
||||||
|
|
||||||
skynet_mq_push(ctx->queue, &smsg);
|
skynet_mq_push(ctx->queue, &smsg);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ skynet_socket_free() {
|
|||||||
static void
|
static void
|
||||||
forward_message(int type, bool padding, struct socket_message * result) {
|
forward_message(int type, bool padding, struct socket_message * result) {
|
||||||
struct skynet_socket_message *sm;
|
struct skynet_socket_message *sm;
|
||||||
int sz = sizeof(*sm);
|
size_t sz = sizeof(*sm);
|
||||||
if (padding) {
|
if (padding) {
|
||||||
if (result->data) {
|
if (result->data) {
|
||||||
sz += strlen(result->data);
|
sz += strlen(result->data);
|
||||||
@@ -56,7 +56,7 @@ forward_message(int type, bool padding, struct socket_message * result) {
|
|||||||
message.source = 0;
|
message.source = 0;
|
||||||
message.session = 0;
|
message.session = 0;
|
||||||
message.data = sm;
|
message.data = sm;
|
||||||
message.sz = sz | PTYPE_SOCKET << HANDLE_REMOTE_SHIFT;
|
message.sz = sz | ((size_t)PTYPE_SOCKET << MESSAGE_TYPE_SHIFT);
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "skynet_monitor.h"
|
#include "skynet_monitor.h"
|
||||||
#include "skynet_socket.h"
|
#include "skynet_socket.h"
|
||||||
#include "skynet_daemon.h"
|
#include "skynet_daemon.h"
|
||||||
|
#include "skynet_harbor.h"
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ dispatch_list(struct timer_node *current) {
|
|||||||
message.source = 0;
|
message.source = 0;
|
||||||
message.session = event->session;
|
message.session = event->session;
|
||||||
message.data = NULL;
|
message.data = NULL;
|
||||||
message.sz = PTYPE_RESPONSE << HANDLE_REMOTE_SHIFT;
|
message.sz = (size_t)MESSAGE_TYPE_SHIFT << MESSAGE_TYPE_SHIFT;
|
||||||
|
|
||||||
skynet_context_push(event->handle, &message);
|
skynet_context_push(event->handle, &message);
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ skynet_timeout(uint32_t handle, int time, int session) {
|
|||||||
message.source = 0;
|
message.source = 0;
|
||||||
message.session = session;
|
message.session = session;
|
||||||
message.data = NULL;
|
message.data = NULL;
|
||||||
message.sz = PTYPE_RESPONSE << HANDLE_REMOTE_SHIFT;
|
message.sz = (size_t)PTYPE_RESPONSE << MESSAGE_TYPE_SHIFT;
|
||||||
|
|
||||||
if (skynet_context_push(handle, &message)) {
|
if (skynet_context_push(handle, &message)) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
Reference in New Issue
Block a user