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"))
165 QMutexLocker lock(&d->m_logMutex);
166 d->m_logLevel = level;
171 QMutexLocker lock(&d->m_logMutex);
172 return d->m_logLevel;
177 QMutexLocker lock(&d->m_logMutex);
178 d->m_logFileName = fileName;
183 QMutexLocker lock(&d->m_logMutex);
184 return d->m_logFileName;
187 void KDSoapServer::log(
const QByteArray &text)
193 QMutexLocker lock(&d->m_logMutex);
194 if (d->m_logFileName.isEmpty()) {
197 if (!d->m_logFile.isOpen()) {
198 d->m_logFile.setFileName(d->m_logFileName);
199 if (!d->m_logFile.open(QIODevice::Append)) {
200 qCritical(
"Could not open log file for writing: %s", qPrintable(d->m_logFileName));
201 d->m_logFileName.clear();
205 d->m_logFile.write(text);
210 if (d->m_logFile.isOpen()) {
211 d->m_logFile.flush();
217 if (d->m_logFile.isOpen()) {
218 d->m_logFile.close();
231 if (getrlimit(RLIMIT_NOFILE, &lim) != 0) {
232 qDebug() <<
"error calling getrlimit:" << strerror(errno);
235 bool changingHardLimit =
false;
237 qDebug() <<
"Current limit" << lim.rlim_cur << lim.rlim_max;
239 if (rlim_t(sockets) <= lim.rlim_cur) {
243 if (rlim_t(sockets) > lim.rlim_max) {
245 lim.rlim_max = sockets;
246 qDebug() <<
"Setting rlim_max to" << sockets;
247 changingHardLimit =
true;
252 lim.rlim_cur = qMin(rlim_t(OPEN_MAX), lim.rlim_max);
255 lim.rlim_cur = lim.rlim_max;
257 if (setrlimit(RLIMIT_NOFILE, &lim) == 0) {
258 qDebug() <<
"limit set to" << lim.rlim_cur;
260 if (changingHardLimit) {
261 qDebug() <<
"WARNING: hard limit is not high enough";
263 qDebug() <<
"error calling setrlimit(" << lim.rlim_cur <<
"," << lim.rlim_max <<
") :" << strerror(errno);
274 d->m_portBeforeSuspend = serverPort();
275 d->m_addressBeforeSuspend = serverAddress();
279 if (d->m_threadPool) {
280 d->m_threadPool->disconnectSockets(
this);
281 }
else if (d->m_mainThreadSocketList) {
282 d->m_mainThreadSocketList->disconnectAll();
288 if (d->m_portBeforeSuspend == 0) {
289 qWarning(
"KDSoapServer: resume() called without calling suspend() first");
291 if (!listen(d->m_addressBeforeSuspend, d->m_portBeforeSuspend)) {
292 qWarning(
"KDSoapServer: failed to listen on %s port %d", qPrintable(d->m_addressBeforeSuspend.toString()), d->m_portBeforeSuspend);
294 d->m_portBeforeSuspend = 0;
300 QMutexLocker lock(&d->m_serverDataMutex);
301 d->m_wsdlFile = file;
302 d->m_wsdlPathInUrl = pathInUrl;
307 QMutexLocker lock(&d->m_serverDataMutex);
308 return d->m_wsdlFile;
313 QMutexLocker lock(&d->m_serverDataMutex);
314 return d->m_wsdlPathInUrl;
319 QMutexLocker lock(&d->m_serverDataMutex);
325 QMutexLocker lock(&d->m_serverDataMutex);
331 QMutexLocker lock(&d->m_serverDataMutex);
332 d->m_maxConnections = sockets;
337 QMutexLocker lock(&d->m_serverDataMutex);
338 return d->m_maxConnections;
343 QMutexLocker lock(&d->m_serverDataMutex);
349 QMutexLocker lock(&d->m_serverDataMutex);
350 return d->m_features;
356 return d->m_sslConfiguration;
361 d->m_sslConfiguration = config;
365 #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)