From b29fa5a40e04f4243c15391b70c37ebce0198fc1 Mon Sep 17 00:00:00 2001 From: Sergey Kudryashov Date: Mon, 4 Aug 2014 18:11:55 +0400 Subject: Add async_ports test --- erts/emulator/test/async_ports_SUITE_data/cport.c | 65 +++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 erts/emulator/test/async_ports_SUITE_data/cport.c (limited to 'erts/emulator/test/async_ports_SUITE_data/cport.c') diff --git a/erts/emulator/test/async_ports_SUITE_data/cport.c b/erts/emulator/test/async_ports_SUITE_data/cport.c new file mode 100644 index 0000000000..179cdc4b8b --- /dev/null +++ b/erts/emulator/test/async_ports_SUITE_data/cport.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include +#include +#include + +typedef unsigned char byte; + +int read_cmd(byte *buf) +{ + int len; + if (read_exact(buf, 4) != 4) + return(-1); + + len = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; + return read_exact(buf, len); +} + +int write_cmd(byte *buf, int len) +{ + byte li[4]; + li[0] = (len >> 24) & 0xff; + li[1] = (len >> 16) & 0xff; + li[2] = (len >> 8) & 0xff; + li[3] = len & 0xff; + write_exact(&li, 4); + + return write_exact(buf, len); +} + +int read_exact(byte *buf, int len) +{ + int i, got=0; + do { + if ((i = read(0, buf+got, len-got)) <= 0) + { + return(i); + } + got += i; + } while (got 0) { + usleep(sleep_time); + write_cmd(buf, len); + } +} -- cgit v1.2.3