Skip to content

Commit

Permalink
Switch to libevent2 API
Browse files Browse the repository at this point in the history
  • Loading branch information
semigodking committed Oct 13, 2016
1 parent 94c8a8c commit 01c58b1
Show file tree
Hide file tree
Showing 19 changed files with 336 additions and 264 deletions.
8 changes: 5 additions & 3 deletions autoproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <errno.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <event2/bufferevent.h>
#include <event2/bufferevent_struct.h>
#include "utils.h"
#include "log.h"
#include "redsocks.h"
Expand Down Expand Up @@ -243,7 +245,7 @@ static void auto_recv_timeout_cb(evutil_socket_t fd, short events, void * arg)

static void direct_relay_readcb_helper(redsocks_client *client, struct bufferevent *from, struct bufferevent *to)
{
if (evbuffer_get_length(bufferevent_get_output(to)) < to->wm_write.high)
if (evbuffer_get_length(bufferevent_get_output(to)) < get_write_hwm(to))
{
if (bufferevent_write_buffer(to, bufferevent_get_input(from)) == -1)
redsocks_log_errno(client, LOG_ERR, "bufferevent_write_buffer");
Expand Down Expand Up @@ -403,7 +405,7 @@ static void direct_relay_clientwritecb(struct bufferevent *to, void *_client)
return;
if (handle_write_to_client(client))
return;
if (output_size < to->wm_write.high)
if (output_size < get_write_hwm(to))
{
if (bufferevent_write_buffer(to, bufferevent_get_input(from)) == -1)
redsocks_log_errno(client, LOG_ERR, "bufferevent_write_buffer");
Expand Down Expand Up @@ -455,7 +457,7 @@ static void direct_relay_relaywritecb(struct bufferevent *to, void *_client)
return;
if (aclient->state == AUTOPROXY_CONFIRMED)
{
if (output_size < to->wm_write.high)
if (output_size < get_write_hwm(to))
{
if (bufferevent_write_buffer(to, bufferevent_get_input(from)) == -1)
redsocks_log_errno(client, LOG_ERR, "bufferevent_write_buffer");
Expand Down
2 changes: 0 additions & 2 deletions direct.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <event.h>
#include "parser.h"
#include "log.h"
#include "main.h"
#include "base.h"
#include "redsocks.h"
#include "utils.h"

Expand Down
5 changes: 3 additions & 2 deletions http-relay.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <event2/bufferevent.h>
#include <event2/bufferevent_struct.h>
#include "log.h"
#include "redsocks.h"
#include "http-auth.h"
Expand Down Expand Up @@ -362,8 +364,7 @@ static void httpr_relay_write_cb(struct bufferevent *buffev, void *_arg)

client->state = httpr_request_sent;

buffev->wm_read.low = 1;
buffev->wm_read.high = HTTP_HEAD_WM_HIGH;
bufferevent_setwatermark(buffev, EV_READ, 1, HTTP_HEAD_WM_HIGH);
bufferevent_enable(buffev, EV_READ);
}
}
Expand Down
14 changes: 8 additions & 6 deletions ipcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static int * addr_cache_counters = NULL;
static int * addr_cache_pointers = NULL;
static cache_data * addr_cache = NULL;
static char cache_changed = 0;
static struct event timer_event;
static struct event * timer_event = NULL;

static inline cache_data * get_cache_data(unsigned int block, unsigned int index);

Expand Down Expand Up @@ -253,7 +253,6 @@ static int cache_init()
}
memset((void *)addr_cache_pointers, 0, size);

memset(&timer_event, 0, sizeof(timer_event));
if (config->cache_file)
{
if (load_cache(config->cache_file))
Expand All @@ -264,8 +263,9 @@ static int cache_init()
{
tv.tv_sec = config->autosave_interval;
tv.tv_usec = 0;
event_assign(&timer_event, get_event_base(), 0, EV_TIMEOUT|EV_PERSIST, cache_auto_saver, NULL);
evtimer_add(&timer_event, &tv);
timer_event = event_new(get_event_base(), -1, EV_TIMEOUT|EV_PERSIST, cache_auto_saver, NULL);
if (timer_event)
evtimer_add(timer_event, &tv);
}
}
set_cache_changed(0);
Expand All @@ -282,9 +282,11 @@ static int cache_fini()
save_cache(config->cache_file);
set_cache_changed(0);
}
if (event_initialized(&timer_event))
if (timer_event)
{
evtimer_del(&timer_event);
evtimer_del(timer_event);
event_free(timer_event);
timer_event = NULL;
}
// Free buffers allocated for cache
if (addr_cache)
Expand Down
11 changes: 0 additions & 11 deletions libevent-compat.h

This file was deleted.

2 changes: 1 addition & 1 deletion log.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <errno.h>
#include <sys/time.h>
#include <sys/types.h>
#include <event.h>
#include <event2/event.h>
#include "utils.h"
#include "log.h"

Expand Down
Loading

0 comments on commit 01c58b1

Please sign in to comment.