]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MAJOR] switched buffers to mempools v2
authorWilly Tarreau <w@1wt.eu>
Sun, 13 May 2007 17:56:02 +0000 (19:56 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 13 May 2007 17:56:02 +0000 (19:56 +0200)
include/proto/buffers.h
include/types/buffers.h
src/buffers.c
src/client.c
src/haproxy.c
src/session.c

index 6c3996218956dd8ce2bda39dc8fa25b47411ff28..74efe8fdf63c5901c55525f1bd2de9782f8e4ef2 100644 (file)
 #ifndef _PROTO_BUFFERS_H
 #define _PROTO_BUFFERS_H
 
+#include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include <common/config.h>
+#include <common/memory.h>
 #include <types/buffers.h>
 
+extern struct pool_head *pool2_buffer;
+
+/* perform minimal intializations, report 0 in case of error, 1 if OK. */
+int init_buffer();
+
 /* Initializes all fields in the buffer. The ->rlim field is initialized last
  * so that the compiler can optimize it away if changed immediately after the
  * call to this function.
index 9b781b8421a6a69965e3fc3d6c6d27f816341391..09d1e34199bb008345b3d52bf2a3d690f30ca142 100644 (file)
@@ -73,9 +73,6 @@ struct buffer {
        char data[BUFSIZE];
 };
 
-#define sizeof_buffer   sizeof(struct buffer)
-extern void **pool_buffer;
-
 
 #endif /* _TYPES_BUFFERS_H */
 
index 5739fcf52412e76b3cef59a1c29d50fb77ed36d7..658539c3ada5dd184e91d1552c2e305e63c29683 100644 (file)
 #include <string.h>
 
 #include <common/config.h>
+#include <common/memory.h>
 #include <proto/buffers.h>
 
-void **pool_buffer   = NULL;
+struct pool_head *pool2_buffer;
+
+
+/* perform minimal intializations, report 0 in case of error, 1 if OK. */
+int init_buffer()
+{
+       pool2_buffer = create_pool("buffer", sizeof(struct buffer), MEM_F_SHARED);
+       return pool2_buffer != NULL;
+}
+
 
 /* writes <len> bytes from message <msg> to buffer <buf>. Returns 0 in case of
  * success, or the number of bytes available otherwise.
index 6afb20636590c6079f683d84d35c37469ced33b4..6a1a3dfb6556e9a08cb4e368e20a50b7222945d9 100644 (file)
@@ -347,7 +347,7 @@ int event_accept(int fd) {
                        write(1, trash, len);
                }
 
-               if ((s->req = pool_alloc(buffer)) == NULL) { /* no memory */
+               if ((s->req = pool_alloc2(pool2_buffer)) == NULL) { /* no memory */
                        if (txn->hdr_idx.v != NULL)
                                pool_free_to(p->hdr_idx_pool, txn->hdr_idx.v);
                        if (txn->rsp.cap != NULL)
@@ -369,8 +369,8 @@ int event_accept(int fd) {
                s->req->wto = s->be->srvtimeout;
                s->req->cto = s->be->srvtimeout;
 
-               if ((s->rep = pool_alloc(buffer)) == NULL) { /* no memory */
-                       pool_free(buffer, s->req);
+               if ((s->rep = pool_alloc2(pool2_buffer)) == NULL) { /* no memory */
+                       pool_free2(pool2_buffer, s->req);
                        if (txn->hdr_idx.v != NULL)
                                pool_free_to(p->hdr_idx_pool, txn->hdr_idx.v);
                        if (txn->rsp.cap != NULL)
index 18bef851473c9a4eb2715f0a37dc0622454a5729..59c61497891e81f48e646020c079cc4f307b9171 100644 (file)
@@ -374,6 +374,7 @@ void init(int argc, char **argv)
        localtime((time_t *)&now.tv_sec);
        start_date = now;
 
+       init_buffer();
        init_task();
        init_session();
        init_proto_http();
@@ -661,7 +662,7 @@ void deinit(void)
        if (fdtab)            free(fdtab);
     
        pool_destroy2(pool2_session);
-       pool_destroy(pool_buffer);
+       pool_destroy2(pool2_buffer);
        pool_destroy(pool_requri);
        pool_destroy2(pool2_task);
        pool_destroy(pool_capture);
index 63bede3ee5079b3861ac5448bf3ea26c88995027..1b574a00bb9c50c5a2c4af9b0864ff927250f794 100644 (file)
@@ -21,6 +21,7 @@
 #include <types/proxy.h>
 #include <types/server.h>
 
+#include <proto/buffers.h>
 #include <proto/hdr_idx.h>
 #include <proto/session.h>
 #include <proto/queue.h>
@@ -38,9 +39,9 @@ void session_free(struct session *s)
        if (s->pend_pos)
                pendconn_free(s->pend_pos);
        if (s->req)
-               pool_free(buffer, s->req);
+               pool_free2(pool2_buffer, s->req);
        if (s->rep)
-               pool_free(buffer, s->rep);
+               pool_free2(pool2_buffer, s->rep);
 
        if (txn->hdr_idx.v != NULL)
                pool_free_to(s->fe->hdr_idx_pool, txn->hdr_idx.v);