From e87440eb6984e23166c4664faaa4859e7f9df14f Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Sun, 10 Jul 2016 16:56:51 +0200 Subject: Tiny slowish pseudo random dd to debug partial writes implementation in mcastleech --- mcastseed/src/Makefile.am | 3 ++- mcastseed/src/random_speed_dd.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 mcastseed/src/random_speed_dd.c (limited to 'mcastseed/src') 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 +#include +#include +#include + +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; +} + -- cgit v1.2.3