r26654: libcli/smb_composite: Rather than specifying each of the gazillion options...
[jelmer/samba4-debian.git] / source / torture / raw / openbench.c
index dcba73dfffc306d5f6fdf9801643b63344847bec..87b27d072837e42cd16e1b22b116adf96bcaf5a9 100644 (file)
@@ -30,6 +30,7 @@
 #include "lib/cmdline/popt_common.h"
 #include "libcli/composite/composite.h"
 #include "libcli/smb_composite/smb_composite.h"
+#include "libcli/resolve/resolve.h"
 #include "param/param.h"
 
 #define BASEDIR "\\benchopen"
@@ -42,6 +43,7 @@ static int num_connected;
 static struct timed_event *report_te;
 
 struct benchopen_state {
+       struct torture_context *tctx;
        TALLOC_CTX *mem_ctx;
        struct event_context *ev;
        struct smbcli_state *cli;
@@ -60,7 +62,7 @@ struct benchopen_state {
        struct timed_event *te;
 
        /* these are used for reconnections */
-       int dest_port;
+       const char **dest_ports;
        const char *dest_host;
        const char *called_name;
        const char *service_type;
@@ -116,26 +118,29 @@ static void reopen_connection(struct event_context *ev, struct timed_event *te,
 
        state->te = NULL;
 
-       if (!torture_get_conn_index(state->client_num, state->mem_ctx, &host, &share)) {
+       if (!torture_get_conn_index(state->client_num, state->mem_ctx, state->tctx, &host, &share)) {
                DEBUG(0,("Can't find host/share for reconnect?!\n"));
                exit(1);
        }
 
        io->in.dest_host    = state->dest_host;
-       io->in.port         = state->dest_port;
+       io->in.dest_ports   = state->dest_ports;
        io->in.called_name  = state->called_name;
        io->in.service      = share;
        io->in.service_type = state->service_type;
        io->in.credentials  = cmdline_credentials;
-       io->in.fallback_to_anonymous = False;
-       io->in.workgroup    = lp_workgroup(global_loadparm);
+       io->in.fallback_to_anonymous = false;
+       io->in.workgroup    = lp_workgroup(state->tctx->lp_ctx);
+       lp_smbcli_options(state->tctx->lp_ctx, &io->in.options);
 
        /* kill off the remnants of the old connection */
        talloc_free(state->tree);
        state->tree = NULL;
        state->fnum = -1;
 
-       ctx = smb_composite_connect_send(io, state->mem_ctx, state->ev);
+       ctx = smb_composite_connect_send(io, state->mem_ctx, 
+                                        lp_resolve_context(state->tctx->lp_ctx), 
+                                        state->ev);
        if (ctx == NULL) {
                DEBUG(0,("Failed to setup async reconnect\n"));
                exit(1);
@@ -338,9 +343,9 @@ static void report_rate(struct event_context *ev, struct timed_event *te,
 /* 
    benchmark open calls
 */
-BOOL torture_bench_open(struct torture_context *torture)
+bool torture_bench_open(struct torture_context *torture)
 {
-       BOOL ret = True;
+       bool ret = true;
        TALLOC_CTX *mem_ctx = talloc_new(torture);
        int i;
        int timelimit = torture_setting_int(torture, "timelimit", 10);
@@ -348,7 +353,7 @@ BOOL torture_bench_open(struct torture_context *torture)
        struct event_context *ev = event_context_find(mem_ctx);
        struct benchopen_state *state;
        int total = 0, minops=0;
-       bool progress=False;
+       bool progress=false;
 
        progress = torture_setting_bool(torture, "progress", true);
        
@@ -358,17 +363,22 @@ BOOL torture_bench_open(struct torture_context *torture)
 
        printf("Opening %d connections\n", nprocs);
        for (i=0;i<nprocs;i++) {
+               state[i].tctx = torture;
                state[i].mem_ctx = talloc_new(state);
                state[i].client_num = i;
                state[i].ev = ev;
-               if (!torture_open_connection_ev(&state[i].cli, i, ev)) {
-                       return False;
+               if (!torture_open_connection_ev(&state[i].cli, i, torture, ev)) {
+                       return false;
                }
                talloc_steal(mem_ctx, state);
                state[i].tree = state[i].cli->tree;
                state[i].dest_host = talloc_strdup(state[i].mem_ctx, 
                                                   state[i].cli->tree->session->transport->socket->hostname);
-               state[i].dest_port = state[i].cli->tree->session->transport->socket->port;
+               state[i].dest_ports = talloc_array(state[i].mem_ctx, 
+                                                  const char *, 2);
+               state[i].dest_ports[0] = talloc_asprintf(state[i].dest_ports, 
+                                                        "%u", state[i].cli->tree->session->transport->socket->port);
+               state[i].dest_ports[1] = NULL;
                state[i].called_name  = talloc_strdup(state[i].mem_ctx,
                                                      state[i].cli->tree->session->transport->called.name);
                state[i].service_type = talloc_strdup(state[i].mem_ctx,
@@ -438,5 +448,5 @@ BOOL torture_bench_open(struct torture_context *torture)
 
 failed:
        talloc_free(mem_ctx);
-       return False;
+       return false;
 }