Permalink
Browse files

modified to work with libbeanstalkclient

  • Loading branch information...
1 parent 1e74d87 commit d2eb95d724dddd053f86254948914fdb2429fe9a @bergundy committed Aug 2, 2010
Showing with 190 additions and 142 deletions.
  1. +15 −4 src/evbsc.c
  2. +7 −11 src/evbsc.h
  3. +168 −127 tests/check_evbsc.c
View
@@ -13,30 +13,41 @@
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include "evbsc.h"
static void write_ready(EV_P_ ev_io *w, int revents);
static void read_ready(EV_P_ ev_io *w, int revents);
static void evbsc_after_connect(evbsc *client);
-evbsc *evbsc_new( struct ev_loop *loop, const char *host, const char *port, error_callback_p_t onerror,
+static void buffer_fill_cb(bsc *bsclient)
+{
+ evbsc *client = (evbsc *)bsclient->data;
+ ev_io_start((client)->loop, &((client)->ww));
+}
+
+evbsc *evbsc_new( struct ev_loop *loop, const char *host, const char *port,
+ const char *default_tube, error_callback_p_t onerror,
size_t buf_len, size_t vec_len, size_t vec_min, char **errorstr )
{
evbsc *client = NULL;
bsc *bsclient = NULL;
- if ( ( bsclient = bsc_new(host, port, onerror, buf_len, vec_len, vec_min, errorstr) ) == NULL )
+ if ( ( bsclient = bsc_new(host, port, default_tube, onerror, buf_len, vec_len, vec_min, errorstr) ) == NULL )
return NULL;
if ( ( client = (evbsc *)malloc(sizeof(evbsc)) ) == NULL ) {
bsc_free(bsclient);
return NULL;
}
+ bsclient->buffer_fill_cb = buffer_fill_cb;
bsclient->data = client;
client->loop = loop;
client->bsclient = bsclient;
evbsc_after_connect(client);
+ if (strcmp(default_tube, BSC_DEFAULT_TUBE) != 0)
+ ev_io_start((client)->loop, &((client)->ww));
return client;
}
@@ -63,7 +74,7 @@ static void evbsc_after_connect(evbsc *client)
client->ww.data = client;
ev_io_start(client->loop, &(client->rw));
- if (!IOQ_EMPTY(client->bsclient->outq))
+ if (!AQUEUE_EMPTY(client->bsclient->outq))
ev_io_start(client->loop, &(client->ww));
}
@@ -84,7 +95,7 @@ static void write_ready(EV_P_ ev_io *w, int revents)
{
evbsc *client = (evbsc *)w->data;
bsc_write(client->bsclient);
- if (IOQ_EMPTY(client->bsclient->outq))
+ if (AQUEUE_EMPTY(client->bsclient->outq))
ev_io_stop(loop, &(client->ww));
return;
View
@@ -18,16 +18,11 @@
#include <ev.h>
#include <beanstalkclient.h>
-#define EVBSC_ENQ_CMD(cmd, client, callback, callback_data, on_error, ...) do { \
- BSC_ENQ_CMD(cmd, (client)->bsclient, (callback), (callback_data), on_error, ##__VA_ARGS__); \
- ev_io_start((client)->loop, &((client)->ww)); \
-} while (false)
-
-#define evbsc_new_w_defaults(loop, host, port, onerror, errorstr) \
- ( evbsc_new( (loop), (host), (port), (onerror), \
- BSC_DEFAULT_BUFFER_SIZE, \
- BSC_DEFAULT_VECTOR_SIZE, \
- BSC_DEFAULT_VECTOR_MIN, \
+#define evbsc_new_w_defaults(loop, host, port, def_tube, onerror, errorstr) \
+ ( evbsc_new( (loop), (host), (port), (def_tube), (onerror), \
+ BSC_DEFAULT_BUFFER_SIZE, \
+ BSC_DEFAULT_VECTOR_SIZE, \
+ BSC_DEFAULT_VECTOR_MIN, \
(errorstr) ) )
struct _evbsc {
@@ -39,7 +34,8 @@ struct _evbsc {
typedef struct _evbsc evbsc;
-evbsc *evbsc_new( struct ev_loop *loop, const char *host, const char *port, error_callback_p_t onerror,
+evbsc *evbsc_new( struct ev_loop *loop, const char *host, const char *port,
+ const char *default_tube, error_callback_p_t onerror,
size_t buf_len, size_t vec_len, size_t vec_min, char **errorstr );
void evbsc_free(evbsc *client);
Oops, something went wrong.

0 comments on commit d2eb95d

Please sign in to comment.