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

View File

@@ -5,12 +5,13 @@
*/
#include "ACSoap.h"
#include "AccountMgr.h"
#include "Log.h"
#include "soapH.h"
#include "soapStub.h"
#include "World.h"
void ACSoapRunnable::run()
void ACSoapThread(const std::string& host, uint16 port)
{
struct soap soap;
soap_init(&soap);
@@ -21,13 +22,14 @@ void ACSoapRunnable::run()
soap.accept_timeout = 3;
soap.recv_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);
}
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())
{
@@ -39,32 +41,26 @@ void ACSoapRunnable::run()
#endif
struct soap* thread_soap = soap_copy(&soap);// make a safe copy
ACE_Message_Block* mb = new ACE_Message_Block(sizeof(struct soap*));
ACE_OS::memcpy(mb->wr_ptr(), &thread_soap, sizeof(struct soap*));
process_message(mb);
process_message(thread_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;
ACE_OS::memcpy(&soap, mb->rd_ptr (), sizeof(struct soap*));
mb->release();
soap_serve(soap);
soap_destroy(soap); // dealloc C++ data
soap_end(soap); // dealloc data and clean up
soap_done(soap); // detach soap struct
free(soap);
soap_serve(soap_message);
soap_destroy(soap_message); // dealloc C++ data
soap_end(soap_message); // dealloc data and clean up
soap_done(soap_message); // detach soap struct
free(soap_message);
}
/*
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)
{
@@ -117,16 +113,10 @@ int ns1__executeCommand(soap* soap, char* command, char** result)
sWorld->QueueCliCommand(cmd);
}
// wait for callback to complete command
int acc = connection.pendingCommands.acquire();
if (acc)
{
LOG_ERROR("server", "ACSoap: Error while acquiring lock, acc = %i, errno = %u", acc, errno);
}
// alright, command finished
// Wait until the command has finished executing
connection.finishedPromise.get_future().wait();
// The command has finished executing already
char* printBuffer = soap_strdup(soap, connection.m_printBuffer.c_str());
if (connection.hasCommandSucceeded())
{
@@ -141,7 +131,6 @@ void SOAPCommand::commandFinished(void* soapconnection, bool success)
{
SOAPCommand* con = (SOAPCommand*)soapconnection;
con->setCommandSuccess(success);
con->pendingCommands.release();
}
////////////////////////////////////////////////////////////////////////////////

View File

@@ -7,49 +7,30 @@
#ifndef _ACSOAP_H
#define _ACSOAP_H
#include "AccountMgr.h"
#include "Define.h"
#include <ace/Semaphore.h>
#include <ace/Task.h>
#include <Threading.h>
#include <future>
#include <mutex>
class ACSoapRunnable : public acore::Runnable
{
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;
};
void process_message(struct soap* soap_message);
void ACSoapThread(const std::string& host, uint16 port);
class SOAPCommand
{
public:
SOAPCommand(): pendingCommands(0, USYNC_THREAD, "pendingCommands"), m_success(false) {}
SOAPCommand() :
m_success(false) { }
~SOAPCommand() { }
void appendToPrintBuffer(const char* msg)
void appendToPrintBuffer(char const* msg)
{
m_printBuffer += msg;
}
ACE_Semaphore pendingCommands;
void setCommandSuccess(bool val)
{
m_success = val;
finishedPromise.set_value();
}
bool hasCommandSucceeded() const
@@ -57,7 +38,7 @@ public:
return m_success;
}
static void print(void* callbackArg, const char* msg)
static void print(void* callbackArg, char const* msg)
{
((SOAPCommand*)callbackArg)->appendToPrintBuffer(msg);
}
@@ -66,6 +47,7 @@ public:
bool m_success;
std::string m_printBuffer;
std::promise<void> finishedPromise;
};
#endif

View File

@@ -247,13 +247,16 @@ int Master::Run()
#endif
#endif
// Start soap serving thread
acore::Thread* soapThread = nullptr;
// Start soap serving thread if enabled
std::shared_ptr<std::thread> soapThread;
if (sConfigMgr->GetOption<bool>("SOAP.Enabled", false))
{
ACSoapRunnable* runnable = new ACSoapRunnable();
runnable->SetListenArguments(sConfigMgr->GetOption<std::string>("SOAP.IP", "127.0.0.1"), uint16(sConfigMgr->GetOption<int32>("SOAP.Port", 7878)));
soapThread = new acore::Thread(runnable);
soapThread.reset(new std::thread(ACSoapThread, sConfigMgr->GetOption<std::string>("SOAP.IP", "127.0.0.1"), sConfigMgr->GetOption<uint16>("SOAP.Port", 7878)),
[](std::thread* thr)
{
thr->join();
delete thr;
});
}
// Start up freeze catcher thread
@@ -286,13 +289,6 @@ int Master::Run()
rarThread.wait();
auctionLising_thread.wait();
if (soapThread)
{
soapThread->wait();
soapThread->destroy();
delete soapThread;
}
if (freezeThread)
{
freezeThread->wait();