18 #include <sys/resource.h>
22 class KDSoapServer::Private
26 : m_threadPool(nullptr)
27 , m_mainThreadSocketList(nullptr)
30 , m_path(QString::fromLatin1(
"/"))
31 , m_maxConnections(-1)
32 , m_portBeforeSuspend(0)
38 delete m_mainThreadSocketList;
44 KDSoapServer::Features m_features;
48 QString m_logFileName;
51 QMutex m_serverDataMutex;
53 QString m_wsdlPathInUrl;
57 QHostAddress m_addressBeforeSuspend;
58 quint16 m_portBeforeSuspend;
61 QSslConfiguration m_sslConfiguration;
70 setMaxPendingConnections(1000);
82 if (max > -1 && numSockets >= max) {
84 log(QByteArray(
"ERROR Too many connections (") + QByteArray::number(numSockets) +
"), incoming connection rejected\n");
85 }
else if (d->m_threadPool) {
87 d->m_threadPool->handleIncomingConnection(socketDescriptor,
this);
90 if (!d->m_mainThreadSocketList) {
93 d->m_mainThreadSocketList->handleIncomingConnection(socketDescriptor);
99 if (d->m_threadPool) {
100 return d->m_threadPool->numConnectedSockets(
this);
101 }
else if (d->m_mainThreadSocketList) {
102 return d->m_mainThreadSocketList->socketCount();
110 if (d->m_threadPool) {
111 return d->m_threadPool->totalConnectionCount(
this);
112 }
else if (d->m_mainThreadSocketList) {
113 return d->m_mainThreadSocketList->totalConnectionCount();
121 if (d->m_threadPool) {
122 d->m_threadPool->resetTotalConnectionCount(
this);
123 }
else if (d->m_mainThreadSocketList) {
124 d->m_mainThreadSocketList->resetTotalConnectionCount();
135 return d->m_threadPool;
140 QMutexLocker lock(&d->m_serverDataMutex);
141 const QHostAddress address = serverAddress();
142 if (address == QHostAddress::Null) {
145 const QString addressStr = address == QHostAddress::Any ? QString::fromLatin1(
"127.0.0.1") : address.toString();
146 return QString::fromLatin1(
"%1://%2:%3%4")
147 .arg(QString::fromLatin1((d->m_features &
Ssl) ?
"https" :
"http"), addressStr)
164 QMutexLocker lock(&d->m_logMutex);
165 d->m_logLevel = level;
170 QMutexLocker lock(&d->m_logMutex);
171 return d->m_logLevel;
176 QMutexLocker lock(&d->m_logMutex);
177 d->m_logFileName = fileName;
182 QMutexLocker lock(&d->m_logMutex);
183 return d->m_logFileName;
186 void KDSoapServer::log(
const QByteArray &text)
192 QMutexLocker lock(&d->m_logMutex);
193 if (d->m_logFileName.isEmpty()) {
196 if (!d->m_logFile.isOpen()) {
197 d->m_logFile.setFileName(d->m_logFileName);
198 if (!d->m_logFile.open(QIODevice::Append)) {
199 qCritical(
"Could not open log file for writing: %s", qPrintable(d->m_logFileName));
200 d->m_logFileName.clear();
204 d->m_logFile.write(text);
209 if (d->m_logFile.isOpen()) {
210 d->m_logFile.flush();
216 if (d->m_logFile.isOpen()) {
217 d->m_logFile.close();
230 if (getrlimit(RLIMIT_NOFILE, &lim) != 0) {
231 qDebug() <<
"error calling getrlimit:" << strerror(errno);
234 bool changingHardLimit =
false;
236 qDebug() <<
"Current limit" << lim.rlim_cur << lim.rlim_max;
238 if (rlim_t(sockets) <= lim.rlim_cur) {
242 if (rlim_t(sockets) > lim.rlim_max) {
244 lim.rlim_max = sockets;
245 qDebug() <<
"Setting rlim_max to" << sockets;
246 changingHardLimit =
true;
251 lim.rlim_cur = qMin(rlim_t(OPEN_MAX), lim.rlim_max);
254 lim.rlim_cur = lim.rlim_max;
256 if (setrlimit(RLIMIT_NOFILE, &lim) == 0) {
257 qDebug() <<
"limit set to" << lim.rlim_cur;
259 if (changingHardLimit) {
260 qDebug() <<
"WARNING: hard limit is not high enough";
262 qDebug() <<
"error calling setrlimit(" << lim.rlim_cur <<
"," << lim.rlim_max <<
") :" << strerror(errno);
273 d->m_portBeforeSuspend = serverPort();
274 d->m_addressBeforeSuspend = serverAddress();
278 if (d->m_threadPool) {
279 d->m_threadPool->disconnectSockets(
this);
280 }
else if (d->m_mainThreadSocketList) {
281 d->m_mainThreadSocketList->disconnectAll();
287 if (d->m_portBeforeSuspend == 0) {
288 qWarning(
"KDSoapServer: resume() called without calling suspend() first");
290 if (!listen(d->m_addressBeforeSuspend, d->m_portBeforeSuspend)) {
291 qWarning(
"KDSoapServer: failed to listen on %s port %d", qPrintable(d->m_addressBeforeSuspend.toString()), d->m_portBeforeSuspend);
293 d->m_portBeforeSuspend = 0;
299 QMutexLocker lock(&d->m_serverDataMutex);
300 d->m_wsdlFile = file;
301 d->m_wsdlPathInUrl = pathInUrl;
306 QMutexLocker lock(&d->m_serverDataMutex);
307 return d->m_wsdlFile;
312 QMutexLocker lock(&d->m_serverDataMutex);
313 return d->m_wsdlPathInUrl;
318 QMutexLocker lock(&d->m_serverDataMutex);
324 QMutexLocker lock(&d->m_serverDataMutex);
330 QMutexLocker lock(&d->m_serverDataMutex);
331 d->m_maxConnections = sockets;
336 QMutexLocker lock(&d->m_serverDataMutex);
337 return d->m_maxConnections;
342 QMutexLocker lock(&d->m_serverDataMutex);
348 QMutexLocker lock(&d->m_serverDataMutex);
349 return d->m_features;
355 return d->m_sslConfiguration;
360 d->m_sslConfiguration = config;
364 #include "moc_KDSoapServer.cpp"
int numConnectedSockets() const
KDSoapThreadPool * threadPool() const
void setPath(const QString &path)
void setLogFileName(const QString &fileName)
int maxConnections() const
void connectionRejected()
static bool setExpectedSocketCount(int sockets)
void setSslConfiguration(const QSslConfiguration &config)
void setUse(KDSoapMessage::Use use)
KDSoapServer(QObject *parent=0)
KDSoapMessage::Use use() const
void setWsdlFile(const QString &file, const QString &pathInUrl)
void incomingConnection(qintptr socketDescriptor) override
QSslConfiguration sslConfiguration() const
void setMaxConnections(int sockets)
void setThreadPool(KDSoapThreadPool *threadPool)
QString logFileName() const
void resetTotalConnectionCount()
QString wsdlPathInUrl() const
void setFeatures(Features features)
LogLevel logLevel() const
Features features() const
int totalConnectionCount() const
void setLogLevel(LogLevel level)