forked from cloudwu/skynet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskynet_harbor.c
49 lines (42 loc) · 1.12 KB
/
skynet_harbor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "skynet.h"
#include "skynet_harbor.h"
#include "skynet_server.h"
#include "skynet_mq.h"
#include "skynet_handle.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
static struct skynet_context * REMOTE = 0;
static unsigned int HARBOR = ~0;
void
skynet_harbor_send(struct remote_message *rmsg, uint32_t source, int session) {
int type = rmsg->sz >> MESSAGE_TYPE_SHIFT;
rmsg->sz &= MESSAGE_TYPE_MASK;
assert(type != PTYPE_SYSTEM && type != PTYPE_HARBOR && REMOTE);
skynet_context_send(REMOTE, rmsg, sizeof(*rmsg) , source, type , session);
}
int
skynet_harbor_message_isremote(uint32_t handle) {
assert(HARBOR != ~0);
int h = (handle & ~HANDLE_MASK);
return h != HARBOR && h !=0;
}
void
skynet_harbor_init(int harbor) {
HARBOR = (unsigned int)harbor << HANDLE_REMOTE_SHIFT;
}
void
skynet_harbor_start(void *ctx) {
// the HARBOR must be reserved to ensure the pointer is valid.
// It will be released at last by calling skynet_harbor_exit
skynet_context_reserve(ctx);
REMOTE = ctx;
}
void
skynet_harbor_exit() {
struct skynet_context * ctx = REMOTE;
REMOTE= NULL;
if (ctx) {
skynet_context_release(ctx);
}
}