From: <eg...@us...> - 2007-05-17 12:04:36
|
Revision: 471 http://svn.sourceforge.net/opengate/?rev=471&view=rev Author: egore Date: 2007-05-17 05:04:38 -0700 (Thu, 17 May 2007) Log Message: ----------- Try to add a server shutdown ... but it segfaults :-/ Modified Paths: -------------- branches/ogsector/src/Sector.h branches/ogsector/src/networkProtocol.h branches/ogsector/src/networkServer.cpp branches/ogsector/src/opengateclient.cpp branches/ogsector/src/opengateserver.cpp Modified: branches/ogsector/src/Sector.h =================================================================== --- branches/ogsector/src/Sector.h 2007-05-17 09:23:30 UTC (rev 470) +++ branches/ogsector/src/Sector.h 2007-05-17 12:04:38 UTC (rev 471) @@ -79,7 +79,7 @@ void selectPrevTarget( SectorObject * obj = NULL ); SectorObject * nextTarget( ); - + SectorObject * prevTarget( ); void sendAllVesselInfos( ); Modified: branches/ogsector/src/networkProtocol.h =================================================================== --- branches/ogsector/src/networkProtocol.h 2007-05-17 09:23:30 UTC (rev 470) +++ branches/ogsector/src/networkProtocol.h 2007-05-17 12:04:38 UTC (rev 471) @@ -18,8 +18,8 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef NETWORK_PROTOCOL__H -#define NETWORK_PROTOCOL__H +#ifndef _OPENGATE_NETWORK_PROTOCOL__H +#define _OPENGATE_NETWORK_PROTOCOL__H #include <Ogre.h> @@ -65,12 +65,20 @@ count += sizeof( T ); } +/*! + * \brief This is the class that every MessageBody (which is transfered over the + * network) should inherit from + * \author Carsten <spo...@us...> + */ class MessageBodyBase{ public: + + /*! Constructor */ MessageBodyBase( ) : type_( 0 ), senderID_( 0 ) { type_ = (Uint8)PROTO_BASE; } + /*! Constructor with data */ MessageBodyBase( const char * data ) : type_( 0 ), senderID_( 0 ) { type_ = (Uint8)PROTO_BASE; int count = 0; @@ -78,6 +86,7 @@ readFromData( senderID_, data, count ); } + /*! Destructor */ virtual ~MessageBodyBase(){ } virtual char * data() { @@ -114,6 +123,11 @@ std::string outData_; }; + +/*! + * \brief This class encapsulates the User ID to send it over the network + * \author Carsten <spo...@us...> + */ class MessageBodyUserID : public MessageBodyBase{ public: MessageBodyUserID( Uint32 userID ) : MessageBodyBase(), userID_( userID ){ @@ -140,6 +154,10 @@ Uint32 userID_; }; +/*! + * \brief This class encapsulates the disconnect event + * \author Carsten <spo...@us...> + */ class MessageBodyDisconnect : public MessageBodyUserID{ public: MessageBodyDisconnect( Uint32 userID ) : MessageBodyUserID( userID ){ @@ -152,6 +170,10 @@ protected: }; +/*! + * \brief This class encapsulates the username + * \author Carsten <spo...@us...> + */ class MessageBodyUserName : public MessageBodyBase{ public: MessageBodyUserName( const std::string & username, Uint32 senderID = 0 ) : MessageBodyBase(), username_( username ){ @@ -183,6 +205,10 @@ std::string username_; }; +/*! + * \brief This class encapsulates the event when a connection was refused + * \author Carsten <spo...@us...> + */ class MessageBodyConnectionRefused : public MessageBodyBase{ public: MessageBodyConnectionRefused( Uint8 reason ) : MessageBodyBase(), reason_( reason ){ @@ -207,6 +233,10 @@ Uint8 reason_; }; +/*! + * \brief This class encapsulates the chat events + * \author Carsten <spo...@us...> + */ class MessageBodyChat : public MessageBodyBase { public: MessageBodyChat( const std::string & message ) : MessageBodyBase(), message_( message ) { @@ -241,6 +271,10 @@ std::string message_; }; +/*! + * \brief This abstract class encapsulates the event happening on/with a vessel + * \author Carsten <spo...@us...> + */ class MessageBodyShipBase : public MessageBodyBase { public: MessageBodyShipBase( Uint8 childID ) @@ -547,5 +581,5 @@ } // namespace OpenGate -#endif //NETWORK_PROTOCOL__H +#endif // _OPENGATE_NETWORK_PROTOCOL__H Modified: branches/ogsector/src/networkServer.cpp =================================================================== --- branches/ogsector/src/networkServer.cpp 2007-05-17 09:23:30 UTC (rev 470) +++ branches/ogsector/src/networkServer.cpp 2007-05-17 12:04:38 UTC (rev 471) @@ -37,14 +37,16 @@ acceptor_.set_option( asio::ip::tcp::acceptor::reuse_address( true ) ); acceptor_.bind( endpoint ); acceptor_.listen(); - + UserSession * newUser = new UserSession( this, userIDCounter_ ); acceptor_.async_accept( newUser->socket(), boost::bind( & Server::handleAccept, this, newUser, asio::placeholders::error ) ); } - + Server::~Server(){ + // TODO: necessary? delete(newUser); + segfaults: acceptor_.close(); } void Server::handleAccept( UserSession * user, const asio::error & error ){ Modified: branches/ogsector/src/opengateclient.cpp =================================================================== --- branches/ogsector/src/opengateclient.cpp 2007-05-17 09:23:30 UTC (rev 470) +++ branches/ogsector/src/opengateclient.cpp 2007-05-17 12:04:38 UTC (rev 471) @@ -37,6 +37,8 @@ OpenGate::LogManager *log = new OpenGate::LogManager(); log->setLogFile( "OpenGate.log" ); log->setChatLogFile( "OpenGateChat.log" ); + log->info("Starting up"); + log->info(PACKAGE_STRING); std::string username = "testuser"; std::string hostname = "localhost"; Modified: branches/ogsector/src/opengateserver.cpp =================================================================== --- branches/ogsector/src/opengateserver.cpp 2007-05-17 09:23:30 UTC (rev 470) +++ branches/ogsector/src/opengateserver.cpp 2007-05-17 12:04:38 UTC (rev 471) @@ -23,6 +23,7 @@ #endif #include <iostream> +#include <signal.h> #include "common.h" #include "networkServer.h" @@ -30,27 +31,61 @@ using namespace OpenGate; +LogManager *logMgr = 0; +asio::io_service *io_servicePtr = 0; +Server *serverPtr = 0; + +void server_shutdown() { + /* TODO: sefaults + if (serverPtr) { + delete(serverPtr); + } + if (io_servicePtr) { + io_servicePtr->interrupt(); + }*/ +} + +void signal_term(int singal) { + logMgr->info("SIG_TERM received... exiting!"); + server_shutdown(); + exit(0); +} + +void signal_interrupt(int singal) { + logMgr->info("SIG_INT received... exiting!"); + server_shutdown(); + exit(0); +} + int main( int argc, char *argv[] ) { - LogManager *log = new LogManager( ); - log->setLogFile( "OGserver.log" ); - log->setChatLogFile( "OGserverChat.log" ); + logMgr = new LogManager( ); + logMgr->setLogFile( "OGserver.log" ); + logMgr->setChatLogFile( "OGserverChat.log" ); + logMgr->info("Starting up"); + logMgr->info(PACKAGE_STRING); - std::cout << "Starting up" << std::endl; - std::cout << "-----------" << std::endl; + signal(SIGTERM, signal_term); + signal(SIGINT, signal_interrupt); try { asio::io_service io_service; + io_servicePtr = &io_service; tcp::endpoint endpoint( tcp::v4(), OG_PORT ); Server server( io_service, endpoint ); - + serverPtr = &server; + io_service.run(); } catch ( asio::error & e ) { - log->fatal( e.what() ); + logMgr->fatal( e.what() ); + server_shutdown(); + return EXIT_FAILURE; } catch ( std::exception & e ) { - log->fatal( std::string("Exception: ") + e.what() ); - } + logMgr->fatal( std::string("Exception: ") + e.what() ); + server_shutdown(); + return EXIT_FAILURE; + } return EXIT_SUCCESS; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |