summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Pouzenc <ludovic@pouzenc.fr>2016-07-10 16:56:51 +0200
committerLudovic Pouzenc <ludovic@pouzenc.fr>2016-07-10 16:56:51 +0200
commite87440eb6984e23166c4664faaa4859e7f9df14f (patch)
tree854cb489d13cffe410d32d49a44d6a3814ccd7c8
parent967b104d80592c192f3e862b1266f6e90475a83e (diff)
downloadeficast-e87440eb6984e23166c4664faaa4859e7f9df14f.tar.gz
eficast-e87440eb6984e23166c4664faaa4859e7f9df14f.tar.bz2
eficast-e87440eb6984e23166c4664faaa4859e7f9df14f.zip
Tiny slowish pseudo random dd to debug partial writes implementation in mcastleech
-rw-r--r--.gitignore1
-rw-r--r--mcastseed/src/Makefile.am3
-rw-r--r--mcastseed/src/random_speed_dd.c32
3 files changed, 35 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 9eaae60..32d416f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,6 +21,7 @@ mcastseed/missing
mcastseed/stamp-h1
mcastseed/src/mcastseed
mcastseed/src/mcastleech
+mcastseed/src/random_speed_dd
mcastseed/src/Makefile
mcastseed/src/Makefile.in
mcastseed/src/*.o
diff --git a/mcastseed/src/Makefile.am b/mcastseed/src/Makefile.am
index 7ad2954..547d715 100644
--- a/mcastseed/src/Makefile.am
+++ b/mcastseed/src/Makefile.am
@@ -4,9 +4,10 @@ AM_CFLAGS =\
-Wall \
-g
-bin_PROGRAMS = mcastseed mcastleech
+bin_PROGRAMS = mcastseed mcastleech random_speed_dd
mcastseed_SOURCES = mcastseed.c msock.c
mcastleech_SOURCES = mcastleech.c msock.c dgrambuf.c
+random_speed_dd_SOURCES = random_speed_dd.c
LDADD = @WSOCKLIB@
diff --git a/mcastseed/src/random_speed_dd.c b/mcastseed/src/random_speed_dd.c
new file mode 100644
index 0000000..0c11c05
--- /dev/null
+++ b/mcastseed/src/random_speed_dd.c
@@ -0,0 +1,32 @@
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+
+char buf[0xffff];
+
+int main() {
+ size_t nread, nwrite, remains;
+
+ srandom(1); // Always the same pseudo-random sequence
+
+ while ( (nread=read(0, buf, 0xf & 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==%zi, nwrite==%zi\n", nread, nwrite);
+ usleep( 0xfffff & rand() );
+ }
+
+ return 0;
+}
+