feat(Core/Soap): delete ACE inherited (#4951)

This commit is contained in:
Kargatum
2021-05-30 18:06:02 +07:00
committed by GitHub
parent cedd636338
commit 48ddfd62c5
3 changed files with 38 additions and 71 deletions
+20 -31
View File
@@ -5,12 +5,13 @@
*/ */
#include "ACSoap.h" #include "ACSoap.h"
#include "AccountMgr.h"
#include "Log.h" #include "Log.h"
#include "soapH.h" #include "soapH.h"
#include "soapStub.h" #include "soapStub.h"
#include "World.h" #include "World.h"
void ACSoapRunnable::run() void ACSoapThread(const std::string& host, uint16 port)
{ {
struct soap soap; struct soap soap;
soap_init(&soap); soap_init(&soap);
@@ -21,13 +22,14 @@ void ACSoapRunnable::run()
soap.accept_timeout = 3; soap.accept_timeout = 3;
soap.recv_timeout = 5; soap.recv_timeout = 5;
soap.send_timeout = 5; soap.send_timeout = 5;
if (!soap_valid_socket(soap_bind(&soap, _host.c_str(), _port, 100)))
if (!soap_valid_socket(soap_bind(&soap, host.c_str(), port, 100)))
{ {
LOG_ERROR("server", "ACSoap: couldn't bind to %s:%d", _host.c_str(), _port); LOG_ERROR("server", "ACSoap: couldn't bind to %s:%d", host.c_str(), port);
exit(-1); exit(-1);
} }
LOG_INFO("server", "ACSoap: bound to http://%s:%d", _host.c_str(), _port); LOG_INFO("server", "ACSoap: bound to http://%s:%d", host.c_str(), port);
while (!World::IsStopped()) while (!World::IsStopped())
{ {
@@ -39,32 +41,26 @@ void ACSoapRunnable::run()
#endif #endif
struct soap* thread_soap = soap_copy(&soap);// make a safe copy struct soap* thread_soap = soap_copy(&soap);// make a safe copy
ACE_Message_Block* mb = new ACE_Message_Block(sizeof(struct soap*)); process_message(thread_soap);
ACE_OS::memcpy(mb->wr_ptr(), &thread_soap, sizeof(struct soap*));
process_message(mb);
} }
soap_done(&soap); soap_done(&soap);
} }
void ACSoapRunnable::process_message(ACE_Message_Block* mb) void process_message(struct soap* soap_message)
{ {
ACE_TRACE (ACE_TEXT ("SOAPWorkingThread::process_message")); //LOG_TRACE("network.soap", "SOAPWorkingThread::process_message");
struct soap* soap; soap_serve(soap_message);
ACE_OS::memcpy(&soap, mb->rd_ptr (), sizeof(struct soap*)); soap_destroy(soap_message); // dealloc C++ data
mb->release(); soap_end(soap_message); // dealloc data and clean up
soap_done(soap_message); // detach soap struct
soap_serve(soap); free(soap_message);
soap_destroy(soap); // dealloc C++ data
soap_end(soap); // dealloc data and clean up
soap_done(soap); // detach soap struct
free(soap);
} }
/*
Code used for generating stubs:
int ns1__executeCommand(char* command, char** result); /*
Code used for generating stubs:
int ns1__executeCommand(char* command, char** result);
*/ */
int ns1__executeCommand(soap* soap, char* command, char** result) int ns1__executeCommand(soap* soap, char* command, char** result)
{ {
@@ -117,16 +113,10 @@ int ns1__executeCommand(soap* soap, char* command, char** result)
sWorld->QueueCliCommand(cmd); sWorld->QueueCliCommand(cmd);
} }
// wait for callback to complete command // Wait until the command has finished executing
connection.finishedPromise.get_future().wait();
int acc = connection.pendingCommands.acquire();
if (acc)
{
LOG_ERROR("server", "ACSoap: Error while acquiring lock, acc = %i, errno = %u", acc, errno);
}
// alright, command finished
// The command has finished executing already
char* printBuffer = soap_strdup(soap, connection.m_printBuffer.c_str()); char* printBuffer = soap_strdup(soap, connection.m_printBuffer.c_str());
if (connection.hasCommandSucceeded()) if (connection.hasCommandSucceeded())
{ {
@@ -141,7 +131,6 @@ void SOAPCommand::commandFinished(void* soapconnection, bool success)
{ {
SOAPCommand* con = (SOAPCommand*)soapconnection; SOAPCommand* con = (SOAPCommand*)soapconnection;
con->setCommandSuccess(success); con->setCommandSuccess(success);
con->pendingCommands.release();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
+10 -28
View File
@@ -7,49 +7,30 @@
#ifndef _ACSOAP_H #ifndef _ACSOAP_H
#define _ACSOAP_H #define _ACSOAP_H
#include "AccountMgr.h"
#include "Define.h" #include "Define.h"
#include <ace/Semaphore.h> #include <future>
#include <ace/Task.h> #include <mutex>
#include <Threading.h>
class ACSoapRunnable : public acore::Runnable void process_message(struct soap* soap_message);
{ void ACSoapThread(const std::string& host, uint16 port);
public:
ACSoapRunnable() : _port(0) { }
void run() override;
void SetListenArguments(const std::string& host, uint16 port)
{
_host = host;
_port = port;
}
private:
void process_message(ACE_Message_Block* mb);
std::string _host;
uint16 _port;
};
class SOAPCommand class SOAPCommand
{ {
public: public:
SOAPCommand(): pendingCommands(0, USYNC_THREAD, "pendingCommands"), m_success(false) {} SOAPCommand() :
m_success(false) { }
~SOAPCommand() { } ~SOAPCommand() { }
void appendToPrintBuffer(const char* msg) void appendToPrintBuffer(char const* msg)
{ {
m_printBuffer += msg; m_printBuffer += msg;
} }
ACE_Semaphore pendingCommands;
void setCommandSuccess(bool val) void setCommandSuccess(bool val)
{ {
m_success = val; m_success = val;
finishedPromise.set_value();
} }
bool hasCommandSucceeded() const bool hasCommandSucceeded() const
@@ -57,7 +38,7 @@ public:
return m_success; return m_success;
} }
static void print(void* callbackArg, const char* msg) static void print(void* callbackArg, char const* msg)
{ {
((SOAPCommand*)callbackArg)->appendToPrintBuffer(msg); ((SOAPCommand*)callbackArg)->appendToPrintBuffer(msg);
} }
@@ -66,6 +47,7 @@ public:
bool m_success; bool m_success;
std::string m_printBuffer; std::string m_printBuffer;
std::promise<void> finishedPromise;
}; };
#endif #endif
+8 -12
View File
@@ -247,13 +247,16 @@ int Master::Run()
#endif #endif
#endif #endif
// Start soap serving thread // Start soap serving thread if enabled
acore::Thread* soapThread = nullptr; std::shared_ptr<std::thread> soapThread;
if (sConfigMgr->GetOption<bool>("SOAP.Enabled", false)) if (sConfigMgr->GetOption<bool>("SOAP.Enabled", false))
{ {
ACSoapRunnable* runnable = new ACSoapRunnable(); soapThread.reset(new std::thread(ACSoapThread, sConfigMgr->GetOption<std::string>("SOAP.IP", "127.0.0.1"), sConfigMgr->GetOption<uint16>("SOAP.Port", 7878)),
runnable->SetListenArguments(sConfigMgr->GetOption<std::string>("SOAP.IP", "127.0.0.1"), uint16(sConfigMgr->GetOption<int32>("SOAP.Port", 7878))); [](std::thread* thr)
soapThread = new acore::Thread(runnable); {
thr->join();
delete thr;
});
} }
// Start up freeze catcher thread // Start up freeze catcher thread
@@ -286,13 +289,6 @@ int Master::Run()
rarThread.wait(); rarThread.wait();
auctionLising_thread.wait(); auctionLising_thread.wait();
if (soapThread)
{
soapThread->wait();
soapThread->destroy();
delete soapThread;
}
if (freezeThread) if (freezeThread)
{ {
freezeThread->wait(); freezeThread->wait();