/[svn]/qsampler/trunk/src/qsamplerMessages.cpp
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerMessages.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2847 by capela, Sun Aug 3 16:56:18 2014 UTC revision 2848 by capela, Sat Oct 3 15:48:18 2015 UTC
# Line 1  Line 1 
1  // qsamplerMessages.cpp  // qsamplerMessages.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2014, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2015, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007, Christian Schoenebeck     Copyright (C) 2007, Christian Schoenebeck
6    
7     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
# Line 113  Messages::~Messages (void) Line 113  Messages::~Messages (void)
113  }  }
114    
115    
116    // Set stdout/stderr blocking mode.
117    bool Messages::stdoutBlock ( int fd, bool bBlock ) const
118    {
119    #if !defined(WIN32)
120            const int iFlags = ::fcntl(fd, F_GETFL, 0);
121            const bool bNonBlock = bool(iFlags & O_NONBLOCK);
122            if (bBlock && bNonBlock)
123                    bBlock = (::fcntl(fd, F_SETFL, iFlags & ~O_NONBLOCK) == 0);
124            else
125            if (!bBlock && !bNonBlock)
126                    bBlock = (::fcntl(fd, F_SETFL, iFlags |  O_NONBLOCK) != 0);
127    #endif
128            return bBlock;
129    }
130    
131    
132  // Own stdout/stderr socket notifier slot.  // Own stdout/stderr socket notifier slot.
133  void Messages::stdoutNotify ( int fd )  void Messages::stdoutNotify ( int fd )
134  {  {
135  #if !defined(WIN32)  #if !defined(WIN32)
136          // Set non-blocking reads, if not already...          // Set non-blocking reads, if not already...
137          const int iFlags = ::fcntl(fd, F_GETFL, 0);          const bool bBlock = stdoutBlock(fd, false);
         int iBlock = ((iFlags & O_NONBLOCK) == 0);  
         if (iBlock)  
                 iBlock = ::fcntl(fd, F_SETFL, iFlags | O_NONBLOCK);  
138          // Read as much as is available...          // Read as much as is available...
139          QString sTemp;          QString sTemp;
140          char achBuffer[1024];          char achBuffer[1024];
# Line 130  void Messages::stdoutNotify ( int fd ) Line 143  void Messages::stdoutNotify ( int fd )
143          while (cchRead > 0) {          while (cchRead > 0) {
144                  achBuffer[cchRead] = (char) 0;                  achBuffer[cchRead] = (char) 0;
145                  sTemp.append(achBuffer);                  sTemp.append(achBuffer);
146                  cchRead = (iBlock ? 0 : ::read(fd, achBuffer, cchBuffer));                  cchRead = (bBlock ? 0 : ::read(fd, achBuffer, cchBuffer));
147          }          }
148          // Needs to be non-empty...          // Needs to be non-empty...
149          if (!sTemp.isEmpty())          if (!sTemp.isEmpty())

Legend:
Removed from v.2847  
changed lines
  Added in v.2848

  ViewVC Help
Powered by ViewVC