Skip to content

Commit

Permalink
play with uv threads
Browse files Browse the repository at this point in the history
  • Loading branch information
pquerna committed Mar 17, 2012
1 parent 876daf9 commit fb4f774
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ Spedye is meant to handle all TLS/SSL traffic for a website -- it is based upon

Spedye aims to make adopting the SPDY protocol extremely easy for all kinds of websites.

# STATUS: incomplete, prototype, etc
# STATUS: incomplete, prototype, work in progress, non-functional, etc, etc


## Features

## Goals / Features

* Built on top of [spdylay](https://github.com/tatsuhiro-t/spdylay).
* SPDY version 2 and version 3
* Multiple threads or processes each running their own libuv event loop to parallelize cryptographic operations across CPUs.
* Server Name Indication: Support for multiple Certificates on a single listening address.


## Usage

The simplest configuration is to forward all traffic on port `:443` to port `:80`:
Expand Down
10 changes: 10 additions & 0 deletions src/spedye.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@ typedef struct spedye_conf_t {
const char *keypath;
} spedye_conf_t;

typedef enum {
SPEDYE_STARTING,
SPEDYE_RUNNING,
SPEDYE_STOPING,
SPEDYE_STOPPED,
} spedye_master_state;

typedef struct spedye_master_t {
uv_thread_t master_thread;
uv_async_t master_wakeup;
spedye_master_state state;
uv_loop_t *loop;
} spedye_master_t;

Expand Down
36 changes: 34 additions & 2 deletions src/spedye_master.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,64 @@

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


static void
master_entry(void* arg)
{
spedye_master_t *m = arg;
m->state = SPEDYE_RUNNING;
fprintf(stderr, "%p\n", m);
}

static void
master_shutdown(uv_async_t* handle, int status)
{
spedye_master_t *m = handle->data;
m->state = SPEDYE_STOPING;
m->master_wakeup.data = NULL;
}

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

*m_out = NULL;

m = malloc(sizeof(spedye_master_t));
m = calloc(1, sizeof(spedye_master_t));
m->loop = loop;
m->state = SPEDYE_STARTING;
uv_ref(m->loop);

rc = uv_async_init(m->loop, &m->master_wakeup, master_shutdown);

m->master_wakeup.data = m;

*m_out = m;

return 0;
return rc;
}

int
spedye_master_run(spedye_master_t *m)
{
int rc;

rc = uv_thread_create(&m->master_thread, master_entry, (void*)m);

return 0;
}

void
spedye_master_destroy(spedye_master_t *m)
{
/* Send wakeup */
uv_async_send(&m->master_wakeup);
uv_thread_join(&m->master_thread);
m->state = SPEDYE_STOPPED;
uv_unref(m->loop);
free(m);
}
Expand Down

0 comments on commit fb4f774

Please sign in to comment.