r145: * Improve error handling
authoryoe <yoe>
Tue, 31 Jan 2006 09:58:41 +0000 (09:58 +0000)
committeryoe <yoe>
Tue, 31 Jan 2006 09:58:41 +0000 (09:58 +0000)
* Fix htonl call to say htonll instead (lesson: test network-using software on
  at least one little endian architecture :-)

Makefile.am
nbd-tester-client.c

index b869c69..1c5a8a3 100644 (file)
@@ -1,9 +1,12 @@
 bin_PROGRAMS = nbd-server
 EXTRA_PROGRAMS = nbd-client
+noinst_PROGRAMS = nbd-tester-client
 nbd_client_SOURCES = nbd-client.c cliserv.h
 nbd_server_SOURCES = nbd-server.c cliserv.h
+nbd_tester_client_SOURCES = nbd-tester-client.c cliserv.h
 nbd_server_CFLAGS = @CFLAGS@ @GLIB_CFLAGS@
-nbd_server_LDADD = @GLIB_LIBS@
+nbd_tester_client_CFLAGS = @CFLAGS@ @GLIB_CFLAGS@
+nbd_tester_client_LDADD = @GLIB_LIBS@
 man_MANS = nbd-server.1 nbd-client.8
 EXTRA_DIST = nbd-client.8.sgml nbd-server.1.sgml gznbd winnbd lfs.h nbd-client.8 nbd-server.1
 MAINTAINERCLEANFILES = nbd-client.8 nbd-server.1
index 719c439..9cc3aca 100644 (file)
@@ -52,6 +52,8 @@ typedef enum {
 
 inline int read_all(int f, void *buf, size_t len) {
        ssize_t res;
+       int retval=0;
+
        while(len>0) {
                if((res=read(f, buf, len)) <=0) {
                        snprintf(errstr, errstr_len, "Read failed: %s", strerror(errno));
@@ -59,7 +61,9 @@ inline int read_all(int f, void *buf, size_t len) {
                }
                len-=res;
                buf+=res;
+               retval+=res;
        }
+       return retval;
 }
 
 int setup_connection(gchar *hostname, int port, CONNECTION_TYPE ctype) {
@@ -216,12 +220,12 @@ int throughput_test(gchar* hostname, int port, int sock, char sock_is_open, char
                snprintf(errstr, errstr_len, "Could not read from socket: %s", strerror(errno));
                goto err_open;
        }
-       read_all(sock,&buf,128);
        if(tmp==0) {
                retval=-1;
                snprintf(errstr, errstr_len, "Server closed connection unexpectedly when trying to read size of device in throughput test");
                goto err;
        }
+       read_all(sock,&buf,128);
        size=ntohll(size);
        req.magic=htonl(NBD_REQUEST_MAGIC);
        req.type=htonl(NBD_CMD_READ);
@@ -229,7 +233,7 @@ int throughput_test(gchar* hostname, int port, int sock, char sock_is_open, char
        for(i=0;i+1024<=size;i+=1024) {
                if(do_write) {
                        *((u64*)req.handle)=i;
-                       req.from=htonl(i);
+                       req.from=htonll(i);
                        write(sock, &req, sizeof(req));
                        printf("Requests(+): %d\n", ++requests);
                }
@@ -242,7 +246,10 @@ int throughput_test(gchar* hostname, int port, int sock, char sock_is_open, char
                        if(FD_ISSET(sock, &set)) {
                                /* Okay, there's something ready for
                                 * reading here */
-                               read_packet_check_header(sock, 1024, i);
+                               if(read_packet_check_header(sock, 1024, i)<0) {
+                                       retval=-1;
+                                       goto err_open;
+                               }
                                printf("Requests(-): %d\n", --requests);
                        }
                } while FD_ISSET(sock, &set);