diff options
author | Monroe Linden <monroe@lindenlab.com> | 2010-04-23 15:50:22 -0700 |
---|---|---|
committer | Monroe Linden <monroe@lindenlab.com> | 2010-04-23 15:50:22 -0700 |
commit | 57a2a2beff565c9a2e2ed0937df178c38d114cb3 (patch) | |
tree | 02981ec90f7f0dd278fd35c4399180280b398b18 /indra/llplugin/llpluginmessagepipe.cpp | |
parent | 13bf599e08d8ad3bba4facbc5fa9f468a1630dc7 (diff) |
Add a way for plugins to send a message and block waiting for the response
This requires some cooperation between the plugin and the host, and will only work for specific messages.
The way it works is as follows:
* the plugin sends a message containing the key "blocking_request" (with any value)
* this will cause the "send message" function to block (continuing to pull incoming messages off the network socket and queue them) until it receives a message from the host containing the key "blocking_response"
** NOTE: if the plugin sends a blocking_request that isn't set up to cause the host to send back a blocking_response, it will block forever
* the blocking_response message will be handed to the plugin's "receive message" function _immediately_ (before the "send message" function returns)
** this means that the plugin can extract response data for use by the the code that sent the message (but is still blocked inside the "send message" call)
** NOTE: this BREAKS the invariant stating that the plugin's "receive message" function will never be called recursively, and the plugin MUST be prepared to deal with this
* after the plugin finishes processing the blocking_response message, the "send message" function that was called with the blocking_request message will return to the plugin
* any queued messages will be delivered after the outer invocation of the plugin's "receive message" function returns (as normal)
Inside the viewer, the code can tell when a plugin is in this blocked state by calling LLPluginProcessParent::isBlocked(). LLPluginClassMedia uses this to avoid sending mouse-move and size-change messages to blocked plugins.
Diffstat (limited to 'indra/llplugin/llpluginmessagepipe.cpp')
-rw-r--r-- | indra/llplugin/llpluginmessagepipe.cpp | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/indra/llplugin/llpluginmessagepipe.cpp b/indra/llplugin/llpluginmessagepipe.cpp index 1d7ddc5592..e524c88cf8 100644 --- a/indra/llplugin/llpluginmessagepipe.cpp +++ b/indra/llplugin/llpluginmessagepipe.cpp @@ -299,26 +299,23 @@ bool LLPluginMessagePipe::pump(F64 timeout) void LLPluginMessagePipe::processInput(void) { // Look for input delimiter(s) in the input buffer. - int start = 0; int delim; - while((delim = mInput.find(MESSAGE_DELIMITER, start)) != std::string::npos) + while((delim = mInput.find(MESSAGE_DELIMITER)) != std::string::npos) { // Let the owner process this message if (mOwner) { - mOwner->receiveMessageRaw(mInput.substr(start, delim - start)); + // Pull the message out of the input buffer before calling receiveMessageRaw. + // It's now possible for this function to get called recursively (in the case where the plugin makes a blocking request) + // and this guarantees that the messages will get dequeued correctly. + std::string message(mInput, 0, delim); + mInput.erase(0, delim + 1); + mOwner->receiveMessageRaw(message); } else { LL_WARNS("Plugin") << "!mOwner" << LL_ENDL; } - - start = delim + 1; } - - // Remove delivered messages from the input buffer. - if(start != 0) - mInput = mInput.substr(start); - } |