mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 02:53:09 +00:00
50 lines
1.1 KiB
C
50 lines
1.1 KiB
C
#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);
|
|
}
|
|
}
|