knetfile.c
authorHenry Amrhein <hamrhein@caltech.edu>
Thu, 3 Jan 2013 06:37:30 +0000 (22:37 -0800)
committerHenry Amrhein <hamrhein@caltech.edu>
Thu, 3 Jan 2013 06:37:30 +0000 (22:37 -0800)
wrapped netwrite() calls with error-checking

knetfile.c

index af091465862c238aefeb3d0562b03f75320b6c1d..d3e628371270fffe07f44de0af31e30c7479a959 100644 (file)
@@ -233,7 +233,10 @@ static int kftp_get_response(knetFile *ftp)
 static int kftp_send_cmd(knetFile *ftp, const char *cmd, int is_get)
 {
        if (socket_wait(ftp->ctrl_fd, 0) <= 0) return -1; // socket is not ready for writing
-       netwrite(ftp->ctrl_fd, cmd, strlen(cmd));
+       if (netwrite(ftp->ctrl_fd, cmd, strlen(cmd)) < 0) {
+               fprintf(stderr, "[%s] error sending command to socket.\n", __func__);
+               return -1;
+       }
        return is_get? kftp_get_response(ftp) : 0;
 }
 
@@ -412,7 +415,10 @@ int khttp_connect_file(knetFile *fp)
        l += sprintf(buf + l, "GET %s HTTP/1.0\r\nHost: %s\r\n", fp->path, fp->http_host);
     l += sprintf(buf + l, "Range: bytes=%lld-\r\n", (long long)fp->offset);
        l += sprintf(buf + l, "\r\n");
-       netwrite(fp->fd, buf, l);
+       if (netwrite(fp->fd, buf, l) < 0) {
+               fprintf(stderr, "[%s] fail write GET line.\n", __func__);
+               return -1;
+       }
        l = 0;
        while (netread(fp->fd, buf + l, 1)) { // read HTTP header; FIXME: bad efficiency
                if (buf[l] == '\n' && l >= 3)