1 |
// qsamplerMessages.cpp |
// qsamplerMessages.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2014, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2017, 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 |
34 |
#include <QDateTime> |
#include <QDateTime> |
35 |
#include <QIcon> |
#include <QIcon> |
36 |
|
|
37 |
#if !defined(WIN32) |
#if !defined(__WIN32__) && !defined(_WIN32) && !defined(WIN32) |
38 |
#include <unistd.h> |
#include <unistd.h> |
39 |
#include <fcntl.h> |
#include <fcntl.h> |
40 |
#endif |
#endif |
113 |
} |
} |
114 |
|
|
115 |
|
|
116 |
|
// Set stdout/stderr blocking mode. |
117 |
|
bool Messages::stdoutBlock ( int fd, bool bBlock ) const |
118 |
|
{ |
119 |
|
#if !defined(__WIN32__) && !defined(_WIN32) && !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__) && !defined(_WIN32) && !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]; |
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()) |
190 |
// Flush current buffer. |
// Flush current buffer. |
191 |
flushStdoutBuffer(); |
flushStdoutBuffer(); |
192 |
|
|
193 |
#if !defined(WIN32) |
#if !defined(__WIN32__) && !defined(_WIN32) && !defined(WIN32) |
194 |
// Destroy if already enabled. |
// Destroy if already enabled. |
195 |
if (!bCapture && m_pStdoutNotifier) { |
if (!bCapture && m_pStdoutNotifier) { |
196 |
delete m_pStdoutNotifier; |
delete m_pStdoutNotifier; |