From a5c6d992b0d637be2ab310cb132023b272781b82 Mon Sep 17 00:00:00 2001 From: yoe Date: Mon, 30 Jan 2006 22:15:44 +0000 Subject: [PATCH] r144: Add test client --- nbd-tester-client.c | 312 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 312 insertions(+) create mode 100644 nbd-tester-client.c diff --git a/nbd-tester-client.c b/nbd-tester-client.c new file mode 100644 index 0000000..719c439 --- /dev/null +++ b/nbd-tester-client.c @@ -0,0 +1,312 @@ +/* + * Test client to test the NBD server. Doesn't do anything useful, except + * checking that the server does, actually, work. + * + * Note that the only 'real' test is to check the client against a kernel. If + * it works here but does not work in the kernel, then that's most likely a bug + * in this program and/or in nbd-server. + * + * Copyright(c) 2006 Wouter Verhelst + * + * This program is Free Software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, in version 2. + * + * This program 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "lfs.h" +#define MY_NAME "nbd-tester-client" +#include "cliserv.h" + +static gchar errstr[1024]; +const static int errstr_len=1024; + +typedef enum { + CONNECTION_TYPE_NONE, + CONNECTION_TYPE_CONNECT, + CONNECTION_TYPE_INIT_PASSWD, + CONNECTION_TYPE_CLISERV, + CONNECTION_TYPE_FULL, +} CONNECTION_TYPE; + +typedef enum { + CONNECTION_CLOSE_PROPERLY, + CONNECTION_CLOSE_FAST, +} CLOSE_TYPE; + +inline int read_all(int f, void *buf, size_t len) { + ssize_t res; + while(len>0) { + if((res=read(f, buf, len)) <=0) { + snprintf(errstr, errstr_len, "Read failed: %s", strerror(errno)); + return -1; + } + len-=res; + buf+=res; + } +} + +int setup_connection(gchar *hostname, int port, CONNECTION_TYPE ctype) { + int sock; + struct hostent *host; + struct sockaddr_in addr; + char buf[256]; + u64 tmp64; + + sock=0; + if(ctypeh_addr); + if((connect(sock, (struct sockaddr *)&addr, sizeof(addr))<0)) { + strncpy(errstr, strerror(errno), errstr_len); + goto err_open; + } + if(ctype ", argv[0]); + exit(EXIT_FAILURE); + } + logging(); + hostname=g_strdup(argv[1]); + p=(strtol(argv[2], NULL, 0)); + if(p==LONG_MIN||p==LONG_MAX) { + g_critical("Could not parse port number: %s", strerror(errno)); + exit(EXIT_FAILURE); + } + port=(int)p; + + if(throughput_test(hostname, port, sock, FALSE, TRUE)<0) { + g_warning("Could not run throughput test: %s", errstr); + exit(EXIT_FAILURE); + } + + return 0; +} -- 1.7.10.4