title: how to change a PIPE size in Linux?
body: <p>I tried to increase a linux pipe buffer size.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>#define _GNU_SOURCE
  
  #include &lt;stdlib.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;sys/stat.h&gt;
  
  #define IO_BUFSIZE 4096
  
  #include&lt;stdio.h&gt; //printf
  #include&lt;string.h&gt;    //strlen
  #include&lt;sys/socket.h&gt;    //socket
  #include&lt;arpa/inet.h&gt; //inet_addr
  
  typedef struct {
          loff_t offset;
          int size;
  } msg_header;
  
  int main(int argc , char *argv[])
  {
  
     loff_t in_off = 0;
     loff_t out_off = 0;
  
     int in_fd = -1; //file id
     int err = -1;
     int splice_bytes = 0;
     int len1 = 0;
     int len2 = 0;
     int len3 = 0;
  
     in_fd = open("/home/wenji/splice-sample/libpfm-4.5.0.tar", O_RDONLY); //open a file
  
     int filedes[2];
     struct stat stbuf;
  
     if(pipe(filedes) &lt; 0)
     {
          perror("pipe error");
     }
  
     //set the pipe size,
     fcntl(filedes[1], F_SETPIPE_SZ, 1048576);
  
  
     if(fstat(in_fd, &amp;stbuf) &lt; 0)
     {
          perror("wrong file id");
     }
  
     len1 = stbuf.st_size;
  
     printf("the file size len=%i\n", len1);
  
      int sock;
      struct sockaddr_in server;
      char message[1000] , server_reply[2000];
      msg_header e_block;
  
      //Create socket
      sock = socket(AF_INET , SOCK_STREAM , 0);
      if (sock == -1)
      {
          printf("Could not create socket");
      }
      puts("Socket created");
  
      server.sin_addr.s_addr = inet_addr("10.1.1.2");
      server.sin_family = AF_INET;
      server.sin_port = htons( 8888 );
  
      //Connect to remote server
      if (connect(sock , (struct sockaddr *)&amp;server , sizeof(server)) &lt; 0)
      {
          perror("connect failed. Error");
          return 1;
      }
  
      puts("Connected\n");
  
  
     printf("the file size = %i \n", len1);
  
      //keep communicating with server
      while(len1&gt;0)
      {
  
          //record the offset
          e_block.offset = in_off;
  
          //first, splice data from file to pipe
  
          splice_bytes = splice(in_fd, &amp;in_off, filedes[1], NULL, 32736, SPLICE_F_MOVE|SPLICE_F_MORE);
          if(splice_bytes &lt; 0)
          {
                  perror("splice error");
          }
  
  
          //record the size
          e_block.size = splice_bytes;
  
          //Send e-block header over
          if( send(sock , &amp;e_block , sizeof(msg_header) , 0) &lt; 0)
          {
              puts("Send failed");
              return 1;
          }
  
          printf("e-block size %i, offset %ld \n", e_block.size, e_block.offset);
  
          len2 = splice_bytes;
          while(len2 &gt; 0) {
          //send the data over network
                  len3 = splice(filedes[0],NULL, sock, 0, len2, SPLICE_F_MOVE|SPLICE_F_MORE);
                  len2 = len2 - len3;
          }
  
          len1 -= splice_bytes;
  
       }
  
      close(sock);
      close(filedes[0]);
      close(filedes[1]);
      close(in_fd);
  
      return 0;
  }
  </code></pre>
  
  <p>When I compile the code, I got the following errors:</p>
  
  <pre><code>client.c: In function ‘main’:
  client.c:45: error: ‘F_SETPIPE_SZ’ undeclared (first use in this function)
  client.c:45: error: (Each undeclared identifier is reported only once
  client.c:45: error: for each function it appears in.)
  </code></pre>
  
  <p>"#define _GNU_SOURCE" has been included in my code.</p>
  
  <p>Here is my "uname -r"</p>
  
  <p>"Linux capecod 3.12.12 #3 SMP Thu Feb 27 21:55:17 CST 2014 x86_64 x86_64 x86_64 GNU/Linux" </p>
  
  <p>Could anybody help me out? thanks</p>
  
  <p>wwu</p>