Commit bbff727d authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Merge from VTEST:

    Author: Frédéric Lécaille <flecaille@haproxy.com>
    Date:   Mon Jul 15 15:20:07 2019 +0200

    Open and close a TCP socket to simulate an unreachable server.

    This is done for each haproxy instance. The socket address (resp. port)
    may be referenced by ${<name>_closed_addr} (resp. ${<name>_closed_port})
    variable where <name> is the haproxy instance name.
parent 222fd882
......@@ -89,6 +89,7 @@ struct haproxy {
char *workdir;
struct vsb *msgs;
char closed_sock[256]; /* Closed TCP socket */
VTAILQ_HEAD(,envar) envars;
};
......@@ -494,6 +495,9 @@ haproxy_new(const char *name)
struct haproxy *h;
struct vsb *vsb;
char buf[PATH_MAX];
int closed_sock;
char addr[128], port[128];
const char *err;
ALLOC_OBJ(h, HAPROXY_MAGIC);
AN(h);
......@@ -523,6 +527,21 @@ haproxy_new(const char *name)
h->cfg_fn = strdup(buf);
AN(h->cfg_fn);
/* Create a new TCP socket to reserve an IP:port and close it asap.
* May be useful to simulate an unreachable server.
*/
bprintf(h->closed_sock, "%s_closed", h->name);
closed_sock = VTCP_listen_on("localhost:0", NULL, 100, &err);
if (err != NULL)
vtc_fatal(h->vl,
"Create listen socket failed: %s", err);
assert(closed_sock > 0);
VTCP_myname(closed_sock, addr, sizeof addr, port, sizeof port);
macro_def(h->vl, h->closed_sock, "sock", "%s %s", addr, port);
macro_def(h->vl, h->closed_sock, "addr", "%s", addr);
macro_def(h->vl, h->closed_sock, "port", "%s", port);
VTCP_close(&closed_sock);
h->cli = haproxy_cli_new(h);
AN(h->cli);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment