lkml.org 
[lkml]   [2016]   [Sep]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH 00/11] splice cleanups
On Wed, Sep 14, 2016 at 10:55 AM, Cedric Blancher
<cedric.blancher@gmail.com> wrote:
> Is there any shell which uses pipe splicing?

for i in /usr/bin/*; do if file $i | grep -q ELF; then if nm -D $i |
grep -q splice; then echo $i; fi; fi; done

For me it does not yield anything by which you could easily try out splicing.

Attaching a simple cp-like program which uses splice if you want to try it out.

Thanks,
Miklos
#define _GNU_SOURCE

#include <err.h>
#include <fcntl.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
int to, from, res;
int pip[2];
int siz = 65536;

if (argc != 3)
err(1, "usage: %s from_file to_file", argv[0]);

from = open(argv[1], O_RDONLY);
if (from == -1)
err(1, "opening %s", argv[1]);

to = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (to == -1)
err(1, "opening %s", argv[2]);

res = pipe(pip);
if (res == -1)
err(1, "creating pipe");

while (1) {
int num;

res = splice(from, NULL, pip[1], NULL, siz, 0);
if (res == -1)
err(1, "splicing from %s to pipe", argv[1]);

num = res;
if (num == 0)
break;

do {
res = splice(pip[0], NULL, to, NULL, num, 0);
if (res == -1)
err(1, "splicing from pipe to %s", argv[2]);

if (res == 0)
break;

num -= res;
} while (num);
}

res = close(to);
if (res == -1)
err(1, "closing %s", argv[2]);

res = close(from);
if (res == -1)
err(1, "closing %s", argv[1]);

return 0;
}
\
 
 \ /
  Last update: 2016-09-17 09:59    [W:0.191 / U:0.376 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site