int do_file(int fd, char *filename) { FILE *f; char lg[10], lbuf[1024], tmpbuf[522]; int bytes, len, totalbytes; if ((f = fopen(filename, "r")) == NULL) return 0; buildrespmodfile(f, lbuf); if (icap_write(fd, lbuf, strlen(lbuf)) < 0) return 0; printf("Sending file:\n"); totalbytes = 0; while ((len = fread(lbuf, sizeof(char), 512, f)) > 0) { totalbytes += len; bytes = sprintf(lg, "%X\r\n", len); icap_write(fd, lg, bytes); icap_write(fd, lbuf, len); icap_write(fd, "\r\n", 2); // printf("Sending chunksize :%d\n",len); } icap_write(fd, "0\r\n\r\n", 5); fclose(f); printf("Done(%d bytes). Reading responce.....\n", totalbytes); totalbytes = readallresponce(fd); printf("Done(%d bytes).\n", totalbytes); }
int do_file(int fd, char *filename){ FILE *f; char lg[10],lbuf[512],tmpbuf[522]; int bytes,len,totalbytesout,totalbytesin; if((f=fopen(filename,"r"))==NULL) return 0; buildrespmodfile(f,lbuf); if(icap_write(fd,lbuf,strlen(lbuf))<0) return 0; // printf("Sending file:\n"); totalbytesout=strlen(lbuf); while((len=fread(lbuf,sizeof(char),512,f))>0){ totalbytesout+=len; bytes=sprintf(lg,"%X\r\n",len); if(icap_write(fd,lg,bytes)<0){ printf("Error writing to socket.....\n"); return 0; } if(icap_write(fd,lbuf,len)<0){ printf("Error writing to socket.....\n"); return 0; } icap_write(fd,"\r\n",2); // printf("Sending chunksize :%d\n",len); } icap_write(fd,"0\r\n\r\n",5); fclose(f); // printf("Done(%d bytes). Reading responce.....\n",totalbytesout); if((totalbytesin=readallresponce(fd))<0){ printf("Read all responce error;\n"); return -1; } // printf("Done(%d bytes).\n",totalbytes); ci_thread_mutex_lock(&statsmtx); in_bytes_stats+=totalbytesin; out_bytes_stats+=totalbytesout; ci_thread_mutex_unlock(&statsmtx); return 1; }
int do_file(int fd, char *filename, int *keepalive) { FILE *f; char lg[10], lbuf[512]; int bytes, len, totalbytesout, totalbytesin; unsigned int arand; if ((f = fopen(filename, "r")) == NULL) return 0; buildrespmodfile(f, lbuf); if (icap_write(fd, lbuf, strlen(lbuf)) < 0) return 0; // printf("Sending file:\n"); totalbytesout = strlen(lbuf); len = rand_r(&arand); len++; len = (int) ((((float) len) / RAND_MAX) * 510.0); len = (len < 512 ? len : 512); len = (len > 0 ? len : 1); while ((len = fread(lbuf, sizeof(char), len, f)) > 0) { totalbytesout += len; bytes = sprintf(lg, "%X\r\n", len); if (icap_write(fd, lg, bytes) < 0) { printf("Error writing to socket:%s (after %d bytes).....\n", lg, totalbytesout); req_errors_rw++; return 0; } if (icap_write(fd, lbuf, len) < 0) { printf("Error writing to socket.....\n"); req_errors_rw++; return 0; } icap_write(fd, "\r\n", 2); // printf("Sending chunksize :%d\n",len); len = rand_r(&arand); len++; len = (int) ((((float) len) / RAND_MAX) * 510.0); len = (len < 512 ? len : 512); len = (len > 0 ? len : 1); } icap_write(fd, "0\r\n\r\n", 5); fclose(f); // printf("Done(%d bytes). Reading responce.....\n",totalbytesout); if ((totalbytesin = readallresponce(fd, keepalive)) < 0) { printf("Read all responce error;\n"); return -1; } // printf("Done(%d bytes).\n",totalbytes); ci_thread_mutex_lock(&statsmtx); in_bytes_stats += totalbytesin; out_bytes_stats += totalbytesout; ci_thread_mutex_unlock(&statsmtx); return 1; }