]> granicus.if.org Git - pgbouncer/commitdiff
Remove concept of 'flushing' from code as bouncer does not actively buffer anything.
authorMarko Kreen <markokr@gmail.com>
Thu, 19 Apr 2007 14:03:55 +0000 (14:03 +0000)
committerMarko Kreen <markokr@gmail.com>
Thu, 19 Apr 2007 14:03:55 +0000 (14:03 +0000)
The flushing logic was remnant from the time when buffering was
pushed to kernel with MSG_MORE.  Now it only complicates code.

src/bouncer.h
src/client.c
src/objects.c
src/sbuf.c
src/sbuf.h
src/server.c
test/asynctest.c

index f1fc7423a9c7420b3701b896920095354cce069b..f81598a755422aaa6e18b50e25df817f38795e42 100644 (file)
@@ -208,7 +208,6 @@ struct PgSocket {
 
        unsigned        wait_for_welcome:1;     /* no server yet in pool */
        unsigned        ready:1;                /* server accepts new query */
-       unsigned        flush_req:1;            /* client requested flush */
        unsigned        admin_user:1;
        unsigned        own_user:1;             /* is console client with same uid */
 
@@ -217,7 +216,7 @@ struct PgSocket {
 
        /* admin conn, waits for completion of PAUSE/SUSPEND cmd */
        unsigned        wait_for_response:1;
-       /* this (server0 socket must be closed ASAP */
+       /* this (server) socket must be closed ASAP */
        unsigned        close_needed:1;
 
        usec_t          connect_time;   /* when connection was made */
index 3e72d1b2b645b77edefbc0a08c6d7dd60bca9776..8b35e85810c45c090063948d63000be6b691d97e 100644 (file)
@@ -271,7 +271,6 @@ static bool handle_client_work(PgSocket *client, MBuf *pkt)
 {
        unsigned pkt_type;
        unsigned pkt_len;
-       bool flush = 0;
        SBuf *sbuf = &client->sbuf;
 
        if (!get_header(pkt, &pkt_type, &pkt_len)) {
@@ -284,9 +283,7 @@ static bool handle_client_work(PgSocket *client, MBuf *pkt)
 
        /* request immidiate response from server */
        case 'H':               /* Flush */
-               client->flush_req = 1;
        case 'S':               /* Sync */
-               /* sync is followed by ReadyForQuery */
 
        /* one-packet queries */
        case 'Q':               /* Query */
@@ -296,9 +293,6 @@ static bool handle_client_work(PgSocket *client, MBuf *pkt)
        case 'c':               /* CopyDone(F/B) */
        case 'f':               /* CopyFail(F/B) */
 
-               /* above packets should be sent ASAP */
-               flush = 1;
-
        /*
         * extended protocol allows server (and thus pooler)
         * to buffer packets until sync or flush is sent by client
@@ -329,7 +323,7 @@ static bool handle_client_work(PgSocket *client, MBuf *pkt)
                client->link->ready = 0;
 
                /* forward the packet */
-               sbuf_prepare_send(sbuf, &client->link->sbuf, pkt_len, flush);
+               sbuf_prepare_send(sbuf, &client->link->sbuf, pkt_len);
                break;
 
        /* client wants to go away */
index c371a13052437df9d43efee85f65cb34374bbc2f..dec7621a829b33f8cc8edf89cb75678b6f6f9224 100644 (file)
@@ -81,7 +81,6 @@ static void clean_socket(PgSocket *sk)
 
        sk->wait_for_welcome = 0;
        sk->ready = 0;
-       sk->flush_req = 0;
        sk->admin_user = 0;
        sk->own_user = 0;
        sk->suspended = 0;
index c34c338a11f0a2c754c59261269d09e365a1f8c3..1e10be6bca1490d405b563ab744cf4a00f5f0fc6 100644 (file)
@@ -213,22 +213,20 @@ void sbuf_close(SBuf *sbuf)
        sbuf->dst = NULL;
        sbuf->sock = 0;
        sbuf->pkt_pos = sbuf->pkt_remain = sbuf->recv_pos = 0;
-       sbuf->pkt_skip = sbuf->wait_send = sbuf->pkt_flush = 0;
+       sbuf->pkt_skip = sbuf->wait_send = 0;
        sbuf->send_pos = sbuf->send_remain = 0;
 }
 
 /* proto_fn tells to send some bytes to socket */
-void sbuf_prepare_send(SBuf *sbuf, SBuf *dst, int amount, bool flush)
+void sbuf_prepare_send(SBuf *sbuf, SBuf *dst, int amount)
 {
        AssertActive(sbuf);
        Assert(sbuf->pkt_remain == 0);
        Assert(sbuf->pkt_skip == 0 || sbuf->send_remain == 0);
-       Assert(!sbuf->pkt_flush || sbuf->send_remain == 0);
        Assert(amount > 0);
 
        sbuf->pkt_skip = 0;
        sbuf->pkt_remain = amount;
-       sbuf->pkt_flush = flush;
        sbuf->dst = dst;
 }
 
@@ -238,12 +236,10 @@ void sbuf_prepare_skip(SBuf *sbuf, int amount)
        AssertActive(sbuf);
        Assert(sbuf->pkt_remain == 0);
        Assert(sbuf->pkt_skip == 0 || sbuf->send_remain == 0);
-       Assert(!sbuf->pkt_flush || sbuf->send_remain == 0);
        Assert(amount > 0);
 
        sbuf->pkt_skip = 1;
        sbuf->pkt_remain = amount;
-       sbuf->pkt_flush = 0;
        sbuf->dst = NULL;
 }
 
@@ -298,6 +294,7 @@ static void sbuf_send_cb(int sock, short flags, void *arg)
                return;
 
        AssertSanity(sbuf);
+       Assert(sbuf->wait_send);
 
        /* prepare normal situation for sbuf_main_loop */
        sbuf->wait_send = 0;
@@ -401,12 +398,8 @@ static bool sbuf_process_pending(SBuf *sbuf)
 
                /*
                 * If start of packet, process packet header.
-                *
-                * Dont append anything to flush packets, send them first.
                 */
-               if (sbuf->pkt_remain == 0 && !sbuf->pkt_flush) {
-                       /* if flush then send it before looking */
-
+               if (sbuf->pkt_remain == 0) {
                        res = sbuf_call_proto(sbuf, SBUF_EV_READ);
                        if (!res)
                                return false;
@@ -425,7 +418,7 @@ static bool sbuf_process_pending(SBuf *sbuf)
                sbuf->pkt_pos += avail;
 
                /* send data */
-               if (sbuf->pkt_skip || sbuf->pkt_flush) {
+               if (sbuf->pkt_skip) {
                        res = sbuf_send_pending(sbuf);
                        if (!res)
                                return false;
@@ -529,9 +522,11 @@ try_more:
         * but with skip_recv switch its should not be needed anymore.
         */
        free = cf_sbuf_len - sbuf->recv_pos;
-       ok = sbuf_actual_recv(sbuf, free);
-       if (!ok)
-               return;
+       if (free > 0) {
+               ok = sbuf_actual_recv(sbuf, free);
+               if (!ok)
+                       return;
+       }
 
 skip_recv:
        /* now handle it */
index ea731ce27a61ea04b1fa633274e9c893db84b770..4f8265150f4e807461f46d48853466e973c0a2fa 100644 (file)
@@ -54,14 +54,14 @@ struct SBuf {
 
        int recv_pos;
        int pkt_pos;
-       int pkt_remain;
        int send_pos;
-       int send_remain;
 
-       unsigned wait_send:1;
-       unsigned pkt_skip:1;
-       unsigned pkt_flush:1;
-       unsigned is_unix:1;
+       int pkt_remain;         /* total packet length remaining */
+       int send_remain;        /* total data to be sent remaining */
+
+       unsigned pkt_skip:1;    /* if current packet should be skipped */
+       unsigned is_unix:1;     /* is it unix socket */
+       unsigned wait_send:1;   /* debug var, otherwise useless */
 
        uint8 buf[0];
 };
@@ -77,7 +77,7 @@ void sbuf_continue(SBuf *sbuf);
 void sbuf_close(SBuf *sbuf);
 
 /* proto_fn can use those functions to order behaviour */
-void sbuf_prepare_send(SBuf *sbuf, SBuf *dst, int amount, bool flush);
+void sbuf_prepare_send(SBuf *sbuf, SBuf *dst, int amount);
 void sbuf_prepare_skip(SBuf *sbuf, int amount);
 
 bool sbuf_answer(SBuf *sbuf, const void *buf, int len);
index ec3d76ea8e1d50a39be28b02bb35bdf757451a0d..f3dc0426be435f13d27d4b61387bc3165e09ac48 100644 (file)
@@ -100,7 +100,6 @@ static bool handle_server_work(PgSocket *server, MBuf *pkt)
 {
        unsigned pkt_type;
        unsigned pkt_len;
-       bool flush = 0;
        bool ready = 0;
        char state;
        SBuf *sbuf = &server->sbuf;
@@ -137,9 +136,6 @@ static bool handle_server_work(PgSocket *server, MBuf *pkt)
                        return false;
                }
 
-               /* above packers need to be sent immidiately */
-               flush = 1;
-
        /*
         * 'E' and 'N' packets currently set ->ready to 0.  Correct would
         * be to leave ->ready as-is, because overal TX state stays same.
@@ -172,12 +168,6 @@ static bool handle_server_work(PgSocket *server, MBuf *pkt)
        case 's':               /* PortalSuspended */
        case 'C':               /* CommandComplete */
 
-               /* check if client wanted immidiate response */
-               if (client && client->flush_req) {
-                       flush = 1;
-                       client->flush_req = 0;
-               }
-
        /* data packets, there will be more coming */
        case 'd':               /* CopyData(F/B) */
        case 'D':               /* DataRow */
@@ -186,7 +176,7 @@ static bool handle_server_work(PgSocket *server, MBuf *pkt)
        case 'T':               /* RowDescription */
 
                if (client) {
-                       sbuf_prepare_send(sbuf, &client->sbuf, pkt_len, flush);
+                       sbuf_prepare_send(sbuf, &client->sbuf, pkt_len);
                } else {
                        if (server->state != SV_TESTED)
                                log_warning("got packet '%c' from server"
index dadfc7ec267ee8f29d968511e6a72f6c5603cdd2..0d9d13ccc1c8e71328e0a72183f8ee88979633dc 100644 (file)
@@ -41,7 +41,7 @@ typedef struct DbConn {
 } DbConn;
 
 static char *bulk_data;
-static int bulk_data_max = 128*1024;  /* power of 2 */
+static int bulk_data_max = 16*1024;  /* power of 2 */
 
 /* fill mem with random junk */
 static void init_bulk_data(void)