Skip to content

Commit

Permalink
Fixed latest libuv API change breakages.
Browse files Browse the repository at this point in the history
  • Loading branch information
kellabyte committed Sep 10, 2013
1 parent 093d48c commit 6f162f1
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 32 deletions.
21 changes: 9 additions & 12 deletions src/haywire/connection_consumer.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
#include "connection_consumer.h"
#include "http_server.h"
#include "http_connection.h"
#include "http_response_cache.h"

void ipc_read2_cb(uv_pipe_t* ipc_pipe, ssize_t nread, uv_buf_t buf, uv_handle_type type)
void ipc_read2_cb(uv_pipe_t* ipc_pipe, ssize_t nread, const uv_buf_t* buf, uv_handle_type type)
{
int rc;
struct ipc_client_ctx* ctx;
Expand All @@ -23,11 +24,12 @@ void ipc_read2_cb(uv_pipe_t* ipc_pipe, ssize_t nread, uv_buf_t buf, uv_handle_ty
uv_close((uv_handle_t*) &ctx->ipc_pipe, NULL);
}

uv_buf_t ipc_alloc_cb(uv_handle_t* handle, size_t suggested_size)
void ipc_alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf)
{
struct ipc_client_ctx* ctx;
ctx = container_of(handle, struct ipc_client_ctx, ipc_pipe);
return uv_buf_init(ctx->scratch, sizeof(ctx->scratch));
buf->base = ctx->scratch;
buf->len = sizeof(ctx->scratch);
}

void ipc_connect_cb(uv_connect_t* req, int status)
Expand All @@ -38,16 +40,11 @@ void ipc_connect_cb(uv_connect_t* req, int status)
rc = uv_read2_start((uv_stream_t*)&ctx->ipc_pipe, ipc_alloc_cb, ipc_read2_cb);
}

void sv_read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf)
void connection_consumer_alloc(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf)
{
//ASSERT(nread == UV_EOF);
uv_close((uv_handle_t*) handle, (uv_close_cb)free);
}

uv_buf_t connection_consumer_alloc(uv_handle_t* handle, size_t suggested_size)
{
static char buf[32];
return uv_buf_init(buf, sizeof(buf));
static char slab[32];
buf->base = slab;
buf->len = sizeof(slab);
}

void connection_consumer_new_connection(uv_stream_t* server_handle, int status)
Expand Down
7 changes: 5 additions & 2 deletions src/haywire/connection_dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "connection_dispatcher.h"
#include "connection_consumer.h"

static struct sockaddr_in listen_addr;

void ipc_close_cb(uv_handle_t* handle)
{
struct ipc_peer_ctx* ctx;
Expand Down Expand Up @@ -65,9 +67,10 @@ void start_connection_dispatching(uv_handle_type type, unsigned int num_servers,

if (type == UV_TCP)
{
struct sockaddr_in listen_addr = uv_ip4_addr(listen_address, listen_port);
uv_ip4_addr(listen_address, listen_port, &listen_addr);

rc = uv_tcp_init(loop, (uv_tcp_t*) &ctx.server_handle);
rc = uv_tcp_bind((uv_tcp_t*) &ctx.server_handle, listen_addr);
rc = uv_tcp_bind((uv_tcp_t*) &ctx.server_handle, (const struct sockaddr*)&listen_addr);
printf("Listening on %s:%d\n", listen_address, listen_port);
}

Expand Down
45 changes: 29 additions & 16 deletions src/haywire/http_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ KHASH_MAP_INIT_STR(string_hashmap, hw_route_entry*)
static configuration* config;
static uv_tcp_t server;
static http_parser_settings parser_settings;
static struct sockaddr_in listen_address;

uv_loop_t* uv_loop;
void* routes;
Expand Down Expand Up @@ -163,7 +164,11 @@ int hw_http_open(int threads)
{
/* If running single threaded there is no need to use the IPC pipe
to distribute requests between threads so lets avoid the IPC overhead */
uv_tcp_bind(&server, uv_ip4_addr(config->http_listen_address, config->http_listen_port));

initialize_http_request_cache();

uv_ip4_addr(config->http_listen_address, config->http_listen_port, &listen_address);
uv_tcp_bind(&server, (const struct sockaddr*)&listen_address);
uv_listen((uv_stream_t*)&server, 128, http_stream_on_connect);
printf("Listening on %s:%d\n", config->http_listen_address, config->http_listen_port);
uv_run(uv_loop, UV_RUN_DEFAULT);
Expand Down Expand Up @@ -206,12 +211,10 @@ void http_stream_on_connect(uv_stream_t* stream, int status)
uv_read_start((uv_stream_t*)&connection->stream, http_stream_on_alloc, http_stream_on_read);
}

uv_buf_t http_stream_on_alloc(uv_handle_t* client, size_t suggested_size)
void http_stream_on_alloc(uv_handle_t* client, size_t suggested_size, uv_buf_t* buf)
{
uv_buf_t buf;
buf.base = (char *)malloc(suggested_size);
buf.len = suggested_size;
return buf;
buf->base = malloc(suggested_size);
buf->len = suggested_size;
}

void http_stream_on_close(uv_handle_t* handle)
Expand All @@ -220,24 +223,34 @@ void http_stream_on_close(uv_handle_t* handle)
free_http_connection(connection);
}

void http_stream_on_read(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf)
void http_stream_on_read(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* buf)
{
size_t parsed;
ssize_t parsed;
http_connection* connection = (http_connection*)tcp->data;

if (nread >= 0)

uv_shutdown_t* req;
if (nread < 0)
{
parsed = http_parser_execute(&connection->parser, &parser_settings, buf.base, nread);
if (parsed < nread)
// Error or EOF
if (buf->base)
{
/* uv_close((uv_handle_t*) &client->handle, http_stream_on_close); */
free(buf->base);
}

req = (uv_shutdown_t*) malloc(sizeof *req);
uv_close((uv_handle_t*) &connection->stream, http_stream_on_close);
return;
}
else

if (nread == 0)
{
uv_close((uv_handle_t*) &connection->stream, http_stream_on_close);
// Everything OK, but nothing read.
free(buf->base);
return;
}
free(buf.base);

parsed = http_parser_execute(&connection->parser, &parser_settings, buf->base, nread);

}

int http_server_write_response(hw_write_context* write_context, hw_string* response)
Expand Down
4 changes: 2 additions & 2 deletions src/haywire/http_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ extern uv_barrier_t* listeners_created_barrier;

http_connection* create_http_connection();
void http_stream_on_connect(uv_stream_t* stream, int status);
uv_buf_t http_stream_on_alloc(uv_handle_t* client, size_t suggested_size);
void http_stream_on_alloc(uv_handle_t* client, size_t suggested_size, uv_buf_t* buf);
void http_stream_on_close(uv_handle_t* handle);
int http_server_write_response(hw_write_context* write_context, hw_string* response);
void http_server_after_write(uv_write_t* req, int status);
void http_stream_on_read(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf);
void http_stream_on_read(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* buf);

0 comments on commit 6f162f1

Please sign in to comment.