mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 12:43:09 +00:00
remove old client
This commit is contained in:
2
Makefile
2
Makefile
@@ -12,7 +12,7 @@ CFLAGS = -g -Wall -I$(LUA_INC) $(MYCFLAGS)
|
|||||||
$(LUA_STATICLIB) :
|
$(LUA_STATICLIB) :
|
||||||
cd 3rd/lua && $(MAKE) CC=$(CC) $(PLAT)
|
cd 3rd/lua && $(MAKE) CC=$(CC) $(PLAT)
|
||||||
|
|
||||||
CSERVICE = snlua logger gate client master multicast tunnel harbor localcast
|
CSERVICE = snlua logger gate master multicast tunnel harbor localcast
|
||||||
LUA_CLIB = skynet socketdriver int64 mcast bson mongo md5 netpack cjson clientsocket
|
LUA_CLIB = skynet socketdriver int64 mcast bson mongo md5 netpack cjson clientsocket
|
||||||
|
|
||||||
SKYNET_SRC = skynet_main.c skynet_handle.c skynet_module.c skynet_mq.c \
|
SKYNET_SRC = skynet_main.c skynet_handle.c skynet_module.c skynet_mq.c \
|
||||||
|
|||||||
@@ -22,8 +22,12 @@ skynet.register_protocol {
|
|||||||
return jsonpack.unpack(skynet.tostring(msg,sz))
|
return jsonpack.unpack(skynet.tostring(msg,sz))
|
||||||
end,
|
end,
|
||||||
dispatch = function (_, _, session, args)
|
dispatch = function (_, _, session, args)
|
||||||
local result = skynet.call("SIMPLEDB", "lua", table.unpack(args))
|
local ok, result = pcall(skynet.call,"SIMPLEDB", "lua", table.unpack(args))
|
||||||
response_client(session, result)
|
if ok then
|
||||||
|
response_client(session, { true, result })
|
||||||
|
else
|
||||||
|
response_client(session, { false, "Invalid command" })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ local function dispatch()
|
|||||||
assert(t == '-' or t == '+')
|
assert(t == '-' or t == '+')
|
||||||
session = tonumber(session)
|
session = tonumber(session)
|
||||||
local result = cjson.decode(str)
|
local result = cjson.decode(str)
|
||||||
print("Response:",session, result)
|
print("Response:",session, result[1], result[2])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,62 +0,0 @@
|
|||||||
#include "skynet.h"
|
|
||||||
#include "skynet_socket.h"
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
struct client {
|
|
||||||
int id;
|
|
||||||
};
|
|
||||||
|
|
||||||
static int
|
|
||||||
_cb(struct skynet_context * context, void * ud, int type, int session, uint32_t source, const void * msg, size_t sz) {
|
|
||||||
assert(sz <= 65535);
|
|
||||||
struct client * c = ud;
|
|
||||||
if (type == PTYPE_RESERVED_ERROR) {
|
|
||||||
// todo: tell client the session is broken
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (type == PTYPE_RESPONSE) {
|
|
||||||
// todo: response to client with session, session may be packed into package
|
|
||||||
} else {
|
|
||||||
assert(type == PTYPE_TEXT);
|
|
||||||
// todo: support other protocol
|
|
||||||
}
|
|
||||||
// todo: design the protocol between client and agent
|
|
||||||
// tmp will be free by skynet_socket.
|
|
||||||
// see skynet_src/socket_server.c : send_socket()
|
|
||||||
uint8_t *tmp = malloc(sz + 2);
|
|
||||||
tmp[0] = (sz >> 8) & 0xff;
|
|
||||||
tmp[1] = sz & 0xff;
|
|
||||||
memcpy(tmp+2, msg, sz);
|
|
||||||
skynet_socket_send(context, c->id, tmp, sz+2);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
client_init(struct client *c, struct skynet_context *ctx, const char * args) {
|
|
||||||
int id = 0;
|
|
||||||
if (args == NULL)
|
|
||||||
return 1;
|
|
||||||
sscanf(args, "%d",&id);
|
|
||||||
c->id = id;
|
|
||||||
skynet_callback(ctx, c, _cb);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct client *
|
|
||||||
client_create(void) {
|
|
||||||
struct client *c = malloc(sizeof(*c));
|
|
||||||
memset(c,0,sizeof(*c));
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
client_release(struct client *c) {
|
|
||||||
free(c);
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user