diff options
author | David Robillard <d@drobilla.net> | 2011-04-19 20:41:24 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-04-19 20:41:24 +0000 |
commit | c9683eb916ff52ab6907773360c655d776b24f23 (patch) | |
tree | 39696902060bf6b3dbba156c1d315f4e69f7ce28 | |
parent | 6ec78b5a9eb499646d7fa6ccb306378426008e9d (diff) | |
download | ingen-c9683eb916ff52ab6907773360c655d776b24f23.tar.gz ingen-c9683eb916ff52ab6907773360c655d776b24f23.tar.bz2 ingen-c9683eb916ff52ab6907773360c655d776b24f23.zip |
Make maximum UDP packet size a runtime parameter (--packet-size, -k).
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@3170 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r-- | src/client/OSCEngineSender.cpp | 6 | ||||
-rw-r--r-- | src/client/OSCEngineSender.hpp | 16 | ||||
-rw-r--r-- | src/client/ingen_client.cpp | 3 | ||||
-rw-r--r-- | src/engine/OSCClientSender.hpp | 6 | ||||
-rw-r--r-- | src/engine/OSCEngineReceiver.cpp | 9 | ||||
-rw-r--r-- | src/gui/ConnectWindow.cpp | 13 | ||||
-rw-r--r-- | src/shared/Configuration.cpp | 1 | ||||
-rw-r--r-- | src/shared/OSCSender.cpp | 13 | ||||
-rw-r--r-- | src/shared/OSCSender.hpp | 7 |
9 files changed, 50 insertions, 24 deletions
diff --git a/src/client/OSCEngineSender.cpp b/src/client/OSCEngineSender.cpp index d2125e08..f78583f9 100644 --- a/src/client/OSCEngineSender.cpp +++ b/src/client/OSCEngineSender.cpp @@ -37,8 +37,10 @@ namespace Client { * from the most recently created server, so create the OSC listener before * this to have it all happen on the same port. Yeah, this is a big magic :/ */ -OSCEngineSender::OSCEngineSender(const URI& engine_url) - : _engine_url(engine_url) +OSCEngineSender::OSCEngineSender(const URI& engine_url, + size_t max_packet_size) + : Shared::OSCSender(max_packet_size) + , _engine_url(engine_url) , _id(0) { _address = lo_address_new_from_url(engine_url.c_str()); diff --git a/src/client/OSCEngineSender.hpp b/src/client/OSCEngineSender.hpp index e5a2fc9f..30e82c5f 100644 --- a/src/client/OSCEngineSender.hpp +++ b/src/client/OSCEngineSender.hpp @@ -18,13 +18,18 @@ #ifndef INGEN_CLIENT_OSCENGINESENDER_HPP #define INGEN_CLIENT_OSCENGINESENDER_HPP -#include <inttypes.h> +#include <stdbool.h> +#include <stddef.h> + #include <string> + #include <lo/lo.h> + #include "ingen/EngineInterface.hpp" #include "shared/OSCSender.hpp" namespace Ingen { + namespace Client { /* OSC (via liblo) interface to the engine. @@ -36,11 +41,14 @@ namespace Client { */ class OSCEngineSender : public EngineInterface, public Shared::OSCSender { public: - OSCEngineSender(const Raul::URI& engine_url); + OSCEngineSender(const Raul::URI& engine_url, + size_t max_packet_size); + ~OSCEngineSender(); - static OSCEngineSender* create(const Raul::URI& engine_url) { - return new OSCEngineSender(engine_url); + static OSCEngineSender* create(const Raul::URI& engine_url, + size_t max_packet_size) { + return new OSCEngineSender(engine_url, max_packet_size); } Raul::URI uri() const { return _engine_url; } diff --git a/src/client/ingen_client.cpp b/src/client/ingen_client.cpp index f1aa5c11..93b00e59 100644 --- a/src/client/ingen_client.cpp +++ b/src/client/ingen_client.cpp @@ -32,7 +32,8 @@ using namespace Ingen; SharedPtr<Ingen::EngineInterface> new_osc_interface(Ingen::Shared::World* world, const std::string& url) { - Client::OSCEngineSender* oes = Client::OSCEngineSender::create(url); + Client::OSCEngineSender* oes = Client::OSCEngineSender::create( + url, world->conf()->option("packet-size").get_int32()); oes->attach(rand(), true); return SharedPtr<EngineInterface>(oes); } diff --git a/src/engine/OSCClientSender.hpp b/src/engine/OSCClientSender.hpp index a30deb15..6ce8d684 100644 --- a/src/engine/OSCClientSender.hpp +++ b/src/engine/OSCClientSender.hpp @@ -41,8 +41,10 @@ class OSCClientSender : public ClientInterface, public Ingen::Shared::OSCSender { public: - explicit OSCClientSender(const Raul::URI& url) - : _url(url) + explicit OSCClientSender(const Raul::URI& url, + size_t max_packet_size) + : Shared::OSCSender(max_packet_size) + , _url(url) { _address = lo_address_new_from_url(url.c_str()); } diff --git a/src/engine/OSCEngineReceiver.cpp b/src/engine/OSCEngineReceiver.cpp index bf03b29d..59aac9e4 100644 --- a/src/engine/OSCEngineReceiver.cpp +++ b/src/engine/OSCEngineReceiver.cpp @@ -300,7 +300,9 @@ OSCEngineReceiver::_register_client_cb(const char* path, const char* types, lo_a lo_address addr = lo_message_get_source(msg); char* const url = lo_address_get_url(addr); - ClientInterface* client = new OSCClientSender((const char*)url); + ClientInterface* client = new OSCClientSender( + (const char*)url, + _engine.world()->conf()->option("packet-size").get_int32()); register_client(client); free(url); @@ -602,12 +604,13 @@ OSCEngineReceiver::unknown_cb(const char* path, const char* types, lo_arg** argv const lo_address addr = lo_message_get_source(msg); char* const url = lo_address_get_url(addr); - warn << "Unknown OSC command " << path << " (" << types << ")" << endl; + warn << "Unknown OSC command " << path << " (" << types << ") " + << "received from " << url << endl; string error_msg = "Unknown command: "; error_msg.append(path).append(" ").append(types); - OSCClientSender(url).error(error_msg); + lo_send(addr, "/error", "s", error_msg.c_str(), LO_ARGS_END); free(url); return 0; diff --git a/src/gui/ConnectWindow.cpp b/src/gui/ConnectWindow.cpp index f0e5c7b1..e5ade51c 100644 --- a/src/gui/ConnectWindow.cpp +++ b/src/gui/ConnectWindow.cpp @@ -192,11 +192,16 @@ ConnectWindow::connect(bool existing) if (!existing) { #ifdef HAVE_LIBLO if (scheme == "osc.udp" || scheme == "osc.tcp") - world->set_engine(SharedPtr<EngineInterface>(new OSCEngineSender(uri))); + world->set_engine( + SharedPtr<EngineInterface>( + new OSCEngineSender( + uri, + world->conf()->option("packet-size").get_int32()))); #endif #ifdef HAVE_SOUP if (scheme == "http") - world->set_engine(SharedPtr<EngineInterface>(new HTTPEngineSender(world, uri))); + world->set_engine(SharedPtr<EngineInterface>( + new HTTPEngineSender(world, uri))); #endif } else { uri = world->engine()->uri().str(); @@ -218,7 +223,9 @@ ConnectWindow::connect(bool existing) if (Raul::Process::launch(cmd)) { world->set_engine(SharedPtr<EngineInterface>( - new OSCEngineSender(string("osc.udp://localhost:").append(port_str)))); + new OSCEngineSender( + string("osc.udp://localhost:").append(port_str), + world->conf()->option("packet-size").get_int32()))); // FIXME: static args SharedPtr<ThreadedSigClientInterface> tsci(new ThreadedSigClientInterface(1024)); diff --git a/src/shared/Configuration.cpp b/src/shared/Configuration.cpp index 650a1d8b..64185fb3 100644 --- a/src/shared/Configuration.cpp +++ b/src/shared/Configuration.cpp @@ -51,6 +51,7 @@ Configuration::Configuration() .add("uuid", 'u', "JACK session UUID", Atom::STRING, "") #endif .add("load", 'l', "Load patch", Atom::STRING, Atom()) + .add("packet-size", 'k', "Maximum UDP packet size", Atom::INT, 4096) .add("parallelism", 'p', "Number of concurrent process threads", Atom::INT, 1) .add("path", 'L', "Target path for loaded patch", Atom::STRING, Atom()) .add("queue-size", 'q', "Event queue size", Atom::INT, 1024) diff --git a/src/shared/OSCSender.cpp b/src/shared/OSCSender.cpp index 58b9ddae..6c07551b 100644 --- a/src/shared/OSCSender.cpp +++ b/src/shared/OSCSender.cpp @@ -15,10 +15,12 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include <cassert> +#include <assert.h> #include <unistd.h> #include <stdarg.h> + #include "raul/log.hpp" + #include "OSCSender.hpp" #include "ingen-config.h" @@ -28,9 +30,10 @@ using namespace Raul; namespace Ingen { namespace Shared { -OSCSender::OSCSender() +OSCSender::OSCSender(size_t max_packet_size) : _bundle(NULL) , _address(NULL) + , _max_packet_size(max_packet_size) , _enabled(true) { } @@ -82,17 +85,13 @@ OSCSender::send(const char *path, const char *types, ...) void OSCSender::send_message(const char* path, lo_message msg) { - // FIXME: size? liblo doesn't export this. - // Don't want to exceed max UDP packet size (good default value?) - static const size_t MAX_BUNDLE_SIZE = 1024; - if (!_enabled) { lo_message_free(msg); return; } if (_bundle) { - if (lo_bundle_length(_bundle) + lo_message_length(msg, path) > MAX_BUNDLE_SIZE) { + if (lo_bundle_length(_bundle) + lo_message_length(msg, path) > _max_packet_size) { warn << "Maximum bundle size reached, bundle split" << endl; lo_send_bundle(_address, _bundle); lo_bundle_free_messages(_bundle); diff --git a/src/shared/OSCSender.hpp b/src/shared/OSCSender.hpp index 1085f2ae..34c5565a 100644 --- a/src/shared/OSCSender.hpp +++ b/src/shared/OSCSender.hpp @@ -18,7 +18,9 @@ #ifndef INGEN_SHARED_OSCSENDER_HPP #define INGEN_SHARED_OSCSENDER_HPP -#include <inttypes.h> +#include <stdbool.h> +#include <stddef.h> + #include <lo/lo.h> namespace Ingen { @@ -26,7 +28,7 @@ namespace Shared { class OSCSender { public: - OSCSender(); + OSCSender(size_t max_packet_size); virtual ~OSCSender() {} lo_address address() const { return _address; } @@ -40,6 +42,7 @@ protected: lo_bundle _bundle; lo_address _address; + size_t _max_packet_size; bool _enabled; }; |