[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[myserver-commit] [2844] Fixed a problem with reboots.
From: |
Giuseppe Scrivano |
Subject: |
[myserver-commit] [2844] Fixed a problem with reboots. |
Date: |
Sat, 27 Sep 2008 11:27:42 +0000 |
Revision: 2844
http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=2844
Author: gscrivano
Date: 2008-09-27 11:27:41 +0000 (Sat, 27 Sep 2008)
Log Message:
-----------
Fixed a problem with reboots. Some dependencies to the `Server' singleton
instance were removed.
Modified Paths:
--------------
trunk/myserver/include/server/clients_thread.h
trunk/myserver/include/server/server.h
trunk/myserver/src/connections_scheduler/connections_scheduler.cpp
trunk/myserver/src/server/clients_thread.cpp
trunk/myserver/src/server/server.cpp
trunk/myserver/tests/test_connection.cpp
Modified: trunk/myserver/include/server/clients_thread.h
===================================================================
--- trunk/myserver/include/server/clients_thread.h 2008-09-26 23:47:27 UTC
(rev 2843)
+++ trunk/myserver/include/server/clients_thread.h 2008-09-27 11:27:41 UTC
(rev 2844)
@@ -22,50 +22,53 @@
#include <include/base/utility.h>
#include <include/connection/connection.h>
#include <include/conf/security/security.h>
-#include <include/protocol/http/http.h>
#include <include/base/mem_buff/mem_buff.h>
-#include <include/protocol/https/https.h>
-#include <include/protocol/control/control_protocol.h>
-class Ftp;
+class FtpParser;
+class HttpProtocol;
+class HttpsProtocol;
+class ControlProtocol;
+class Server;
+
+
class ClientsThread
{
- friend class Server;
+ friend class Server;
#ifdef WIN32
- friend unsigned int __stdcall clients_thread(void* pParam);
+ friend unsigned int __stdcall clients_thread(void* pParam);
#endif
#ifdef HAVE_PTHREAD
- friend void* clients_thread(void* pParam);
+ friend void* clients_thread(void* pParam);
#endif
public:
- enum RETURN_CODE
- {
- /*!
- *Delete the current connection from the connections pool.
- */
- DELETE_CONNECTION = 0,
- /*!
- *Keep the connection in the connections pool waiting for new
data.
- */
- KEEP_CONNECTION = 1,
- /*!
- *The request present in the connection buffer is not complete,
keep
- *data in the buffer and append to it.
- */
- INCOMPLETE_REQUEST = 2,
- /*!
- *The request present in the buffer is not complete, append to
the buffer
- *and check before new data is present.
- */
- INCOMPLETE_REQUEST_NO_WAIT = 3
- };
- MemBuf *getBuffer();
- MemBuf *getBuffer2();
- ClientsThread();
- ~ClientsThread();
- void stop();
+ enum RETURN_CODE
+ {
+ /*!
+ *Delete the current connection from the connections pool.
+ */
+ DELETE_CONNECTION = 0,
+ /*!
+ *Keep the connection in the connections pool waiting for new data.
+ */
+ KEEP_CONNECTION = 1,
+ /*!
+ *The request present in the connection buffer is not complete, keep
+ *data in the buffer and append to it.
+ */
+ INCOMPLETE_REQUEST = 2,
+ /*!
+ *The request present in the buffer is not complete, append to the buffer
+ *and check before new data is present.
+ */
+ INCOMPLETE_REQUEST_NO_WAIT = 3
+ };
+ MemBuf *getBuffer();
+ MemBuf *getBuffer2();
+ ClientsThread(Server* server);
+ ~ClientsThread();
+ void stop();
int getTimeout();
void setTimeout(int);
int isToDestroy();
@@ -73,31 +76,34 @@
int isStatic();
int isBusy();
void setStatic(int);
- int run();
- ThreadID getThreadId(){return tid;}
+ int run();
+ ThreadID getThreadId(){return tid;}
int join();
+
+
private:
- ThreadID tid;
+ Server* server;
+ ThreadID tid;
int toDestroy;
int timeout;
- int initialized;
+ int initialized;
int staticThread;
- u_long id;
+ u_long id;
int busy;
- int threadIsStopped;
- int threadIsRunning;
- u_long buffersize;
- u_long buffersize2;
- int isRunning();
- int isStopped();
- HttpProtocol* httpParser;
- HttpsProtocol* httpsParser;
- ControlProtocol *controlProtocolParser;
- Ftp *ftpParser;
- MemBuf buffer;
- MemBuf buffer2;
- int controlConnections();
- u_long nBytesToRead;
+ int threadIsStopped;
+ int threadIsRunning;
+ u_long buffersize;
+ u_long buffersize2;
+ int isRunning();
+ int isStopped();
+ FtpParser *ftpParser;
+ HttpProtocol* httpParser;
+ HttpsProtocol* httpsParser;
+ ControlProtocol *controlProtocolParser;
+ MemBuf buffer;
+ MemBuf buffer2;
+ int controlConnections();
+ u_long nBytesToRead;
};
#ifdef WIN32
Modified: trunk/myserver/include/server/server.h
===================================================================
--- trunk/myserver/include/server/server.h 2008-09-26 23:47:27 UTC (rev
2843)
+++ trunk/myserver/include/server/server.h 2008-09-27 11:27:41 UTC (rev
2844)
@@ -60,8 +60,6 @@
void* listenServer(void* pParam);
#endif
-extern int rebootMyServerConsole;
-
class Server : public MulticastRegistry<string, void*, int>
{
public:
@@ -93,12 +91,12 @@
int countAvailableThreads();
void checkThreadsNumber();
int removeThread(u_long ID);
- int isServerReady();
+ bool isServerReady();
ProtocolsManager* getProtocolsManager();
void disableAutoReboot();
void enableAutoReboot();
- int isAutorebootEnabled();
- int isRebooting(){return rebooting;}
+ bool isAutorebootEnabled();
+ bool isRebooting(){return rebooting;}
void rebootOnNextLoop();
const char* getMainConfFile();
const char* getVhostConfFile();
@@ -150,10 +148,12 @@
void setProcessPermissions();
ConnectionsScheduler* getConnectionsScheduler(){return
&connectionsScheduler;}
- int deleteConnection(ConnectionPtr, int);
+ int deleteConnection(ConnectionPtr);
void increaseFreeThread();
void decreaseFreeThread();
+
+
private:
friend class ClientsThread;
#ifdef WIN32
@@ -177,6 +177,7 @@
void mainLoop();
void loadPlugins();
void displayBoot();
+ int postLoad();
CachedFileFactory cachedFiles;
@@ -193,16 +194,16 @@
u_long uid;
u_long gid;
int currentThreadID;
- /*! Used when rebooting to load new configuration files. */
- int pausing;
ProtocolsManager protocols;
XmlParser configurationFileManager;
XmlParser languageParser;
- int autoRebootEnabled;
- int toReboot;
- int rebooting;
+
+ bool autoRebootEnabled;
+ bool toReboot;
+ bool rebooting;
+
LogManager logManager;
- int serverReady;
+ bool serverReady;
u_long verbosity;
u_long throttlingRate;
u_long buffersize;
@@ -214,7 +215,7 @@
string* externalPath;
string* serverAdmin;
int initialize();
- int addThread(int staticThread = 0);
+ int addThread(bool staticThread = false);
ConnectionPtr addConnectionToList(Socket* s, MYSERVER_SOCKADDRIN *asock_in,
char *ipAddr, char *localIpAddr,
u_short port, u_short localPort, int);
Modified: trunk/myserver/src/connections_scheduler/connections_scheduler.cpp
===================================================================
--- trunk/myserver/src/connections_scheduler/connections_scheduler.cpp
2008-09-26 23:47:27 UTC (rev 2843)
+++ trunk/myserver/src/connections_scheduler/connections_scheduler.cpp
2008-09-27 11:27:41 UTC (rev 2844)
@@ -167,11 +167,15 @@
if(event == EV_TIMEOUT)
{
- server->deleteConnection(connection, 0);
+ if(!connection->allowDelete())
+ return;
+
+ server->deleteConnection(connection);
+ removeConnection(connection);
}
else if(event == EV_READ)
{
- server->getConnectionsScheduler()->addReadyConnection(connection);
+ addReadyConnection(connection);
}
}
@@ -207,7 +211,7 @@
event_once(handle, EV_READ | EV_TIMEOUT, newDataHandler, da, &tv);
}
if(cmd == 'r')
- break;
+ return;
/* Handle other cmd without do anything else. */
}
@@ -587,6 +591,8 @@
if(dispatchedThreadId)
Thread::join(dispatchedThreadId);
+ terminateConnections();
+
eventsMutex.lock();
list<ListenerArg*>::iterator it = listeners.begin();
@@ -606,8 +612,6 @@
listeners.clear();
eventsMutex.unlock();
-
- terminateConnections();
}
/*!
@@ -645,6 +649,7 @@
if(connection->socket)
connections.remove(connection->socket->getHandle());
connectionsMutex.unlock();
+ delete connection;
}
/*!
@@ -662,7 +667,7 @@
for(; it != connections.end(); it++)
{
ConnectionPtr c = *it;
- if ( c->allowDelete(true) && c->socket)
+ if (c->allowDelete(true) && c->socket)
c->socket->close();
}
}
Modified: trunk/myserver/src/server/clients_thread.cpp
===================================================================
--- trunk/myserver/src/server/clients_thread.cpp 2008-09-26 23:47:27 UTC
(rev 2843)
+++ trunk/myserver/src/server/clients_thread.cpp 2008-09-27 11:27:41 UTC
(rev 2844)
@@ -16,15 +16,18 @@
*/
#include "stdafx.h"
+#include <include/server/clients_thread.h>
+
#include <include/base/thread/thread.h>
#include <include/server/server.h>
-#include <include/server/clients_thread.h>
#include <include/conf/security/security.h>
-#include <include/protocol/http/http_request.h>
-#include <include/protocol/http/http_response.h>
#include <include/base/socket/socket.h>
#include <include/base/string/stringutils.h>
+
+#include <include/protocol/http/http.h>
#include <include/base/mem_buff/mem_buff.h>
+#include <include/protocol/https/https.h>
+#include <include/protocol/control/control_protocol.h>
#include <include/protocol/ftp/ftp.h>
#ifdef NOT_WIN
@@ -48,13 +51,15 @@
/*!
*Construct the object.
*/
-ClientsThread::ClientsThread()
+ClientsThread::ClientsThread(Server* server)
{
+ this->server = server;
busy = 0;
initialized = 0;
toDestroy = 0;
staticThread = 0;
nBytesToRead = 0;
+
httpParser = 0;
httpsParser = 0;
controlProtocolParser = 0;
@@ -124,8 +129,6 @@
#endif
{
- Server* server = Server::getInstance();
-
#ifdef NOT_WIN
/* Block SigTerm, SigInt, and SigPipe in threads. */
sigset_t sigmask;
@@ -148,8 +151,8 @@
ct->threadIsRunning = 1;
ct->threadIsStopped = 0;
- ct->buffersize = server->getInstance()->getBuffersize();
- ct->buffersize2 = server->getInstance()->getBuffersize2();
+ ct->buffersize = ct->server->getBuffersize();
+ ct->buffersize2 = ct->server->getBuffersize2();
ct->buffer.setLength(ct->buffersize);
ct->buffer.m_nSizeLimit = ct->buffersize;
@@ -163,11 +166,10 @@
ct->initialized = 1;
- Server::getInstance()->increaseFreeThread();
+ ct->server->increaseFreeThread();
-
/* Wait that the server is ready before go in the running loop. */
- while(!server->isServerReady() && ct->threadIsRunning)
+ while(!ct->server->isServerReady() && ct->threadIsRunning)
{
Thread::wait(500);
}
@@ -191,7 +193,7 @@
}
ret = ct->controlConnections();
- Server::getInstance()->increaseFreeThread();
+ ct->server->increaseFreeThread();
ct->busy = 0;
/*
@@ -207,23 +209,24 @@
ostringstream s;
s << "Bad alloc: " << ba.what();
- Server::getInstance()->logPreparePrintError();
- Server::getInstance()->logWriteln(s.str().c_str());
- Server::getInstance()->logEndPrintError();
+ ct->server->logPreparePrintError();
+ ct->server->logWriteln(s.str().c_str());
+ ct->server->logEndPrintError();
}
catch( exception &e)
{
ostringstream s;
s << "Error: " << e.what();
- Server::getInstance()->logPreparePrintError();
- Server::getInstance()->logWriteln(s.str().c_str());
- Server::getInstance()->logEndPrintError();
+ ct->server->logPreparePrintError();
+ ct->server->logWriteln(s.str().c_str());
+ ct->server->logEndPrintError();
};
}
- Server::getInstance()->decreaseFreeThread();
+ ct->server->decreaseFreeThread();
+
delete ct;
Thread::terminate();
@@ -303,10 +306,11 @@
Protocol* protocol = 0;
u_long dataRead = 0;
- c = Server::getInstance()->getConnection(this->id);
- Server::getInstance()->decreaseFreeThread();
+ c = server->getConnection(this->id);
+ server->decreaseFreeThread();
+
/*
*Check if c is a valid connection structure.
*/
@@ -319,7 +323,7 @@
err = c->socket->recv(&((char*)(buffer.getBuffer()))[dataRead],
MYSERVER_KB(8) - dataRead - 1, 0);
- if(err == -1 && !Server::getInstance()->deleteConnection(c, this->id))
+ if(err == -1 && !server->deleteConnection(c))
return 0;
buffer.setLength(dataRead + err);
@@ -336,7 +340,7 @@
}
else
{
- Server::getInstance()->deleteConnection(c, this->id);
+ server->deleteConnection(c);
return 0;
}
@@ -365,7 +369,7 @@
}
else
{
- protocol =
Server::getInstance()->getProtocol(c->host->getProtocolName());
+ protocol = server->getProtocol(c->host->getProtocolName());
if(protocol)
{
retcode = protocol->controlConnection(c,
@@ -388,14 +392,14 @@
/*! Delete the connection. */
if(retcode == DELETE_CONNECTION)
{
- Server::getInstance()->deleteConnection(c, this->id);
+ server->deleteConnection(c);
return 0;
}
/*! Keep the connection. */
else if(retcode == KEEP_CONNECTION)
{
c->connectionBuffer.setLength(0);
- Server::getInstance()->getConnectionsScheduler()->addWaitingConnection(c);
+ server->getConnectionsScheduler()->addWaitingConnection(c);
}
/*! Incomplete request to buffer. */
else if(retcode == INCOMPLETE_REQUEST)
@@ -406,13 +410,13 @@
*Save the header in the connection buffer.
*/
c->connectionBuffer.setBuffer(buffer.getBuffer(), nBytesToRead);
- Server::getInstance()->getConnectionsScheduler()->addWaitingConnection(c);
+ server->getConnectionsScheduler()->addWaitingConnection(c);
}
/* Incomplete request to check before new data is available. */
else if(retcode == INCOMPLETE_REQUEST_NO_WAIT)
{
c->setForceControl(1);
- Server::getInstance()->getConnectionsScheduler()->addReadyConnection(c);
+ server->getConnectionsScheduler()->addReadyConnection(c);
}
c->setTimeout( getTicks() );
Modified: trunk/myserver/src/server/server.cpp
===================================================================
--- trunk/myserver/src/server/server.cpp 2008-09-26 23:47:27 UTC (rev
2843)
+++ trunk/myserver/src/server/server.cpp 2008-09-27 11:27:41 UTC (rev
2844)
@@ -77,12 +77,11 @@
Server::Server() : connectionsScheduler(this),
listenThreads(&connectionsScheduler, this)
{
- toReboot = 0;
- autoRebootEnabled = 1;
- pausing = 0;
- rebooting = 0;
+ toReboot = false;
+ autoRebootEnabled = true;
+ rebooting = false;
maxConnections = 0;
- serverReady = 0;
+ serverReady = false;
throttlingRate = 0;
uid = 0;
gid = 0;
@@ -289,12 +288,8 @@
*/
void Server::start(string &mainConf, string &mimeConf, string &vhostConf,
string &externPath, string &langPath)
{
- u_long i;
- string buffer;
int err = 0;
int ret;
- ostringstream nCPU;
- string strCPU;
#ifdef WIN32
DWORD eventsCount, cNumRead;
INPUT_RECORD irInBuf[128];
@@ -328,101 +323,9 @@
logWriteln( languageParser.getValue("MSG_SERVER_CONF") );
- /*
- *Get the name of the local machine.
- */
- memset(serverName, 0, HOST_NAME_MAX+1);
- Socket::gethostname(serverName, HOST_NAME_MAX);
-
- buffer.assign(languageParser.getValue("MSG_GETNAME"));
- buffer.append(" ");
- buffer.append(serverName);
- logWriteln(buffer.c_str());
-
- /*
- *Find the IP addresses of the local machine.
- */
- if(ipAddresses)
- delete ipAddresses;
- ipAddresses = new string();
- buffer.assign("Host: ");
- buffer.append(serverName);
- logWriteln(buffer.c_str() );
-
- if(Socket::getLocalIPsList(*ipAddresses))
- {
- string msg;
- msg.assign(languageParser.getValue("ERR_ERROR"));
- msg.append(" : Reading IP list");
- logPreparePrintError();
- logWriteln(msg.c_str());
- logEndPrintError();
+ if(postLoad())
return;
- }
- else
- {
- string msg;
- msg.assign("IP: ");
- msg.append(*ipAddresses);
- logWriteln(msg.c_str());
- }
- /* Load the MIME types. */
- logWriteln(languageParser.getValue("MSG_LOADMIME"));
- if(mimeManager)
- delete mimeManager;
- mimeManager = new MimeManager();
-
- if(int nMIMEtypes = mimeManager->loadXML(mimeConfigurationFile->c_str()))
- {
- ostringstream stream;
- stream << languageParser.getValue("MSG_MIMERUN") << ": " << nMIMEtypes;
- logWriteln(stream.str().c_str());
- }
- else
- {
- logPreparePrintError();
- logWriteln(languageParser.getValue("ERR_LOADMIME"));
- logEndPrintError();
- }
-
- nCPU << (u_int)getCPUCount();
-
- strCPU.assign(languageParser.getValue("MSG_NUM_CPU"));
- strCPU.append(" ");
- strCPU.append(nCPU.str());
- logWriteln(strCPU.c_str());
-
- connectionsScheduler.restart();
-
- listenThreads.initialize(&languageParser);
-
- if(vhostList)
- delete vhostList;
-
- vhostList = new VhostManager(&listenThreads);
-
- if(vhostList == NULL)
- return;
-
- getProcessServerManager()->load();
-
- /* Load the home directories configuration. */
- homeDir.load();
-
- loadPlugins();
-
- /* Load the virtual hosts configuration from the xml file. */
- vhostList->loadXMLConfigurationFile(vhostConfigurationFile->c_str(),
- getMaxLogFileSize());
-
-
- if(path == 0)
- path = new string();
-
- if(getdefaultwd(*path))
- return;
-
setProcessPermissions();
if(getGid())
@@ -439,23 +342,12 @@
logWriteln(out.str().c_str());
}
- for(i = 0; i < nStaticThreads; i++)
- {
- logWriteln(languageParser.getValue("MSG_CREATET"));
- ret = addThread(1);
-
- if(ret)
- return;
-
- logWriteln(languageParser.getValue("MSG_THREADR"));
- }
-
logWriteln(languageParser.getValue("MSG_READY"));
if(logManager.getType() == LogManager::TYPE_CONSOLE)
logWriteln(languageParser.getValue("MSG_BREAK"));
- serverReady = 1;
+ serverReady = true;
/* Finally we can give control to the main loop. */
mainLoop();
@@ -482,6 +374,124 @@
}
/*!
+ *Complete the loading phase.
+ */
+int Server::postLoad()
+{
+ ostringstream nCPU;
+ string strCPU;
+ string buffer;
+
+ /*
+ *Get the name of the local machine.
+ */
+ memset(serverName, 0, HOST_NAME_MAX+1);
+ Socket::gethostname(serverName, HOST_NAME_MAX);
+
+ buffer.assign(languageParser.getValue("MSG_GETNAME"));
+ buffer.append(" ");
+ buffer.append(serverName);
+ logWriteln(buffer.c_str());
+
+ /*
+ *Find the IP addresses of the local machine.
+ */
+ if(ipAddresses)
+ delete ipAddresses;
+ ipAddresses = new string();
+ buffer.assign("Host: ");
+ buffer.append(serverName);
+ logWriteln(buffer.c_str() );
+
+ if(Socket::getLocalIPsList(*ipAddresses))
+ {
+ string msg;
+ msg.assign(languageParser.getValue("ERR_ERROR"));
+ msg.append(" : Reading IP list");
+ logPreparePrintError();
+ logWriteln(msg.c_str());
+ logEndPrintError();
+ return -1;
+ }
+ else
+ {
+ string msg;
+ msg.assign("IP: ");
+ msg.append(*ipAddresses);
+ logWriteln(msg.c_str());
+ }
+
+ /* Load the MIME types. */
+ logWriteln(languageParser.getValue("MSG_LOADMIME"));
+
+ if(mimeManager)
+ delete mimeManager;
+
+ mimeManager = new MimeManager();
+
+ if(int nMIMEtypes = mimeManager->loadXML(mimeConfigurationFile->c_str()))
+ {
+ ostringstream stream;
+ stream << languageParser.getValue("MSG_MIMERUN") << ": " << nMIMEtypes;
+ logWriteln(stream.str().c_str());
+ }
+ else
+ {
+ logPreparePrintError();
+ logWriteln(languageParser.getValue("ERR_LOADMIME"));
+ logEndPrintError();
+ }
+
+ nCPU << (u_int)getCPUCount();
+
+ strCPU.assign(languageParser.getValue("MSG_NUM_CPU"));
+ strCPU.append(" ");
+ strCPU.append(nCPU.str());
+ logWriteln(strCPU.c_str());
+
+ connectionsScheduler.restart();
+
+ listenThreads.initialize(&languageParser);
+
+ if(vhostList)
+ delete vhostList;
+
+ vhostList = new VhostManager(&listenThreads);
+
+ if(vhostList == NULL)
+ return -1;
+
+ getProcessServerManager()->load();
+
+ /* Load the home directories configuration. */
+ homeDir.load();
+
+ loadPlugins();
+
+ /* Load the virtual hosts configuration from the xml file. */
+ vhostList->loadXMLConfigurationFile(vhostConfigurationFile->c_str(),
+ getMaxLogFileSize());
+
+
+ if(path == 0)
+ path = new string();
+
+ if(getdefaultwd(*path))
+ return -1;
+
+ for(u_long i = 0; i < nStaticThreads; i++)
+ {
+ logWriteln(languageParser.getValue("MSG_CREATET"));
+ if(addThread(true))
+ return -1;
+
+ logWriteln(languageParser.getValue("MSG_THREADR"));
+ }
+
+ return 0;
+}
+
+/*!
*Load the plugins.
*/
void Server::loadPlugins()
@@ -625,10 +635,8 @@
listenThreads.terminate();
- connectionsScheduler.terminateConnections();
clearAllConnections();
-
Socket::stopBlockingOperations(false);
connectionsScheduler.restart();
@@ -918,7 +926,7 @@
if(verbosity > 1)
{
- logWriteln(languageParser.getValue("MSG_MEMCLEAN"));
+ logWriteln(languageParser.getValue("MSG_MEMCLEAN"));
}
freeHashedData();
@@ -931,15 +939,19 @@
languageParser.close();
if(mimeManager)
+ {
mimeManager->clean();
- delete mimeManager;
- mimeManager = 0;
+ delete mimeManager;
+ mimeManager = 0;
+ }
+
#ifdef WIN32
/*
*Under WIN32 cleanup environment strings.
*/
FreeEnvironmentStrings((LPTSTR)envString);
#endif
+
getProcessServerManager()->clear();
filtersFactory.free();
@@ -1010,7 +1022,7 @@
if(serverAdmin)
delete serverAdmin;
serverAdmin = 0;
- autoRebootEnabled = 1;
+ autoRebootEnabled = false;
if(configurationFileManager.open(mainConfigurationFile->c_str()))
return -1;
@@ -1207,9 +1219,8 @@
*we did not reach the limit.
*/
if((threads.size() < nMaxThreads) && (freeThreads < 1))
- {
- addThread(0);
- }
+ addThread(false);
+
threadsMutex->unlock();
}
@@ -1472,22 +1483,13 @@
}
/*!
- *Delete a connection from the list.
+ *Get notified when a connection is closed.
*/
-int Server::deleteConnection(ConnectionPtr s, int /*id*/)
+int Server::deleteConnection(ConnectionPtr s)
{
string msg("remove-connection");
vector<Multicast<string, void*, int>*>* handlers;
- int ret = 0;
- /*
- *Remove the connection from the active connections list.
- */
- if(!s || !s->allowDelete())
- {
- return 0;
- }
-
handlers = getHandlers(msg);
if(handlers)
@@ -1497,12 +1499,7 @@
(*handlers)[i]->updateMulticast(this, msg, s);
}
}
-
- connectionsScheduler.removeConnection(s);
-
- delete s;
-
- return ret;
+ return 0;
}
/*!
@@ -1527,7 +1524,7 @@
{
for(it = connections.begin(); it != connections.end(); it++)
{
- deleteConnection(*it, 1);
+ deleteConnection(*it);
}
}
catch(...)
@@ -1673,7 +1670,7 @@
logWriteln(out.str().c_str());
logEndPrintError();
}
- autoRebootEnabled = 0;
+ autoRebootEnabled = false;
}
/*
@@ -1691,7 +1688,7 @@
logWriteln(out.str().c_str());
logEndPrintError();
}
- autoRebootEnabled = 0;
+ autoRebootEnabled = false;
}
}
@@ -1727,16 +1724,14 @@
if(handlers)
{
for(size_t i = 0; i < handlers->size(); i++)
- {
(*handlers)[i]->updateMulticast(this, msg, 0);
- }
}
- serverReady = 0;
+ serverReady = false;
/* Reset the toReboot flag. */
- toReboot = 0;
+ toReboot = false;
- rebooting = 1;
+ rebooting = true;
/* Do nothing if the reboot is disabled. */
if(!autoRebootEnabled)
@@ -1761,13 +1756,14 @@
mustEndServer = false;
- rebooting = 0;
+ rebooting = false;
- ret = initialize();
+ ret = initialize() || postLoad();
if(ret)
return ret;
+ serverReady = true;
logWriteln("Rebooted");
@@ -1777,7 +1773,7 @@
/*!
*Returns if the server is ready.
*/
-int Server::isServerReady()
+bool Server::isServerReady()
{
return serverReady;
}
@@ -1787,8 +1783,8 @@
*/
void Server::rebootOnNextLoop()
{
- serverReady = 0;
- toReboot = 1;
+ serverReady = false;
+ toReboot = true;
}
@@ -1838,7 +1834,7 @@
*/
void Server::disableAutoReboot()
{
- autoRebootEnabled = 0;
+ autoRebootEnabled = false;
}
/*!
@@ -1846,7 +1842,7 @@
*/
void Server::enableAutoReboot()
{
- autoRebootEnabled = 1;
+ autoRebootEnabled = true;
}
@@ -1877,7 +1873,7 @@
/*!
*Return nonzero if the autoreboot is enabled.
*/
-int Server::isAutorebootEnabled()
+bool Server::isAutorebootEnabled()
{
return autoRebootEnabled;
}
@@ -1885,7 +1881,7 @@
/*!
*Create a new thread.
*/
-int Server::addThread(int staticThread)
+int Server::addThread(bool staticThread)
{
int ret;
string msg("new-thread");
@@ -1916,7 +1912,7 @@
return 0;
}
- newThread = new ClientsThread();
+ newThread = new ClientsThread(this);
if(newThread == 0)
return -1;
@@ -1949,9 +1945,6 @@
return -1;
}
- /*
- *If everything was done correctly add the new thread to the linked list.
- */
threads.push_back(newThread);
return 0;
}
Modified: trunk/myserver/tests/test_connection.cpp
===================================================================
--- trunk/myserver/tests/test_connection.cpp 2008-09-26 23:47:27 UTC (rev
2843)
+++ trunk/myserver/tests/test_connection.cpp 2008-09-27 11:27:41 UTC (rev
2844)
@@ -92,7 +92,7 @@
void testActiveThread()
{
- ClientsThread *ct = new ClientsThread();
+ ClientsThread *ct = new ClientsThread(NULL);
connection->setActiveThread(ct);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [myserver-commit] [2844] Fixed a problem with reboots.,
Giuseppe Scrivano <=