# # # patch "netsync.cc" # from [6d75d32b27057d033026d79cd1ce5a8332876c76] # to [e422d4447dbdeadd9f8ae95565ee05e7fb4b4a87] # # patch "netxx_pipe.cc" # from [f6193b3a26c1f277b655a3be12009eddeef71498] # to [cda597f46d4c085fc4ec18786c3ba1316c221381] # # patch "netxx_pipe.hh" # from [41d912dba5cf1c70862cff97b8e20bb199de2281] # to [3bd86ee5c96447657c531ea6383c63d543a8ace8] # ============================================================ --- netsync.cc 6d75d32b27057d033026d79cd1ce5a8332876c76 +++ netsync.cc e422d4447dbdeadd9f8ae95565ee05e7fb4b4a87 @@ -2970,7 +2970,7 @@ serve_single_connection(protocol_role ro app_state & app, unsigned long timeout_seconds) { - shared_ptr str(new Netxx::StdioStream(0,1)); + shared_ptr str(new Netxx::StdioStream); shared_ptr sess (new session (role, server_voice, include_pattern, exclude_pattern, app, "stdio", str)); ============================================================ --- netxx_pipe.cc f6193b3a26c1f277b655a3be12009eddeef71498 +++ netxx_pipe.cc cda597f46d4c085fc4ec18786c3ba1316c221381 @@ -35,14 +35,19 @@ using std::strerror; using std::perror; using std::strerror; -Netxx::StdioStream::StdioStream(int _readfd, int _writefd) +Netxx::StdioStream::StdioStream(void) : - readfd(_readfd), - writefd(_writefd) +#ifdef WIN32 + readfd ((int)GetStdHandle(STD_INPUT_HANDLE)), + writefd ((int)GetStdHandle(STD_OUTPUT_HANDLE)) +#else + readfd (stdin), + writefd (stdout) +#endif { // This allows netxx to call select() on these file descriptors. Unless // they are actually a socket (ie, we are spawned from 'mtn sync - // file:...'), this will fail (at least on Win32). + // file:...'), this will fail on Win32. probe_info.add_socket (readfd); probe_info.add_socket (writefd); @@ -53,18 +58,12 @@ Netxx::StdioStream::StdioStream(int _rea L(FL("failed to load WinSock")); } - if (_setmode(_readfd, _O_BINARY) == -1) + if (_setmode(readfd, _O_BINARY) == -1) L(FL("failed to set input file descriptor to binary")); - if (_setmode(_writefd, _O_BINARY) == -1) + 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 } @@ -281,6 +280,19 @@ Netxx::StdioProbe::add(const StreamBase } } +void +Netxx::StdioProbe::add(const StreamServer &ss, ready_type rt) +{ + try + { + Probe::add(ss,rt); + } + catch (...) + { + I(0); // Should not be a StdioStream here + } +} + #ifdef BUILD_UNIT_TESTS #include "unit_tests.hh" ============================================================ --- netxx_pipe.hh 41d912dba5cf1c70862cff97b8e20bb199de2281 +++ netxx_pipe.hh 3bd86ee5c96447657c531ea6383c63d543a8ace8 @@ -58,6 +58,8 @@ namespace Netxx namespace Netxx { + class StdioProbe; + class StreamServer; class SpawnedStream : public StreamBase { @@ -83,19 +85,18 @@ namespace Netxx virtual const ProbeInfo* get_probe_info (void) const; }; - class StdioProbe; - class StdioStream : public StreamBase { friend class StdioProbe; - int readfd; - int writefd; - ProbeInfo probe_info; + int readfd; + int writefd; + ProbeInfo probe_info; + public: - explicit StdioStream (int readfd, int writefd); - // Construct a Stream object from existing files; typically stdout - // and stdin of the current process. + explicit StdioStream (void); + // Construct a Stream object from stdout and stdin of the current + // process. virtual ~StdioStream() { close(); } virtual signed_size_type read (void *buffer, size_type length); @@ -108,8 +109,11 @@ namespace Netxx struct StdioProbe : Probe { public: + // Note that Netxx::Probe::add is a template, not virtual; we provide + // the versions needed by netsync code. void add(const StdioStream &ps, ready_type rt=ready_none); void add(const StreamBase &sb, ready_type rt=ready_none); + void add(const StreamServer &ss, ready_type rt=ready_none); }; }