remove old client

This commit is contained in:
Cloud Wu
2014-04-14 22:31:23 +08:00
parent 98c9059a60
commit 47167ea2e8
4 changed files with 8 additions and 66 deletions

View File

@@ -12,7 +12,7 @@ CFLAGS = -g -Wall -I$(LUA_INC) $(MYCFLAGS)
$(LUA_STATICLIB) :
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
SKYNET_SRC = skynet_main.c skynet_handle.c skynet_module.c skynet_mq.c \

View File

@@ -22,8 +22,12 @@ skynet.register_protocol {
return jsonpack.unpack(skynet.tostring(msg,sz))
end,
dispatch = function (_, _, session, args)
local result = skynet.call("SIMPLEDB", "lua", table.unpack(args))
response_client(session, result)
local ok, result = pcall(skynet.call,"SIMPLEDB", "lua", table.unpack(args))
if ok then
response_client(session, { true, result })
else
response_client(session, { false, "Invalid command" })
end
end
}

View File

@@ -23,7 +23,7 @@ local function dispatch()
assert(t == '-' or t == '+')
session = tonumber(session)
local result = cjson.decode(str)
print("Response:",session, result)
print("Response:",session, result[1], result[2])
end
end
end

View File

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