Permalink
Browse files

format sources

  • Loading branch information...
turleypol committed Oct 21, 2017
1 parent 63a3979 commit 37ec763c81f0ffa42c87d44b0bb32dab64f5b196
Showing with 66 additions and 49 deletions.
  1. +43 −40 pol-core/pol/module/osmod.cpp
  2. +21 −8 pol-core/pol/network/auxclient.cpp
  3. +2 −1 pol-core/pol/network/auxclient.h
@@ -587,11 +587,11 @@ BObjectImp* OSExecutorModule::mf_OpenConnection()
{
const String* host;
const String* scriptname_str;
BObjectImp* scriptparam;
BObjectImp* scriptparam;
unsigned short port;
int assume_string_int;
if ( getStringParam( 0, host ) && getParam( 1, port ) &&
getStringParam( 2, scriptname_str ) && getParamImp( 3, scriptparam ) && getParam( 4, assume_string_int ))
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;
@@ -603,42 +603,45 @@ BObjectImp* OSExecutorModule::mf_OpenConnection()
{
return new BError( "Script " + sd.name() + " does not exist." );
}
if (!this_uoexec->suspend())
{
DEBUGLOG << "Script Error in '" << this_uoexec->scriptname() << "' PC=" << this_uoexec->PC
<< ": \n"
<< "\tThe execution of this script can't be blocked!\n";
return new Bscript::BError("Script can't be blocked");
}
weak_ptr<Core::UOExecutor> uoexec_w = this_uoexec->weakptr;
std::string hostname(host->value());
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())
{
DEBUGLOG << "OpenConnection Script has been destroyed\n";
s.close();
return;
}
if (!success_open)
{
uoexec_w.get_weakptr()->ValueStack.back().set(
new BObject(new BError("Error connecting to client")));
}
else
{
uoexec_w.get_weakptr()->ValueStack.back().set(new BObject(new BLong(1)));
}
uoexec_w.get_weakptr()->os_module->revive();
}
std::unique_ptr<Network::AuxClientThread> client(new Network::AuxClientThread(sd, s, scriptparam->copy(),assume_string));
client->run();
});
if ( !this_uoexec->suspend() )
{
DEBUGLOG << "Script Error in '" << this_uoexec->scriptname() << "' PC=" << this_uoexec->PC
<< ": \n"
<< "\tThe execution of this script can't be blocked!\n";
return new Bscript::BError( "Script can't be blocked" );
}
weak_ptr<Core::UOExecutor> uoexec_w = this_uoexec->weakptr;
std::string hostname( host->value() );
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() )
{
DEBUGLOG << "OpenConnection Script has been destroyed\n";
s.close();
return;
}
if ( !success_open )
{
uoexec_w.get_weakptr()->ValueStack.back().set(
new BObject( new BError( "Error connecting to client" ) ) );
}
else
{
uoexec_w.get_weakptr()->ValueStack.back().set( new BObject( new BLong( 1 ) ) );
}
uoexec_w.get_weakptr()->os_module->revive();
}
std::unique_ptr<Network::AuxClientThread> client(
new Network::AuxClientThread( sd, s, scriptparam->copy(), assume_string ) );
client->run();
} );
return new BLong( 0 );
}
@@ -105,11 +105,24 @@ void AuxConnection::disconnect()
}
AuxClientThread::AuxClientThread( AuxService* auxsvc, Clib::SocketListener& listener )
: SocketClientThread( listener ), _auxservice( auxsvc ), _auxconnection(), _uoexec(nullptr), _scriptdef(), _params(nullptr), _assume_string(false)
: 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(nullptr), _auxconnection(), _uoexec(nullptr), _scriptdef(scriptdef), _params(params), _assume_string(assume_string)
AuxClientThread::AuxClientThread( Core::ScriptDef scriptdef, Clib::Socket& sock,
Bscript::BObjectImp* params, bool assume_string )
: SocketClientThread( sock ),
_auxservice( nullptr ),
_auxconnection(),
_uoexec( nullptr ),
_scriptdef( scriptdef ),
_params( params ),
_assume_string( assume_string )
{
}
@@ -124,12 +137,12 @@ bool AuxClientThread::init()
if ( _auxservice )
uoemod = Core::start_script( _auxservice->scriptdef(), _auxconnection.get() );
else
uoemod = Core::start_script( _scriptdef, _auxconnection.get(), _params);
uoemod = Core::start_script( _scriptdef, _auxconnection.get(), _params );
_uoexec = uoemod->uoexec.weakptr;
if (_assume_string)
{
uoemod->uoexec.auxsvc_assume_string = _assume_string;
}
if ( _assume_string )
{
uoemod->uoexec.auxsvc_assume_string = _assume_string;
}
return true;
}
else
@@ -85,7 +85,8 @@ class AuxClientThread : public Clib::SocketClientThread
{
public:
AuxClientThread( AuxService* auxsvc, Clib::SocketListener& listener );
AuxClientThread( Core::ScriptDef scriptdef, Clib::Socket& sock, Bscript::BObjectImp* params, bool assume_string);
AuxClientThread( Core::ScriptDef scriptdef, Clib::Socket& sock, Bscript::BObjectImp* params,
bool assume_string );
virtual void run() POL_OVERRIDE;
void transmit( const Bscript::BObjectImp* imp );
Bscript::BObjectImp* get_ip();

0 comments on commit 37ec763

Please sign in to comment.