コード例 #1
0
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);

}
コード例 #2
0
ファイル: icap-stretch.c プロジェクト: p1rate5s/c-icap
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;
}
コード例 #3
0
int threadjobreqmod(struct buffer *buf)
{
    struct sockaddr_in addr;
    struct hostent *hent;
    int port = 1344;
    int fd;


    hent = gethostbyname(servername);
    if (hent == NULL)
        addr.sin_addr.s_addr = inet_addr(servername);
    else
        memcpy(&addr.sin_addr, hent->h_addr, hent->h_length);
    addr.sin_family = AF_INET;
    addr.sin_port = htons(port);


    while (1) {
        fd = socket(AF_INET, SOCK_STREAM, 0);
        if (fd == -1) {
            printf("Error oppening socket ....\n");
            return -1;
        }

        if (connect(fd, (struct sockaddr *) &addr, sizeof(addr))) {
            printf("Error connecting to socket .....\n");
            return -1;
        }

        for (;;) {
            if (icap_write(fd, buf->buf, buf->size) < 0) {
                printf("Connection closed try again...\n");
                break;
            }
            readheaderresponce(fd);
            if (!keepalive)
                break;
//             sleep(4);
            sleep(1);
        }
        sleep(1);
        close(fd);
    }
}
コード例 #4
0
ファイル: icap-stretch.c プロジェクト: p1rate5s/c-icap
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;
}
コード例 #5
0
ファイル: bspclean.c プロジェクト: AlexShiLucky/rtems
static void reconf(void)
{
  icap_write(0, 0xffff); /* dummy word */
  icap_write(0, 0xffff); /* dummy word */
  icap_write(0, 0xffff); /* dummy word */
  icap_write(0, 0xffff); /* dummy word */
  icap_write(1, 0xaa99); /* sync word part 1 */
  icap_write(1, 0x5566); /* sync word part 2 */
  icap_write(1, 0x30a1); /* write to command register */
  icap_write(1, 0x0000); /* null command */
  icap_write(1, 0x30a1); /* write to command register */
  icap_write(1, 0x000e); /* reboot command */
  icap_write(1, 0x2000); /* NOP */
  icap_write(1, 0x2000); /* NOP */
  icap_write(1, 0x2000); /* NOP */
  icap_write(1, 0x2000); /* NOP */
  icap_write(0, 0x1111); /* NULL */
  icap_write(0, 0xffff); /* dummy word */
}