# # patch "netxx_pipe.cc" # from [f2f865d07427d8a9728cd9bd35751bdf0eb5789a] # to [8e668a8b794126a41700d57572b75b685c687cf0] # # patch "netxx_pipe.hh" # from [10a3e9ac278675359a3a56ea78cbb3a35c0f4e23] # to [3c30849ded35bb51dabfa36d1bd012a2c0d4bc9a] # =============================================== --- netxx_pipe.cc f2f865d07427d8a9728cd9bd35751bdf0eb5789a +++ netxx_pipe.cc 8e668a8b794126a41700d57572b75b685c687cf0 @@ -101,6 +101,11 @@ // non-blocking: RIT=MAXDWORD RTTM=0 RTTC=0 readfd=fd1[0]; writefd=fd2[1]; + + memset(&overlap,0,sizeof overlap); + overlap.hEvent=CreateEvent(0,FALSE,FALSE,0); // TRUE,TRUE,0); ?? + bytes_available=0; + I(overlap.hEvent!=0); #else int fd1[2],fd2[2]; child=pipe_and_fork(fd1,fd2); @@ -164,6 +169,39 @@ { return &pi_; } +#ifdef WIN32 +Netxx::Probe::result_type Netxx::PipeCompatibleProbe::ready(const Timeout &timeout, ready_type rt) +{ if (!is_pipe) return Probe::ready(timeout,rt); + if (rt&ready_write) return ready_write; + if (rt&ready_read) + { if (pipe->bytes_available) return ready_read; + // ResetEvent(pipe->overlap.hEvent); + DWORD bytes_read=0; + if (!ReadFileEx((HANDLE)_get_osfhandle(readfd),pipe->readbuf,sizeof pipe->readbuf,&bytes_read,&pipe->overlap,NULL)) + { L(F("ReadFileEx failed %d\n") % GetLastError()); + throw oops("ReadFileEx failed "); + } + if (bytes_read) + { pipe->bytes_available=bytes_read; + return ready_read; + } + if (WaitForSingleObject(pipe->hEvent,timeout->seconds)) + { L(F("WaitForSingleObject failed %d\n") % GetLastError()); + throw oops("WaitForSingleObject failed "); + } + if (GetOverlappedResult((HANDLE)_get_osfhandle(readfd),&pipe->overlap,&bytes_read,FALSE)) + { L(F("GetOverlappedResult failed %d\n") % GetLastError()); + throw oops("GetOverlappedResult failed "); + } + if (bytes_read) + { pipe->bytes_available=bytes_read; + return ready_read; + } + } + return ready_none; +} +#endif + #ifdef BUILD_UNIT_TESTS #include "unit_tests.hh" =============================================== --- netxx_pipe.hh 10a3e9ac278675359a3a56ea78cbb3a35c0f4e23 +++ netxx_pipe.hh 3c30849ded35bb51dabfa36d1bd012a2c0d4bc9a @@ -8,13 +8,26 @@ #include #include #include +#ifdef WIN32 +# include +#endif namespace Netxx { +#ifdef WIN32 +class PipeCompatibleProbe; +#endif class PipeStream : public StreamBase { int readfd, writefd; ProbeInfo pi_; int child; +#ifdef WIN32 + char readbuf[1024]; + unsigned bytes_available; + OVERLAPPED overlap; + + friend class PipeCompatibleProbe; +#endif public: explicit PipeStream (int readfd, int writefd); explicit PipeStream (const std::string &cmd, const std::vector &args);