From: Marko Kreen Date: Tue, 8 Jul 2008 20:01:56 +0000 (+0000) Subject: remove extra argument for SBuf callback X-Git-Tag: pgbouncer_1_2_rc2~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=41de9a4758cb33bf878d7f4102a3a120c0cf5703;p=pgbouncer remove extra argument for SBuf callback conserves memory and conforms more with general coding style. plus few cleanups --- diff --git a/include/client.h b/include/client.h index 5477a7f..91b4bdf 100644 --- a/include/client.h +++ b/include/client.h @@ -16,7 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -bool client_proto(SBuf *sbuf, SBufEvent evtype, MBuf *pkt, void *arg) _MUSTCHECK; +bool client_proto(SBuf *sbuf, SBufEvent evtype, MBuf *pkt) _MUSTCHECK; bool set_pool(PgSocket *client, const char *dbname, const char *username) _MUSTCHECK; diff --git a/include/sbuf.h b/include/sbuf.h index e3482d1..02565e0 100644 --- a/include/sbuf.h +++ b/include/sbuf.h @@ -47,8 +47,7 @@ typedef struct SBuf SBuf; next event loop (eg. too few data available). */ typedef bool (*sbuf_cb_t)(SBuf *sbuf, SBufEvent evtype, - MBuf *mbuf, - void *arg); + MBuf *mbuf); /* for some reason, libevent has no typedef for callback */ typedef void (*sbuf_libevent_cb)(int, short, void *); @@ -68,19 +67,18 @@ struct SBuf { int sock; /* fd for this socket */ - unsigned pkt_remain; /* total packet length remaining */ + unsigned pkt_remain; /* total packet length remaining */ sbuf_cb_t proto_cb; /* protocol callback */ - void *proto_cb_arg; /* extra arg to callback */ SBuf *dst; /* target SBuf for current packet */ - IOBuf *io; + IOBuf *io; /* data buffer, lazily allocated */ }; #define sbuf_socket(sbuf) ((sbuf)->sock) -void sbuf_init(SBuf *sbuf, sbuf_cb_t proto_fn, void *arg); +void sbuf_init(SBuf *sbuf, sbuf_cb_t proto_fn); bool sbuf_accept(SBuf *sbuf, int read_sock, bool is_unix) _MUSTCHECK; bool sbuf_connect(SBuf *sbuf, const PgAddr *addr, const char *unix_dir, int timeout_sec) _MUSTCHECK; diff --git a/include/server.h b/include/server.h index 8df244b..614e841 100644 --- a/include/server.h +++ b/include/server.h @@ -16,5 +16,5 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -bool server_proto(SBuf *sbuf, SBufEvent evtype, MBuf *pkt, void *arg) _MUSTCHECK; +bool server_proto(SBuf *sbuf, SBufEvent evtype, MBuf *pkt) _MUSTCHECK; diff --git a/src/client.c b/src/client.c index 2845852..4b8af73 100644 --- a/src/client.c +++ b/src/client.c @@ -336,10 +336,10 @@ static bool handle_client_work(PgSocket *client, PktHdr *pkt) } /* callback from SBuf */ -bool client_proto(SBuf *sbuf, SBufEvent evtype, MBuf *data, void *arg) +bool client_proto(SBuf *sbuf, SBufEvent evtype, MBuf *data) { bool res = false; - PgSocket *client = arg; + PgSocket *client = container_of(sbuf, PgSocket, sbuf); PktHdr pkt; diff --git a/src/objects.c b/src/objects.c index f439571..1b8c201 100644 --- a/src/objects.c +++ b/src/objects.c @@ -69,7 +69,7 @@ static void construct_client(void *obj) memset(client, 0, sizeof(PgSocket)); list_init(&client->head); - sbuf_init(&client->sbuf, client_proto, client); + sbuf_init(&client->sbuf, client_proto); client->state = CL_FREE; } @@ -79,7 +79,7 @@ static void construct_server(void *obj) memset(server, 0, sizeof(PgSocket)); list_init(&server->head); - sbuf_init(&server->sbuf, server_proto, server); + sbuf_init(&server->sbuf, server_proto); server->state = SV_FREE; } diff --git a/src/sbuf.c b/src/sbuf.c index c76ecb8..02146ad 100644 --- a/src/sbuf.c +++ b/src/sbuf.c @@ -66,10 +66,9 @@ static inline IOBuf *get_iobuf(SBuf *sbuf) { return sbuf->io; } *********************************/ /* initialize SBuf with proto handler */ -void sbuf_init(SBuf *sbuf, sbuf_cb_t proto_fn, void *arg) +void sbuf_init(SBuf *sbuf, sbuf_cb_t proto_fn) { memset(sbuf, 0, sizeof(SBuf)); - sbuf->proto_cb_arg = arg; sbuf->proto_cb = proto_fn; } @@ -227,7 +226,7 @@ bool sbuf_continue_with_callback(SBuf *sbuf, sbuf_libevent_cb user_cb) AssertActive(sbuf); event_set(&sbuf->ev, sbuf->sock, EV_READ | EV_PERSIST, - user_cb, sbuf->proto_cb_arg); + user_cb, sbuf); err = event_add(&sbuf->ev, NULL); if (err < 0) { @@ -328,7 +327,7 @@ static bool sbuf_call_proto(SBuf *sbuf, int event) else memset(&mbuf, 0, sizeof(mbuf)); - res = sbuf->proto_cb(sbuf, event, &mbuf, sbuf->proto_cb_arg); + res = sbuf->proto_cb(sbuf, event, &mbuf); AssertSanity(sbuf); Assert(event != SBUF_EV_READ || !res || sbuf->sock > 0); diff --git a/src/server.c b/src/server.c index 314f2cd..3efc054 100644 --- a/src/server.c +++ b/src/server.c @@ -320,10 +320,10 @@ static bool handle_connect(PgSocket *server) } /* callback from SBuf */ -bool server_proto(SBuf *sbuf, SBufEvent evtype, MBuf *data, void *arg) +bool server_proto(SBuf *sbuf, SBufEvent evtype, MBuf *data) { bool res = false; - PgSocket *server = arg; + PgSocket *server = container_of(sbuf, PgSocket, sbuf); PgPool *pool = server->pool; PktHdr pkt; diff --git a/src/takeover.c b/src/takeover.c index fe74c64..91aad72 100644 --- a/src/takeover.c +++ b/src/takeover.c @@ -265,7 +265,7 @@ static void takeover_parse_data(PgSocket *bouncer, */ static void takeover_recv_cb(int sock, short flags, void *arg) { - PgSocket *bouncer = arg; + PgSocket *bouncer = container_of(arg, PgSocket, sbuf); uint8_t data_buf[2048]; uint8_t cnt_buf[128]; struct msghdr msg;