Permalink
Browse files

activated for ingoing auxconnections the threadpool

fixed initialization order of AuxClientThread
do not let members uninitialized in AuxClientThread
some minor tunings
  • Loading branch information...
turleypol committed Oct 21, 2017
1 parent bae849a commit 63a3979b2fa64154c0ca9bc324a9eec5e2fe1baf
@@ -26,7 +26,7 @@ MoveDelta move_delta[8] = {{0, -1}, // 0 is N
UFACING away_cvt[8] = {FACING_S, FACING_SW, FACING_W, FACING_NW,
FACING_N, FACING_NE, FACING_E, FACING_SE};
std::array<int,7> adjustments = {0, +1, -1, +2, -2, +3, -3};
std::array<int,7> adjustments = {{0, +1, -1, +2, -2, +3, -3}};
}
namespace Mobile
{
@@ -587,15 +587,14 @@ BObjectImp* OSExecutorModule::mf_OpenConnection()
{
const String* host;
const String* scriptname_str;
BObjectImp* imp;
BObjectImp* scriptparam;
unsigned short port;
int escriptint;
if ( ( host = getStringParam( 0 ) ) != NULL && getParam( 1, port ) &&
( scriptname_str = getStringParam( 2 ) ) != NULL && (imp = getParamImp( 3 )) != NULL && getParam( 4, escriptint ))
int assume_string_int;
if ( getStringParam( 0, host ) && getParam( 1, port ) &&
getStringParam( 2, scriptname_str ) && getParamImp( 3, scriptparam ) && getParam( 4, assume_string_int ))
{
// FIXME needs to inherit available modules?
Core::ScriptDef sd; // = new ScriptDef();
INFO_PRINT << "Starting connection script " << scriptname_str->value() << "\n";
Core::ScriptDef sd;
if ( !sd.config_nodie( scriptname_str->value(), exec.prog()->pkg, "scripts/" ) )
{
return new BError( "Error in script name" );
@@ -614,15 +613,15 @@ BObjectImp* OSExecutorModule::mf_OpenConnection()
weak_ptr<Core::UOExecutor> uoexec_w = this_uoexec->weakptr;
std::string hostname(host->value());
bool assume_string = escriptint != 0;
Core::networkManager.auxthreadpool->push([uoexec_w, sd, hostname, port, imp, assume_string]() {
bool assume_string = assume_string_int != 0;
Core::networkManager.auxthreadpool->push([uoexec_w, sd, hostname, port, scriptparam, assume_string]() {
Clib::Socket s;
bool success_open = s.open(hostname.c_str(), port);
{
Core::PolLock lck;
if (!uoexec_w.exists())
{
INFO_PRINT << "Script has been destroyed\n";
DEBUGLOG << "OpenConnection Script has been destroyed\n";
s.close();
return;
}
@@ -637,7 +636,7 @@ BObjectImp* OSExecutorModule::mf_OpenConnection()
}
uoexec_w.get_weakptr()->os_module->revive();
}
std::unique_ptr<Network::AuxClientThread> client(new Network::AuxClientThread(sd, s, imp->copy(),assume_string));
std::unique_ptr<Network::AuxClientThread> client(new Network::AuxClientThread(sd, s, scriptparam->copy(),assume_string));
client->run();
});
@@ -62,7 +62,7 @@ size_t AuxConnection::sizeEstimate() const
bool AuxConnection::isTrue() const
{
return ( _auxclientthread != NULL );
return ( _auxclientthread != nullptr );
}
Bscript::BObjectRef AuxConnection::get_member( const char* membername )
@@ -80,7 +80,7 @@ Bscript::BObjectImp* AuxConnection::call_method( const char* methodname, Bscript
{
if ( ex.numParams() == 1 )
{
if ( _auxclientthread != NULL )
if ( _auxclientthread != nullptr )
{
Bscript::BObjectImp* value = ex.getParamImp( 0 );
// FIXME this can block!
@@ -96,20 +96,20 @@ Bscript::BObjectImp* AuxConnection::call_method( const char* methodname, Bscript
return new Bscript::BError( "1 parameter expected" );
}
}
return NULL;
return nullptr;
}
void AuxConnection::disconnect()
{
_auxclientthread = NULL;
_auxclientthread = nullptr;
}
AuxClientThread::AuxClientThread( AuxService* auxsvc, Clib::SocketListener& listener )
: SocketClientThread( listener ), _auxservice( auxsvc ), _uoexec( 0 )
: SocketClientThread( listener ), _auxservice( auxsvc ), _auxconnection(), _uoexec(nullptr), _scriptdef(), _params(nullptr), _assume_string(false)
{
}
AuxClientThread::AuxClientThread( Core::ScriptDef scriptdef, Clib::Socket& sock, Bscript::BObjectImp* params, bool assume_string )
: SocketClientThread( sock ), _auxservice( 0 ), _uoexec(0), _scriptdef(scriptdef), _params(params), _assume_string(assume_string)
: SocketClientThread( sock ), _auxservice(nullptr), _auxconnection(), _uoexec(nullptr), _scriptdef(scriptdef), _params(params), _assume_string(assume_string)
{
}
@@ -126,7 +126,7 @@ bool AuxClientThread::init()
else
uoemod = Core::start_script( _scriptdef, _auxconnection.get(), _params);
_uoexec = uoemod->uoexec.weakptr;
if (_assume_string == true)
if (_assume_string)
{
uoemod->uoexec.auxsvc_assume_string = _assume_string;
}
@@ -257,20 +257,13 @@ void AuxService::run()
if ( listener.GetConnection( 5 ) )
{
Core::PolLock lock;
#ifdef PERGON
// TODO remove the ifdef it works..
AuxClientThread* client( new AuxClientThread( this, listener ) );
Core::networkManager.auxthreadpool->push(
[client]()
{
std::unique_ptr<AuxClientThread> _clientptr( client );
_clientptr->run();
} );
#else
Clib::SocketClientThread* clientthread = new AuxClientThread( this, listener );
clientthread->start();
// note SocketClientThread::start deletes the SocketClientThread upon thread exit.
#endif
}
}
}
@@ -94,12 +94,12 @@ class AuxClientThread : public Clib::SocketClientThread
bool init();
bool ipAllowed( sockaddr MyPeer );
weak_ptr<Core::UOExecutor> _uoexec;
AuxService* _auxservice;
ref_ptr<AuxConnection> _auxconnection;
weak_ptr<Core::UOExecutor> _uoexec;
Core::ScriptDef _scriptdef;
Bscript::BObjectImp* _params;
bool _assume_string;
ref_ptr<AuxConnection> _auxconnection;
};
}
}

0 comments on commit 63a3979

Please sign in to comment.