Skip to content

Commit

Permalink
start stubbing master
Browse files Browse the repository at this point in the history
  • Loading branch information
pquerna committed Mar 13, 2012
1 parent 93f3da8 commit 3203196
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 8 deletions.
1 change: 1 addition & 0 deletions spedye.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
],
'sources': [
'src/spedye_init.c',
'src/spedye_master.c',
],
'include_dirs': [
'src',
Expand Down
14 changes: 13 additions & 1 deletion src/spedye.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,21 @@

#include "uv.h"

typedef struct spedye_conf_t {
const char *certpath;
const char *keypath;
} spedye_conf_t;

typedef struct spedye_master_t {
uv_loop_t *loop;
} spedye_master_t;


void spedye_process_init();
void spedye_process_destroy();

int spedye_init(uv_loop_t *loop);
int spedye_master_create(spedye_master_t **m, spedye_conf_t *conf, uv_loop_t *loop);
int spedye_master_run(spedye_master_t *m);
void spedye_master_destroy(spedye_master_t *m);

#endif
5 changes: 0 additions & 5 deletions src/spedye_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ crypto_lock_cb(int mode, int n, const char* file, int line)
}


static void
spedye_init_ssl()
{
}

static int have_init_spedye = 0;

void
Expand Down
37 changes: 35 additions & 2 deletions src/spedye_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>

#ifndef WIN32
#include <pthread.h>
Expand All @@ -26,14 +27,46 @@

#include "spedye.h"

static int
process_args(spedye_conf_t *conf, int argc, char *argv[])
{
int i;
/* TODO: parse args */
for (i = 0; i < argc; i++) {
printf("[%d] = %s\n", i, argv[i]);
}
return 0;
}

int main(int argc, char *argv[])
{
int rv;
spedye_conf_t conf;
spedye_master_t *master;
uv_loop_t *loop;

loop = uv_default_loop();
memset(&conf, 0, sizeof(spedye_conf_t));

spedye_process_init();
/* TODO: parse args */

rv = process_args(&conf, argc, argv);

if (rv) {
return rv;
}

loop = uv_default_loop();

rv = spedye_master_create(&master, &conf, loop);

if (rv) {
return rv;
}

spedye_master_run(master);

spedye_master_destroy(master);

/* TOOD: spawn loops/other threads */
/* TOOD: Create listeners */
/* TOOD: handle HTTPS 1:1 -> HTTP */
Expand Down
49 changes: 49 additions & 0 deletions src/spedye_master.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2012 The Spedye Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include "spedye.h"
#include <stdlib.h>

int
spedye_master_create(spedye_master_t **m_out, spedye_conf_t *conf, uv_loop_t *loop)
{
spedye_master_t *m;

*m_out = NULL;

m = malloc(sizeof(spedye_master_t));
m->loop = loop;
uv_ref(m->loop);

*m_out = m;

return 0;
}

int
spedye_master_run(spedye_master_t *m)
{
return 0;
}

void
spedye_master_destroy(spedye_master_t *m)
{
uv_unref(m->loop);
free(m);
}

0 comments on commit 3203196

Please sign in to comment.