-
- CtdlLogPrintf(CTDL_DEBUG, "For this download we are expecting %d bytes\n", download_len);
- while (bytes_received < download_len) {
- /*
- * If shutting down we can exit here and unlink the temp file.
- * this shouldn't loose us any messages.
- */
- if (CtdlThreadCheckStop())
- {
- fclose(fp);
- unlink(tempfilename);
- return;
- }
- snprintf(buf, sizeof buf, "READ %ld|%ld",
- bytes_received,
- ((download_len - bytes_received > IGNET_PACKET_SIZE)
- ? IGNET_PACKET_SIZE : (download_len - bytes_received)));
-
- if (sock_puts(sock, buf) < 0) {
- fclose(fp);
- unlink(tempfilename);
- return;
- }
- if (sock_getln(sock, buf, sizeof buf) < 0) {
+ snprintf(buf, sizeof buf, "READ %d|%d",
+ bytes_received,
+ ((download_len - bytes_received > IGNET_PACKET_SIZE)
+ ? IGNET_PACKET_SIZE : (download_len - bytes_received))
+ );
+
+ if (sock_puts(sock, buf) < 0) {
+ fclose(fp);
+ unlink(tempfilename);
+ return;
+ }
+ if (sock_getln(sock, buf, sizeof buf) < 0) {
+ fclose(fp);
+ unlink(tempfilename);
+ return;
+ }
+
+ if (buf[0] == '6') {
+ plen = extract_int(&buf[4], 0);
+ StrBuf *pbuf = NewStrBuf();
+ if (socket_read_blob(sock, pbuf, plen, CLIENT_TIMEOUT) != plen) {
+ CtdlLogPrintf(CTDL_INFO, "Short read from peer; aborting.\n");