pipes can be blocking, non blocking or blocking on one side only
default is again blocking, because it causes less trouble
This commit is contained in:
		@@ -9,6 +9,10 @@
 | 
			
		||||
    @license LGPL, see file <a href="license.html">COPYING</a>
 | 
			
		||||
 | 
			
		||||
    $Log$
 | 
			
		||||
    Revision 1.7  2004/12/18 20:58:19  marc
 | 
			
		||||
    pipes can be blocking, non blocking or blocking on one side only
 | 
			
		||||
    default is again blocking, because it causes less trouble
 | 
			
		||||
 | 
			
		||||
    Revision 1.6  2004/12/14 20:32:10  marc
 | 
			
		||||
    support for connect_cin
 | 
			
		||||
    pipe is now non blocking by default
 | 
			
		||||
@@ -55,20 +59,30 @@ namespace mrw {
 | 
			
		||||
    int _fd[2];
 | 
			
		||||
    int _lastError;
 | 
			
		||||
  public:
 | 
			
		||||
    /// blocking mode
 | 
			
		||||
    enum BlockingMode {
 | 
			
		||||
      non_blocking,             ///< both sides are non blocking
 | 
			
		||||
      block_input,              ///< pipe input is blocking
 | 
			
		||||
      block_output,             ///< pipe output is blocking
 | 
			
		||||
      blocking                  ///< both sides are blocking
 | 
			
		||||
    };
 | 
			
		||||
    /// creates a unix pipe
 | 
			
		||||
    /** @param blocking Flag whether the pipe is blocking (default: no) */
 | 
			
		||||
    Pipe(bool blocking=false) throw(std::bad_exception): _lastError(-1) {
 | 
			
		||||
    /** @param mode Flag whether the pipe is blocking (default: yes) */
 | 
			
		||||
    Pipe(BlockingMode mode=blocking) throw(std::bad_exception):
 | 
			
		||||
      _lastError(-1) {
 | 
			
		||||
      _fd[0] = -1;
 | 
			
		||||
      _fd[1] = -1;
 | 
			
		||||
      if (::pipe(_fd)==-1) {
 | 
			
		||||
        _lastError=errno;
 | 
			
		||||
        return;
 | 
			
		||||
      }
 | 
			
		||||
      if (!blocking) {
 | 
			
		||||
      if (mode==non_blocking || mode==block_output) {
 | 
			
		||||
        int val(fcntl(_fd[0], F_GETFL, 0));
 | 
			
		||||
        if (fcntl(_fd[0], F_SETFL, (val!=-1?val:0)|O_NONBLOCK) == -1)
 | 
			
		||||
          _lastError=errno;
 | 
			
		||||
        val = fcntl(_fd[1], F_GETFL, 0);
 | 
			
		||||
      }
 | 
			
		||||
      if (mode==non_blocking || mode==block_input) {
 | 
			
		||||
        int val(fcntl(_fd[1], F_GETFL, 0));
 | 
			
		||||
        if (fcntl(_fd[1], F_SETFL, (val!=-1?val:0)|O_NONBLOCK) == -1)
 | 
			
		||||
          _lastError=errno;
 | 
			
		||||
      }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user