summaryrefslogtreecommitdiff
path: root/draft/mcastseed/src/random_speed_dd.c
diff options
context:
space:
mode:
authorLudovic Pouzenc <ludovic@pouzenc.fr>2017-05-05 11:28:51 +0200
committerLudovic Pouzenc <ludovic@pouzenc.fr>2017-05-05 11:28:51 +0200
commit604f3d64764270c052cfb43081ec522237bbdb75 (patch)
treeb3db80e35399412693c7a986b3021435b2914fe4 /draft/mcastseed/src/random_speed_dd.c
parentf7f175cb29192682f3ece9479f24a40672a3d74d (diff)
downloadeficast-604f3d64764270c052cfb43081ec522237bbdb75.tar.gz
eficast-604f3d64764270c052cfb43081ec522237bbdb75.tar.bz2
eficast-604f3d64764270c052cfb43081ec522237bbdb75.zip
Massive add for all draft stuff to keep it in sync
Diffstat (limited to 'draft/mcastseed/src/random_speed_dd.c')
-rw-r--r--draft/mcastseed/src/random_speed_dd.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/draft/mcastseed/src/random_speed_dd.c b/draft/mcastseed/src/random_speed_dd.c
new file mode 100644
index 0000000..4d94bc0
--- /dev/null
+++ b/draft/mcastseed/src/random_speed_dd.c
@@ -0,0 +1,36 @@
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+
+char buf[0xffff];
+
+int main() {
+ ssize_t nread, nwrite, remains;
+
+ srandom(1); /* Always the same pseudo-random sequence */
+
+ while ( (nread=read(0, buf, 0xfff & rand())) > 0 ) {
+ remains = nread;
+ while ( remains ) {
+ nwrite=write(1, buf, nread);
+ if ( nwrite < 0 ) {
+ if ( !(errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) ) {
+ perror("write");
+ return nwrite;
+ }
+ } else {
+ remains -= nwrite;
+ }
+ }
+ /*fprintf(stderr, "nread==%zu, nwrite==%zu\n", nread, nwrite);*/
+ usleep( 0xffff & rand() );
+ }
+ if ( nread < 0 ) {
+ perror("read");
+ return nread;
+ }
+
+ return 0;
+}
+