/*
- include/types/global.h
- Global variables.
-
- Copyright (C) 2000-2007 Willy Tarreau - w@1wt.eu
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation, version 2.1
- exclusively.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ * include/types/global.h
+ * Global variables.
+ *
+ * Copyright (C) 2000-2010 Willy Tarreau - w@1wt.eu
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, version 2.1
+ * exclusively.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
#ifndef _TYPES_GLOBAL_H
#define _TYPES_GLOBAL_H
extern int actconn; /* # of active sessions */
extern int listeners;
extern char trash[BUFSIZE];
+extern char *swap_buffer;
extern const int zero;
extern const int one;
extern const struct linger nolinger;
/* this is used to drain data, and as a temporary buffer for sprintf()... */
char trash[BUFSIZE];
+/* this buffer is always the same size as standard buffers and is used for
+ * swapping data inside a buffer.
+ */
+char *swap_buffer = NULL;
+
const int zero = 0;
const int one = 1;
const struct linger nolinger = { .l_onoff = 1, .l_linger = 0 };
if (global.nbproc < 1)
global.nbproc = 1;
+ swap_buffer = (char *)calloc(1, global.tune.bufsize);
+
fdinfo = (struct fdinfo *)calloc(1,
sizeof(struct fdinfo) * (global.maxsock));
fdtab = (struct fdtab *)calloc(1,
/* two possible cases :
* - the buffer is in one contiguous block, we move it in-place
- * - the buffer is in two blocks, we move it via the trash
+ * - the buffer is in two blocks, we move it via the swap_buffer
*/
if (buf->l) {
- if (buf->r <= buf->w)
+ int block1 = buf->l;
+ int block2 = 0;
+ if (buf->r <= buf->w) {
/* non-contiguous block */
- buffer_bounce_realign(buf);
- else
- memmove(buf->data, buf->w, buf->l);
+ block1 = buf->data + buf->size - buf->w;
+ block2 = buf->r - buf->data;
+ }
+ if (block2)
+ memcpy(swap_buffer, buf->data, block2);
+ memmove(buf->data, buf->w, block1);
+ if (block2)
+ memcpy(buf->data + block1, swap_buffer, block2);
}
/* adjust all known pointers */