From: <ps...@us...> - 2008-12-10 15:53:11
|
Revision: 1288 http://znc.svn.sourceforge.net/znc/?rev=1288&view=rev Author: psychon Date: 2008-12-10 15:53:07 +0000 (Wed, 10 Dec 2008) Log Message: ----------- Update to latest Csocket and use its new init interface Modified Paths: -------------- trunk/Csocket.cpp trunk/Csocket.h trunk/main.cpp trunk/znc.cpp Modified: trunk/Csocket.cpp =================================================================== --- trunk/Csocket.cpp 2008-12-09 20:25:34 UTC (rev 1287) +++ trunk/Csocket.cpp 2008-12-10 15:53:07 UTC (rev 1288) @@ -28,7 +28,7 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * -* $Revision: 1.89 $ +* $Revision: 1.90 $ */ #include "Csocket.h" @@ -311,7 +311,32 @@ return( ETIMEDOUT ); } +bool InitCsocket() +{ +#ifdef _WIN32 + WSADATA wsaData; + int iResult = WSAStartup( MAKEWORD( 2, 2 ), &wsaData ); + if( iResult != NO_ERROR ) + return( false ); +#endif /* _WIN32 */ #ifdef HAVE_LIBSSL + if( !InitSSL() ) + return( false ); +#endif /* HAVE_LIBSSL */ + return( true ); +} + +void ShutdownCsocket() +{ +#ifdef HAVE_LIBSSL + ERR_free_strings(); +#endif /* HAVE_LIBSSL */ +#ifdef _WIN32 + WSACleanup(); +#endif /* _WIN32 */ +} + +#ifdef HAVE_LIBSSL bool InitSSL( ECompType eCompressionType ) { SSL_load_error_strings(); Modified: trunk/Csocket.h =================================================================== --- trunk/Csocket.h 2008-12-09 20:25:34 UTC (rev 1287) +++ trunk/Csocket.h 2008-12-10 15:53:07 UTC (rev 1288) @@ -28,7 +28,7 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * -* $Revision: 1.199 $ +* $Revision: 1.200 $ */ // note to compile with win32 need to link to winsock2, using gcc its -lws2_32 @@ -261,15 +261,27 @@ CT_RLE = 2 }; +void SSLErrors( const char *filename, u_int iLineNum ); + /** - * @brief You HAVE to call this in order to use the SSL library + * @brief You HAVE to call this in order to use the SSL library, calling InitCsocket() also calls this + * so unless you need to call InitSSL for a specific reason call InitCsocket() * @return true on success */ bool InitSSL( ECompType eCompressionType = CT_NONE ); -void SSLErrors( const char *filename, u_int iLineNum ); + #endif /* HAVE_LIBSSL */ +/** + * This does all the csocket initialized inclusing InitSSL() and win32 specific initializations, only needs to be called once + */ +bool InitCsocket(); +/** + * Shutdown and release global allocated memory + */ +void ShutdownCsocket(); + //! @todo need to make this sock specific via getsockopt inline int GetSockError() { @@ -280,27 +292,6 @@ #endif /* _WIN32 */ } -#ifdef _WIN32 -inline bool InitWin32() -{ - WSADATA wsaData; - int iResult = WSAStartup( MAKEWORD( 2, 2 ), &wsaData ); - if( iResult != NO_ERROR ) - return( false ); - - return( true ); -} -inline void ShutdownWin32() -{ - WSACleanup(); -} -#define InitCsocket InitWin32 -#define ShutdownCsocket ShutdownWin32 -#else -#define InitCsocket (void)0 -#define ShutdownCsocket (void)0 -#endif /* _WIN32 */ - //! wrappers for FD_SET and such to work in templates. inline void TFD_ZERO( fd_set *set ) { Modified: trunk/main.cpp =================================================================== --- trunk/main.cpp 2008-12-09 20:25:34 UTC (rev 1287) +++ trunk/main.cpp 2008-12-10 15:53:07 UTC (rev 1288) @@ -74,10 +74,6 @@ srand(time(NULL)); CUtils::SetStdoutIsTTY(isatty(1)); -#ifdef HAVE_LIBSSL - InitSSL(); -#endif /* HAVE_LIBSSL */ - int iArg, iOptIndex = -1; bool bMakeConf = false; bool bMakePass = false; Modified: trunk/znc.cpp =================================================================== --- trunk/znc.cpp 2008-12-09 20:25:34 UTC (rev 1287) +++ trunk/znc.cpp 2008-12-10 15:53:07 UTC (rev 1288) @@ -26,6 +26,11 @@ }; CZNC::CZNC() { + if (!InitCsocket()) { + CUtils::PrintError("Failed to initialize Csocket!"); + exit(-1); + } + #ifdef _MODULES m_pModules = new CGlobalModules(); #endif @@ -68,6 +73,7 @@ delete m_pModules; #endif + ShutdownCsocket(); DeletePidFile(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |