new harbor

This commit is contained in:
云风
2012-08-17 11:50:45 +08:00
parent b06d380219
commit 4f6826de40
25 changed files with 331 additions and 1010 deletions

View File

@@ -5,12 +5,10 @@
#include "skynet_module.h"
#include "skynet_timer.h"
#include "skynet_harbor.h"
#include "skynet_master.h"
#include <pthread.h>
#include <unistd.h>
#include <assert.h>
#include <zmq.h>
static void *
_timer(void *p) {
@@ -33,59 +31,51 @@ _worker(void *p) {
static void
_start(int thread) {
pthread_t pid[thread+2];
pthread_t pid[thread+1];
pthread_create(&pid[0], NULL, _timer, NULL);
pthread_create(&pid[1], NULL, skynet_harbor_dispatch_thread, NULL);
int i;
for (i=2;i<thread+2;i++) {
for (i=1;i<thread+1;i++) {
pthread_create(&pid[i], NULL, _worker, NULL);
}
for (i=0;i<thread+2;i++) {
for (i=0;i<thread+1;i++) {
pthread_join(pid[i], NULL);
}
}
struct master_arg {
void * context;
const char * port;
};
static void *
_master_thread(void *ud) {
struct master_arg * args = ud;
skynet_master(args->context, args->port);
free(args);
return NULL;
}
static void
_start_master(void * context, const char * port) {
pthread_t pid;
struct master_arg * args = malloc(sizeof(*args));
args->context = context;
args->port = port;
pthread_create(&pid, NULL, _master_thread, args);
static int
_start_master(const char * master) {
struct skynet_context *ctx = skynet_context_new("master", master);
if (ctx == NULL)
return 1;
return 0;
}
void
skynet_start(struct skynet_config * config) {
void *context = zmq_init (1);
assert(context);
if (config->standalone) {
_start_master(context, config->master);
}
// harbor must be init first
skynet_harbor_init(context, config->master , config->local, config->harbor);
skynet_harbor_init(config->harbor);
skynet_handle_init(config->harbor);
skynet_mq_init(config->mqueue_size);
skynet_module_init(config->module_path);
skynet_timer_init();
if (config->standalone) {
if (_start_master(config->standalone)) {
return;
}
}
// harbor must be init first
if (skynet_harbor_start(config->master , config->local)) {
return;
}
struct skynet_context *ctx;
ctx = skynet_context_new("logger", config->logger);
assert(ctx);
if (ctx == NULL) {
return;
}
ctx = skynet_context_new("snlua", config->start);
_start(config->thread);