int m_threadId;\r
ReLogger m_threadLogger;\r
ReSlaveAppender* m_appender;\r
- ReThreadPool* m_starter;\r
+ ReThreadPool* m_pool;\r
#if defined __linux__\r
pthread_t m_threadInfo;\r
#elif defined __WIN32__\r
bool startThread(ReThread* thread);\r
bool waitForAlmostAll(int mayResist, int timeoutSec);\r
bool waitForDone(int timeoutSec);\r
+ /** Returns whether the threads should stop.\r
+ * @return <code>true</code>: all threads should stop\r
+ */\r
+ inline bool shouldStop() const {\r
+ return m_shouldStop;\r
+ }\r
+ /** Sets that the threads should stop.\r
+ */\r
+ inline void setShouldStop() {\r
+ m_shouldStop = true;\r
+ }\r
private:\r
bool insertThread(ReThread* thread);\r
private:\r
ReThread** m_threads;\r
int m_maxKillTimeSec;\r
ReMutex m_mutexThreads;\r
+ bool m_shouldStop;\r
};\r
#endif /* BASE_RETHREAD_HPP_ */\r
i18n("unknown command: $1 length: $2")).arg(command).arg(
m_received.length()).end();
}
- } while (rc != ReNetCommandHandler::PS_STOP);
+ } while (rc != ReNetCommandHandler::PS_STOP && ! m_shouldStop);
+ if (rc != ReNetCommandHandler::PS_STOP)
+ m_pool->setShouldStop();
close();
m_id = -1;
}
bool rc = false;
struct addrinfo hints;
struct addrinfo* addrInfo;
- ReThreadPool threadStarter(m_maxConnections + 1, m_logger);
+ ReThreadPool pool(m_maxConnections + 1, m_logger);
// first, load up address structs with getaddrinfo():
memset(&hints, 0, sizeof hints);
socklen_t lengthAddr = sizeof(struct sockaddr_in);
while ((clientSocket = accept(m_handleSocket,
(struct sockaddr *) &addrClient, &lengthAddr)) != 0) {
- m_logger->sayF(LOG_INFO | CAT_NETWORK, LC_LISTEN_FOR_ALL_4,
- i18n("accepted: $1")).arg(m_port).end();
- if (m_countConnections >= m_maxConnections) {
- // close the connection atonce:
- m_logger->sayF(LOG_WARNING | CAT_NETWORK,
- LC_LISTEN_FOR_ALL_5,
- i18n("connection refused (too many connections): $1"))
- .arg(m_port).end();
- reCloseSocket(clientSocket);
- } else {
- pthread_t sniffer_thread;
- ReTCPServerConnection* connection = createConnection(
- nextId++, clientSocket, addrClient);
-
- if (!threadStarter.startThread(connection)) {
- m_logger->sayF(LOG_ERROR | CAT_PROCESS,
- LC_LISTEN_FOR_ALL_6,
- i18n("cannot create a thread: $1")).arg(
- getLastOSError()).end();
+ if (! pool.shouldStop()) {
+ m_logger->sayF(LOG_INFO | CAT_NETWORK, LC_LISTEN_FOR_ALL_4,
+ i18n("accepted: $1")).arg(m_port).end();
+ if (m_countConnections >= m_maxConnections) {
+ // close the connection at once:
+ m_logger->sayF(LOG_WARNING | CAT_NETWORK,
+ LC_LISTEN_FOR_ALL_5,
+ i18n(
+ "connection refused (too many connections): $1"))
+ .arg(m_port).end();
reCloseSocket(clientSocket);
- clientSocket = -1;
+ } else {
+ ReTCPServerConnection* connection = createConnection(
+ nextId++, clientSocket, addrClient);
+
+ if (!pool.startThread(connection)) {
+ m_logger->sayF(LOG_ERROR | CAT_PROCESS,
+ LC_LISTEN_FOR_ALL_6,
+ i18n("cannot create a thread: $1")).arg(
+ getLastOSError()).end();
+ reCloseSocket(clientSocket);
+ clientSocket = -1;
+ }
}
-
- //Now join the thread , so that we dont terminate before the thread
- //pthread_join( sniffer_thread , NULL);
- puts("Handler assigned");
}
}
- if (clientSocket < 0) {
- perror("accept failed");
- return 1;
+ if (pool.shouldStop()) {
+ m_logger->say(LOG_INFO | CAT_PROCESS, LC_LISTEN_FOR_ALL_7,
+ i18n("stop request received"));
}
}
}