Skip to content

Instantly share code, notes, and snippets.

@apk
Created October 20, 2011 05:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apk/1300486 to your computer and use it in GitHub Desktop.
Save apk/1300486 to your computer and use it in GitHub Desktop.
Pipe slowed down to 200 cps
main () {
int f = 0;
int w;
char buf [1024];
while (1) {
int r = read (0, buf, sizeof (buf));
if (r <= 0) break;
if (r < sizeof (buf)) {
f = 1;
}
for (w = 0; w < r; ) {
int x = r - w;
if (x > 2) x = 2;
x = write (1, buf + w, x);
if (x <= 0) break;
w += x;
if (f) usleep (5000 * x);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment