summaryrefslogtreecommitdiff
path: root/indra/llplugin/llpluginprocesschild.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llplugin/llpluginprocesschild.cpp')
-rw-r--r--indra/llplugin/llpluginprocesschild.cpp81
1 files changed, 70 insertions, 11 deletions
diff --git a/indra/llplugin/llpluginprocesschild.cpp b/indra/llplugin/llpluginprocesschild.cpp
index 9b43ec0e3e..d1cf91b253 100644
--- a/indra/llplugin/llpluginprocesschild.cpp
+++ b/indra/llplugin/llpluginprocesschild.cpp
@@ -48,6 +48,8 @@ LLPluginProcessChild::LLPluginProcessChild()
mSocket = LLSocket::create(gAPRPoolp, LLSocket::STREAM_TCP);
mSleepTime = PLUGIN_IDLE_SECONDS; // default: send idle messages at 100Hz
mCPUElapsed = 0.0f;
+ mBlockingRequest = false;
+ mBlockingResponseReceived = false;
}
LLPluginProcessChild::~LLPluginProcessChild()
@@ -83,9 +85,14 @@ void LLPluginProcessChild::idle(void)
bool idle_again;
do
{
- if(mSocketError != APR_SUCCESS)
+ if(APR_STATUS_IS_EOF(mSocketError))
{
- LL_INFOS("Plugin") << "message pipe is in error state, moving to STATE_ERROR"<< LL_ENDL;
+ // Plugin socket was closed. This covers both normal plugin termination and host crashes.
+ setState(STATE_ERROR);
+ }
+ else if(mSocketError != APR_SUCCESS)
+ {
+ LL_INFOS("Plugin") << "message pipe is in error state (" << mSocketError << "), moving to STATE_ERROR"<< LL_ENDL;
setState(STATE_ERROR);
}
@@ -155,8 +162,6 @@ void LLPluginProcessChild::idle(void)
{
setState(STATE_PLUGIN_INITIALIZING);
LLPluginMessage message("base", "init");
- message.setValue("user_data_path", mUserDataPath);
- message.setValue("language_code", mLanguageCode);
sendMessageToPlugin(message);
}
break;
@@ -228,6 +233,7 @@ void LLPluginProcessChild::idle(void)
void LLPluginProcessChild::sleep(F64 seconds)
{
+ deliverQueuedMessages();
if(mMessagePipe)
{
mMessagePipe->pump(seconds);
@@ -240,6 +246,7 @@ void LLPluginProcessChild::sleep(F64 seconds)
void LLPluginProcessChild::pump(void)
{
+ deliverQueuedMessages();
if(mMessagePipe)
{
mMessagePipe->pump(0.0f);
@@ -311,15 +318,32 @@ void LLPluginProcessChild::receiveMessageRaw(const std::string &message)
LL_DEBUGS("Plugin") << "Received from parent: " << message << LL_ENDL;
+ // Decode this message
+ LLPluginMessage parsed;
+ parsed.parse(message);
+
+ if(mBlockingRequest)
+ {
+ // We're blocking the plugin waiting for a response.
+
+ if(parsed.hasValue("blocking_response"))
+ {
+ // This is the message we've been waiting for -- fall through and send it immediately.
+ mBlockingResponseReceived = true;
+ }
+ else
+ {
+ // Still waiting. Queue this message and don't process it yet.
+ mMessageQueue.push(message);
+ return;
+ }
+ }
+
bool passMessage = true;
// FIXME: how should we handle queueing here?
{
- // Decode this message
- LLPluginMessage parsed;
- parsed.parse(message);
-
std::string message_class = parsed.getClass();
if(message_class == LLPLUGIN_MESSAGE_CLASS_INTERNAL)
{
@@ -329,8 +353,6 @@ void LLPluginProcessChild::receiveMessageRaw(const std::string &message)
if(message_name == "load_plugin")
{
mPluginFile = parsed.getValue("file");
- mUserDataPath = parsed.getValue("user_data_path");
- mLanguageCode = parsed.getValue("language_code");
}
else if(message_name == "shm_add")
{
@@ -429,7 +451,13 @@ void LLPluginProcessChild::receiveMessageRaw(const std::string &message)
void LLPluginProcessChild::receivePluginMessage(const std::string &message)
{
LL_DEBUGS("Plugin") << "Received from plugin: " << message << LL_ENDL;
-
+
+ if(mBlockingRequest)
+ {
+ //
+ LL_ERRS("Plugin") << "Can't send a message while already waiting on a blocking request -- aborting!" << LL_ENDL;
+ }
+
// Incoming message from the plugin instance
bool passMessage = true;
@@ -440,6 +468,12 @@ void LLPluginProcessChild::receivePluginMessage(const std::string &message)
// Decode this message
LLPluginMessage parsed;
parsed.parse(message);
+
+ if(parsed.hasValue("blocking_request"))
+ {
+ mBlockingRequest = true;
+ }
+
std::string message_class = parsed.getClass();
if(message_class == "base")
{
@@ -498,6 +532,19 @@ void LLPluginProcessChild::receivePluginMessage(const std::string &message)
LL_DEBUGS("Plugin") << "Passing through to parent: " << message << LL_ENDL;
writeMessageRaw(message);
}
+
+ while(mBlockingRequest)
+ {
+ // The plugin wants to block and wait for a response to this message.
+ sleep(mSleepTime); // this will pump the message pipe and process messages
+
+ if(mBlockingResponseReceived || mSocketError != APR_SUCCESS || (mMessagePipe == NULL))
+ {
+ // Response has been received, or we've hit an error state. Stop waiting.
+ mBlockingRequest = false;
+ mBlockingResponseReceived = false;
+ }
+ }
}
@@ -506,3 +553,15 @@ void LLPluginProcessChild::setState(EState state)
LL_DEBUGS("Plugin") << "setting state to " << state << LL_ENDL;
mState = state;
};
+
+void LLPluginProcessChild::deliverQueuedMessages()
+{
+ if(!mBlockingRequest)
+ {
+ while(!mMessageQueue.empty())
+ {
+ receiveMessageRaw(mMessageQueue.front());
+ mMessageQueue.pop();
+ }
+ }
+}