# # # patch "netxx_pipe.cc" # from [f6193b3a26c1f277b655a3be12009eddeef71498] # to [b9833401905053b47b08bb062fa26d8d2606064c] # # patch "netxx_pipe_stdio_main.cc" # from [4df1d617bf6619bd73223493e8a2425370d3e46e] # to [74b05a9fe5dfa0a1a0e7f816b13de0cdb241c6f1] # ============================================================ --- netxx_pipe.cc f6193b3a26c1f277b655a3be12009eddeef71498 +++ netxx_pipe.cc b9833401905053b47b08bb062fa26d8d2606064c @@ -59,12 +59,6 @@ Netxx::StdioStream::StdioStream(int _rea if (_setmode(_writefd, _O_BINARY) == -1) L(FL("failed to set output file descriptor to binary")); -#else - // FIXME: do we need to set these non-blocking? - int flags = fcntl(readfd, F_GETFL, 0); - I(fcntl(readfd, F_SETFL, flags | O_NONBLOCK) != -1); - flags = fcntl(writefd, F_GETFL, 0); - I(fcntl(writefd, F_SETFL, flags | O_NONBLOCK) != -1); #endif } @@ -351,7 +345,7 @@ UNIT_TEST(pipe, spawn_stdio) UNIT_TEST(pipe, spawn_stdio) { - unit_test_spawn ("netxx_pipe_stdio_main"); + unit_test_spawn ("./netxx_pipe_stdio_main"); } #endif ============================================================ --- netxx_pipe_stdio_main.cc 4df1d617bf6619bd73223493e8a2425370d3e46e +++ netxx_pipe_stdio_main.cc 74b05a9fe5dfa0a1a0e7f816b13de0cdb241c6f1 @@ -17,7 +17,12 @@ #include "netxx_pipe.hh" #include + +#ifdef WIN32 #include +#else +#include +#endif struct tester_sanity : public sanity { @@ -33,15 +38,17 @@ sanity & global_sanity = real_sanity; tester_sanity real_sanity; sanity & global_sanity = real_sanity; -int main (int argc, const char *argv[]) +int main (int argc, char *argv[]) { int fid = STDIN_FILENO; + global_sanity.initialize(argc, argv, 0); + // If an argument is given, it is a file to read instead of stdin, for debugging if (argc == 2) { fprintf (stderr, "opening %s\n", argv[1]); - fid = _open (argv[1], 0); + fid = open (argv[1], 0); } { @@ -50,29 +57,29 @@ int main (int argc, const char *argv[]) Netxx::Probe::result_type probe_result; Netxx::Timeout short_time(0,1000); - char buffer[256]; + char buffer[256]; Netxx::signed_size_type bytes_read; - int i; + int i; + int quit = 0; probe.add (stream, Netxx::Probe::ready_read); - // if no argument specified, continue forever; else exit after 100 loops - for (i = 0; (argc == 1) || (i < 100); i++) + // Exit when ready returns none + // But that never happens when reading a file, so exit on a count in that case + for (i = 0; (!quit) && ((argc == 1) || (i < 100)); i++) try { probe_result = probe.ready(short_time); - fprintf (stderr, "probe_result => %d\n", probe_result.second); switch (probe_result.second) { case Netxx::Probe::ready_none: + quit = 1; break; case Netxx::Probe::ready_read: bytes_read = stream.read (buffer, sizeof (buffer)); - fprintf (stderr, "bytes read => %d\n", bytes_read); stream.write (buffer, bytes_read); - break; case Netxx::Probe::ready_write: @@ -91,7 +98,7 @@ int main (int argc, const char *argv[]) stream.close(); if (fid != STDIN_FILENO) - _close (fid); + close (fid); } return 1;