summaryrefslogtreecommitdiff
path: root/indra/llplugin
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llplugin')
-rw-r--r--indra/llplugin/llpluginclassmedia.h4
-rw-r--r--indra/llplugin/llplugininstance.h2
-rw-r--r--indra/llplugin/llpluginmessagepipe.cpp51
-rw-r--r--indra/llplugin/llpluginmessagepipe.h3
-rw-r--r--indra/llplugin/llpluginprocessparent.h2
5 files changed, 40 insertions, 22 deletions
diff --git a/indra/llplugin/llpluginclassmedia.h b/indra/llplugin/llpluginclassmedia.h
index d95fa40091..5fe8254331 100644
--- a/indra/llplugin/llpluginclassmedia.h
+++ b/indra/llplugin/llpluginclassmedia.h
@@ -41,7 +41,7 @@ class LLPluginClassMedia : public LLPluginProcessParentOwner
LOG_CLASS(LLPluginClassMedia);
public:
LLPluginClassMedia(LLPluginClassMediaOwner *owner);
- ~LLPluginClassMedia();
+ virtual ~LLPluginClassMedia();
// local initialization, called by the media manager when creating a source
bool init(const std::string &launcher_filename,
@@ -270,7 +270,7 @@ public:
std::string getHoverText() const { return mHoverText; };
std::string getHoverLink() const { return mHoverLink; };
- std::string getMediaName() const { return mMediaName; };
+ const std::string& getMediaName() const { return mMediaName; };
std::string getMediaDescription() const { return mMediaDescription; };
// Crash the plugin. If you use this outside of a testbed, you will be punished.
diff --git a/indra/llplugin/llplugininstance.h b/indra/llplugin/llplugininstance.h
index 3643a15d8c..e6926c3e37 100644
--- a/indra/llplugin/llplugininstance.h
+++ b/indra/llplugin/llplugininstance.h
@@ -39,7 +39,7 @@
class LLPluginInstanceMessageListener
{
public:
- ~LLPluginInstanceMessageListener();
+ virtual ~LLPluginInstanceMessageListener();
/** Plugin receives message from plugin loader shell. */
virtual void receivePluginMessage(const std::string &message) = 0;
};
diff --git a/indra/llplugin/llpluginmessagepipe.cpp b/indra/llplugin/llpluginmessagepipe.cpp
index 8d13e38ad5..091e93ea4b 100644
--- a/indra/llplugin/llpluginmessagepipe.cpp
+++ b/indra/llplugin/llpluginmessagepipe.cpp
@@ -94,10 +94,10 @@ void LLPluginMessagePipeOwner::killMessagePipe(void)
LLPluginMessagePipe::LLPluginMessagePipe(LLPluginMessagePipeOwner *owner, LLSocket::ptr_t socket):
mInputMutex(gAPRPoolp),
mOutputMutex(gAPRPoolp),
+ mOutputStartIndex(0),
mOwner(owner),
mSocket(socket)
{
-
mOwner->setMessagePipe(this);
}
@@ -113,6 +113,14 @@ bool LLPluginMessagePipe::addMessage(const std::string &message)
{
// queue the message for later output
LLMutexLock lock(&mOutputMutex);
+
+ // If we're starting to use up too much memory, clear
+ if (mOutputStartIndex > 1024 * 1024)
+ {
+ mOutput = mOutput.substr(mOutputStartIndex);
+ mOutputStartIndex = 0;
+ }
+
mOutput += message;
mOutput += MESSAGE_DELIMITER; // message separator
@@ -165,35 +173,44 @@ bool LLPluginMessagePipe::pumpOutput()
if(mSocket)
{
apr_status_t status;
- apr_size_t size;
+ apr_size_t in_size, out_size;
LLMutexLock lock(&mOutputMutex);
- if(!mOutput.empty())
+
+ const char * output_data = &(mOutput.data()[mOutputStartIndex]);
+ if(*output_data != '\0')
{
// write any outgoing messages
- size = (apr_size_t)mOutput.size();
+ in_size = (apr_size_t) (mOutput.size() - mOutputStartIndex);
+ out_size = in_size;
setSocketTimeout(0);
// LL_INFOS("Plugin") << "before apr_socket_send, size = " << size << LL_ENDL;
- status = apr_socket_send(
- mSocket->getSocket(),
- (const char*)mOutput.data(),
- &size);
+ status = apr_socket_send(mSocket->getSocket(),
+ output_data,
+ &out_size);
// LL_INFOS("Plugin") << "after apr_socket_send, size = " << size << LL_ENDL;
- if(status == APR_SUCCESS)
+ if((status == APR_SUCCESS) || APR_STATUS_IS_EAGAIN(status))
{
- // success
- mOutput = mOutput.substr(size);
- }
- else if(APR_STATUS_IS_EAGAIN(status))
- {
- // Socket buffer is full...
- // remove the written part from the buffer and try again later.
- mOutput = mOutput.substr(size);
+ // Success or Socket buffer is full...
+
+ // If we've pumped the entire string, clear it
+ if (out_size == in_size)
+ {
+ mOutputStartIndex = 0;
+ mOutput.clear();
+ }
+ else
+ {
+ llassert(in_size > out_size);
+
+ // Remove the written part from the buffer and try again later.
+ mOutputStartIndex += out_size;
+ }
}
else if(APR_STATUS_IS_EOF(status))
{
diff --git a/indra/llplugin/llpluginmessagepipe.h b/indra/llplugin/llpluginmessagepipe.h
index beb942c0fe..c3498beac0 100644
--- a/indra/llplugin/llpluginmessagepipe.h
+++ b/indra/llplugin/llpluginmessagepipe.h
@@ -40,7 +40,7 @@ class LLPluginMessagePipeOwner
LOG_CLASS(LLPluginMessagePipeOwner);
public:
LLPluginMessagePipeOwner();
- ~LLPluginMessagePipeOwner();
+ virtual ~LLPluginMessagePipeOwner();
// called with incoming messages
virtual void receiveMessageRaw(const std::string &message) = 0;
@@ -86,6 +86,7 @@ protected:
std::string mInput;
LLMutex mOutputMutex;
std::string mOutput;
+ std::string::size_type mOutputStartIndex;
LLPluginMessagePipeOwner *mOwner;
LLSocket::ptr_t mSocket;
diff --git a/indra/llplugin/llpluginprocessparent.h b/indra/llplugin/llpluginprocessparent.h
index 26c6b0c402..c66723f175 100644
--- a/indra/llplugin/llpluginprocessparent.h
+++ b/indra/llplugin/llpluginprocessparent.h
@@ -41,7 +41,7 @@
class LLPluginProcessParentOwner
{
public:
- ~LLPluginProcessParentOwner();
+ virtual ~LLPluginProcessParentOwner();
virtual void receivePluginMessage(const LLPluginMessage &message) = 0;
virtual bool receivePluginMessageEarly(const LLPluginMessage &message) {return false;};
// This will only be called when the plugin has died unexpectedly