From e9aead94351153cd98d91383cad56ff01b10efa7 Mon Sep 17 00:00:00 2001 From: upstream svn Date: Thu, 4 Jun 2009 08:28:19 +0200 Subject: [PATCH] Upstream tarball 9627 --- .svn-revision | 2 +- docs/Changelog | 4 ++- src/amule.h | 66 +++++++++++++++++++++++++------------ src/amuled.cpp | 102 +++++++++++++++++++++++++++++++++++++-------------------- 4 files changed, 115 insertions(+), 59 deletions(-) diff --git a/.svn-revision b/.svn-revision index 699dbbf5..376aea0c 100644 --- a/.svn-revision +++ b/.svn-revision @@ -1 +1 @@ -9626 +9627 diff --git a/docs/Changelog b/docs/Changelog index 6ad66f29..fdfcf8cf 100644 --- a/docs/Changelog +++ b/docs/Changelog @@ -66,7 +66,9 @@ Version 2.3.0 - The river knows. * Reduce file handle usage by closing part files after idle time * Speed up selection of shared directories with many subdirectories, fixed red marking of folders with shared subdirectories - * Ported CorruptionBlackBox from eMule + * Ban clients that uploaded bad data (based on CorruptionBlackBox from eMule) + * Support wxWidgets 2.9 + * amuled for Windows (with wx 2.9) Vollstrecker: * Unify copyright lines diff --git a/src/amule.h b/src/amule.h index de339866..6db94b6b 100644 --- a/src/amule.h +++ b/src/amule.h @@ -376,11 +376,24 @@ DECLARE_APP(CamuleGuiApp) #else /* ! AMULE_DAEMON */ +// wxWidgets 2.8 requires special code for event handling and sockets. +// 2.9 doesn't, so standard event loop and sockets can be used +// +// Windows: aMuled compiles with 2.8 (without the special code), +// but works only with 2.9 + +#if !wxCHECK_VERSION(2, 9, 0) + #ifdef __WXMSW__ + // MSW: can't run amuled with 2.8 anyway, just get it compiled + #define AMULED_DUMMY + #else + #define AMULED28 + #endif +#endif -#include +#ifdef AMULED28 #include - class CSocketSet; @@ -409,20 +422,25 @@ public: }; +#endif // AMULED28 + +// no AppTraits used on Windows +#ifndef __WXMSW__ + typedef std::map EndProcessDataMap; +#include class CDaemonAppTraits : public wxConsoleAppTraits { private: - CAmuledGSocketFuncTable *m_table; - wxMutex m_lock; - std::list m_sched_delete; -#ifndef __WXMSW__ struct sigaction m_oldSignalChildAction; struct sigaction m_newSignalChildAction; -#endif +#ifdef AMULED28 + CAmuledGSocketFuncTable *m_table; + wxMutex m_lock; + std::list m_sched_delete; public: CDaemonAppTraits(CAmuledGSocketFuncTable *table); virtual GSocketGUIFunctionsTable* GetSocketGUIFunctionsTable(); @@ -430,50 +448,56 @@ public: virtual void RemoveFromPendingDelete(wxObject *object); void DeletePending(); +#else // AMULED28 +public: + CDaemonAppTraits(); +#endif // !AMULED28 -#ifndef __WXMSW__ virtual int WaitForChild(wxExecuteData& execData); -#endif + #ifdef __WXMAC__ virtual wxStandardPathsBase& GetStandardPaths(); #endif }; - -#ifndef __WXMSW__ - void OnSignalChildHandler(int signal, siginfo_t *siginfo, void *ucontext); - pid_t AmuleWaitPid(pid_t pid, int *status, int options, wxString *msg); +void OnSignalChildHandler(int signal, siginfo_t *siginfo, void *ucontext); +pid_t AmuleWaitPid(pid_t pid, int *status, int options, wxString *msg); #endif // __WXMSW__ class CamuleDaemonApp : public CamuleApp { private: +#ifdef AMULED28 bool m_Exit; CAmuledGSocketFuncTable *m_table; -#ifndef __WXMSW__ - struct sigaction m_oldSignalChildAction; - struct sigaction m_newSignalChildAction; -#endif // __WXMSW__ - +#endif bool OnInit(); int OnRun(); int OnExit(); virtual int InitGui(bool geometry_enable, wxString &geometry_string); +#ifndef __WXMSW__ + struct sigaction m_oldSignalChildAction; + struct sigaction m_newSignalChildAction; public: + wxAppTraits *CreateTraits(); +#endif // __WXMSW__ + +public: + +#ifdef AMULED28 CamuleDaemonApp(); void ExitMainLoop() { m_Exit = true; } - +#endif + bool CopyTextToClipboard(wxString strText); virtual void ShowAlert(wxString msg, wxString title, int flags); DECLARE_EVENT_TABLE() - - wxAppTraits *CreateTraits(); }; DECLARE_APP(CamuleDaemonApp) diff --git a/src/amuled.cpp b/src/amuled.cpp index b1dd106f..08df7835 100644 --- a/src/amuled.cpp +++ b/src/amuled.cpp @@ -27,13 +27,6 @@ #include -// amuled doesn't run on Windows. -// To make it at least compile some code has to be excluded. -// For a real port all usages of TODO_MSW have to be resolved ! -#ifdef __WXMSW__ - #define TODO_MSW 1 -#endif - #ifdef HAVE_CONFIG_H #include "config.h" // Needed for HAVE_SYS_RESOURCE_H, HAVE_STRERROR_R and STRERROR_R_CHAR_P, etc #endif @@ -176,6 +169,7 @@ END_EVENT_TABLE() IMPLEMENT_APP(CamuleDaemonApp) +#ifdef AMULED28 /* * Socket handling in wxBase * @@ -308,8 +302,6 @@ void CAmuledGSocketFuncTable::RemoveSocket(GSocket *socket, GSocketEvent event) void CAmuledGSocketFuncTable::RunSelect() { -#ifndef TODO_MSW -// This is why it doesn't work on Windows wxMutexLocker lock(m_lock); int max_fd = -1; @@ -325,8 +317,6 @@ void CAmuledGSocketFuncTable::RunSelect() m_in_set->Detected(&GSocket::Detected_Read); m_out_set->Detected(&GSocket::Detected_Write); } - -#endif } GSocketGUIFunctionsTable *CDaemonAppTraits::GetSocketGUIFunctionsTable() @@ -383,17 +373,20 @@ void CAmuledGSocketFuncTable::Disable_Events(GSocket *socket) Uninstall_Callback(socket, GSOCK_OUTPUT); } +#endif // AMULED28 + +#ifndef __WXMSW__ + +#ifdef AMULED28 CDaemonAppTraits::CDaemonAppTraits(CAmuledGSocketFuncTable *table) : wxConsoleAppTraits(), +m_oldSignalChildAction(), +m_newSignalChildAction(), m_table(table), m_lock(wxMUTEX_RECURSIVE), m_sched_delete() -#ifndef TODO_MSW -,m_oldSignalChildAction(), -m_newSignalChildAction() -#endif { m_lock.Unlock(); } @@ -432,6 +425,29 @@ void CDaemonAppTraits::DeletePending() //m_sched_delete.erase(m_sched_delete.begin(), m_sched_delete.end()); } +wxAppTraits *CamuleDaemonApp::CreateTraits() +{ + return new CDaemonAppTraits(m_table); +} + +#else // AMULED28 + +CDaemonAppTraits::CDaemonAppTraits() +: +wxConsoleAppTraits(), +m_oldSignalChildAction(), +m_newSignalChildAction() +{ +} + +wxAppTraits *CamuleDaemonApp::CreateTraits() +{ + return new CDaemonAppTraits(); +} + +#endif // !AMULED28 + +#endif // __WXMSW__ #ifdef __WXMAC__ #include // Do_not_auto_remove (guess) @@ -443,6 +459,8 @@ wxStandardPathsBase& CDaemonAppTraits::GetStandardPaths() #endif +#ifdef AMULED28 + CamuleDaemonApp::CamuleDaemonApp() : m_Exit(false), @@ -451,11 +469,7 @@ m_table(new CAmuledGSocketFuncTable()) wxPendingEventsLocker = new wxCriticalSection; } - -wxAppTraits *CamuleDaemonApp::CreateTraits() -{ - return new CDaemonAppTraits(m_table); -} +#endif // !AMULED28 #ifndef __WXMSW__ @@ -640,6 +654,8 @@ int CamuleDaemonApp::OnRun() } #endif // __WXMSW__ +#ifdef AMULED28 + while ( !m_Exit ) { m_table->RunSelect(); ProcessPendingEvents(); @@ -649,23 +665,17 @@ int CamuleDaemonApp::OnRun() // ShutDown is beeing called twice. Once here and again in OnExit(). ShutDown(); -#ifndef __WXMSW__ - msg.Empty(); - ret = sigaction(SIGCHLD, &m_oldSignalChildAction, NULL); - if (ret == -1) { - strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN); - msg << wxT("CamuleDaemonApp::OnRun(): second sigaction() failed: ") << - char2unicode(errorBuffer) << - wxT("."); - AddLogLineM(true, msg); - } else { - msg << wxT("CamuleDaemonApp::OnRun(): Uninstallation of SIGCHLD " - "callback with sigaction() succeeded."); - AddDebugLogLineM(false, logGeneral, msg); - } -#endif // __WXMSW__ + return 0; + +#else +#ifdef AMULED_DUMMY return 0; +#else + return wxApp::OnRun(); +#endif + +#endif } bool CamuleDaemonApp::OnInit() @@ -731,6 +741,7 @@ int CamuleDaemonApp::InitGui(bool ,wxString &) int CamuleDaemonApp::OnExit() { +#ifdef AMULED28 /* * Stop all socket threads before entering * shutdown sequence. @@ -741,8 +752,27 @@ int CamuleDaemonApp::OnExit() delete clientudp; clientudp = NULL; } - +#endif + ShutDown(); + +#ifndef __WXMSW__ + const int ERROR_BUFFER_LEN = 256; + char errorBuffer[ERROR_BUFFER_LEN]; + wxString msg; + int ret = sigaction(SIGCHLD, &m_oldSignalChildAction, NULL); + if (ret == -1) { + strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN); + msg << wxT("CamuleDaemonApp::OnRun(): second sigaction() failed: ") << + char2unicode(errorBuffer) << + wxT("."); + AddLogLineM(true, msg); + } else { + msg << wxT("CamuleDaemonApp::OnRun(): Uninstallation of SIGCHLD " + "callback with sigaction() succeeded."); + AddDebugLogLineM(false, logGeneral, msg); + } +#endif // __WXMSW__ // lfroen: delete socket threads if (ECServerHandler) { -- 2.11.4.GIT