mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
some bugfix for gate/socket lib
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "skynet.h"
|
||||
#include "skynet_socket.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
@@ -7,8 +8,7 @@
|
||||
#include <string.h>
|
||||
|
||||
struct client {
|
||||
int gate;
|
||||
uint8_t id[4];
|
||||
int id;
|
||||
};
|
||||
|
||||
static int
|
||||
@@ -17,14 +17,11 @@ _cb(struct skynet_context * context, void * ud, int type, int session, uint32_t
|
||||
struct client * c = ud;
|
||||
// tmp will be free by skynet_socket.
|
||||
// see skynet_src/socket_server.c : send_socket()
|
||||
uint8_t *tmp = malloc(sz + 4 + 2);
|
||||
uint8_t *tmp = malloc(sz + 2);
|
||||
tmp[0] = (sz >> 8) & 0xff;
|
||||
tmp[1] = sz & 0xff;
|
||||
memcpy(tmp+2, msg, sz);
|
||||
// 4 bytes id at the end
|
||||
memcpy(tmp+2+sz, c->id, 4);
|
||||
|
||||
skynet_send(context, source, c->gate, PTYPE_CLIENT | PTYPE_TAG_DONTCOPY, 0, tmp, sz+6);
|
||||
skynet_socket_send(context, c->id, tmp, sz+2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -32,16 +29,13 @@ _cb(struct skynet_context * context, void * ud, int type, int session, uint32_t
|
||||
int
|
||||
client_init(struct client *c, struct skynet_context *ctx, const char * args) {
|
||||
int fd = 0, gate = 0, id = 0;
|
||||
// gate and id is unused now.
|
||||
sscanf(args, "%d %d %d",&fd,&gate,&id);
|
||||
if (gate == 0) {
|
||||
skynet_error(ctx, "Invalid init client %s",args);
|
||||
return 1;
|
||||
}
|
||||
c->gate = gate;
|
||||
c->id[0] = id & 0xff;
|
||||
c->id[1] = (id >> 8) & 0xff;
|
||||
c->id[2] = (id >> 16) & 0xff;
|
||||
c->id[3] = (id >> 24) & 0xff;
|
||||
c->id = fd;
|
||||
skynet_callback(ctx, c, _cb);
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user