# # patch "netxx/probe.h" # from [ab8ffcf0b226a90c7f79c56a7d41346c23b0d664] # to [7dbd28f284875bb3af6e59db3be0fb9378f8e7bb] # # patch "netxx_pipe.cc" # from [b17ca135b4a0b719e78a51e75c8fddca24efddd7] # to [48ca72384003858db9c3981eb3c46a8f7f98bd42] # # patch "netxx_pipe.hh" # from [da5c07b8728ee74c0d91457d0bdafe9fd54dbd02] # to [ea2ea18000ee00822b72c66c5dec449a947f43bc] # ======================================================================== --- netxx/probe.h ab8ffcf0b226a90c7f79c56a7d41346c23b0d664 +++ netxx/probe.h 7dbd28f284875bb3af6e59db3be0fb9378f8e7bb @@ -48,6 +48,8 @@ namespace Netxx { +class PipeCompatibleProbe; + /** * The Netxx::Probe class is a wrapper around one of the Netxx probe * classes. The reason that we have a wrapper is because most operating @@ -55,6 +57,11 @@ * kqueue(2) or /dev/poll. **/ class Probe { + /* + * Probe has no public way to select read only and write only sockets + * needed for probing pipes, so grant PipeCompatibleProbe to use add_socket + */ + friend class PipeCompatibleProbe; public: /* * Bitmask for telling Probe exactly what you want and for testing the ======================================================================== --- netxx_pipe.cc b17ca135b4a0b719e78a51e75c8fddca24efddd7 +++ netxx_pipe.cc 48ca72384003858db9c3981eb3c46a8f7f98bd42 @@ -9,8 +9,8 @@ Netxx::PipeStream::PipeStream(int _readfd, int _writefd) : readfd(_readfd), writefd(_writefd), child() -{ pi_.add_socket(readfd); - pi_.add_socket(writefd); +{ //pi_.add_socket(readfd); + //pi_.add_socket(writefd); } #ifndef __WIN32__ @@ -57,8 +57,8 @@ #include #include #include +#endif #include -#endif Netxx::PipeStream::PipeStream (const std::string &cmd, const std::vector &args) : readfd(), writefd(), child() @@ -129,8 +129,8 @@ writefd=fd2[1]; fcntl(readfd,F_SETFL,fcntl(readfd,F_GETFL)|O_NONBLOCK); #endif - pi_.add_socket(readfd); - pi_.add_socket(writefd); +// pi_.add_socket(readfd); +// pi_.add_socket(writefd); } Netxx::signed_size_type Netxx::PipeStream::read (void *buffer, size_type length) @@ -179,7 +179,7 @@ #endif const Netxx::ProbeInfo* Netxx::PipeStream::get_probe_info (void) const -{ return &pi_; +{ return 0; } #ifdef WIN32 @@ -254,6 +254,27 @@ { assert(!ip_pipe); Probe::add(ss,rt); } +#else // unix +void Netxx::PipeCompatibleProbe::add(PipeStream &ps, ready_type rt) +{ + if (rt==ready_none || rt&ready_read) add_socket(ps.get_readfd(),ready_read); + if (rt==ready_none || rt&ready_write) add_socket(ps.get_writefd(),ready_write); +} + +void Netxx::PipeCompatibleProbe::add(const StreamBase &sb, ready_type rt) +{ + try + { add(const_cast(dynamic_cast(sb)),rt); + } + catch (...) + { Probe::add(sb,rt); + } +} + +void Netxx::PipeCompatibleProbe::add(const StreamServer &ss, ready_type rt) +{ + Probe::add(ss,rt); +} #endif #ifdef BUILD_UNIT_TESTS @@ -281,10 +302,13 @@ Netxx::PipeCompatibleProbe probe; Netxx::Timeout timeout(2L), instant(0,1); probe.clear(); - probe.add(static_cast(pipe), - Netxx::Probe::ready_read | Netxx::Probe::ready_oobd); - Netxx::Probe::result_type res = probe.ready(timeout); - L(F("probe %d/%d\n") % res.first % res.second); + probe.add(pipe, Netxx::Probe::ready_write); + Netxx::Probe::result_type res = probe.ready(instant); + L(F("probe for write %d/%d\n") % res.first % res.second); + probe.clear(); + probe.add(pipe, Netxx::Probe::ready_read | Netxx::Probe::ready_oobd); + res = probe.ready(timeout); + L(F("probe for read %d/%d\n") % res.first % res.second); do { bytes=pipe.read(buf,sizeof buf); if (bytes<=0) break; ======================================================================== --- netxx_pipe.hh da5c07b8728ee74c0d91457d0bdafe9fd54dbd02 +++ netxx_pipe.hh ea2ea18000ee00822b72c66c5dec449a947f43bc @@ -34,14 +34,12 @@ */ namespace Netxx { -#ifdef WIN32 class PipeCompatibleProbe; class StreamServer; -#endif class PipeStream : public StreamBase { int readfd, writefd; - ProbeInfo pi_; +// ProbeInfo pi_; int child; #ifdef WIN32 char readbuf[1024]; @@ -87,6 +85,10 @@ #endif }; #else - typedef Probe PipeCompatibleProbe; + struct PipeCompatibleProbe : Probe + { void add(PipeStream &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); + }; #endif }