From 7952f019562f83f186753f768a11e234184205f1 Mon Sep 17 00:00:00 2001 From: Brett Renfer Date: Mon, 21 Mar 2016 17:46:18 -0400 Subject: [PATCH 1/2] Removed defunct broadcast methods/events --- .../include/ofxLibwebsockets/Client.h | 1 - .../include/ofxLibwebsockets/Events.h | 1 - .../include/ofxLibwebsockets/Protocol.h | 5 ----- .../include/ofxLibwebsockets/Server.h | 8 +------ libs/ofxLibwebsockets/src/Protocol.cpp | 22 ------------------- libs/ofxLibwebsockets/src/Server.cpp | 8 ------- 6 files changed, 1 insertion(+), 44 deletions(-) diff --git a/libs/ofxLibwebsockets/include/ofxLibwebsockets/Client.h b/libs/ofxLibwebsockets/include/ofxLibwebsockets/Client.h index c749b99..6abdaa5 100644 --- a/libs/ofxLibwebsockets/include/ofxLibwebsockets/Client.h +++ b/libs/ofxLibwebsockets/include/ofxLibwebsockets/Client.h @@ -76,7 +76,6 @@ namespace ofxLibwebsockets { ofAddListener( clientProtocol.oncloseEvent, app, &T::onClose); ofAddListener( clientProtocol.onidleEvent, app, &T::onIdle); ofAddListener( clientProtocol.onmessageEvent, app, &T::onMessage); - ofAddListener( clientProtocol.onbroadcastEvent, app, &T::onBroadcast); } // get pointer to libwebsockets connection wrapper diff --git a/libs/ofxLibwebsockets/include/ofxLibwebsockets/Events.h b/libs/ofxLibwebsockets/include/ofxLibwebsockets/Events.h index 8087cbb..c44b1a0 100644 --- a/libs/ofxLibwebsockets/include/ofxLibwebsockets/Events.h +++ b/libs/ofxLibwebsockets/include/ofxLibwebsockets/Events.h @@ -35,5 +35,4 @@ namespace ofxLibwebsockets { ofEvent onClose; ofEvent onIdle; ofEvent onMessage; - ofEvent onBroadcast; };*/ \ No newline at end of file diff --git a/libs/ofxLibwebsockets/include/ofxLibwebsockets/Protocol.h b/libs/ofxLibwebsockets/include/ofxLibwebsockets/Protocol.h index 505463b..52625e9 100644 --- a/libs/ofxLibwebsockets/include/ofxLibwebsockets/Protocol.h +++ b/libs/ofxLibwebsockets/include/ofxLibwebsockets/Protocol.h @@ -33,8 +33,6 @@ namespace ofxLibwebsockets { virtual bool allowClient(const std::string name, const std::string ip) const; - void broadcast(const std::string& message); - unsigned int idx; unsigned int rx_buffer_size; @@ -49,7 +47,6 @@ namespace ofxLibwebsockets { virtual void onerror (Event& args); virtual void onidle (Event& args); virtual void onmessage (Event& args); - virtual void onbroadcast(Event& args); // internal events: called by Reactor ofEvent onconnectEvent; @@ -58,7 +55,6 @@ namespace ofxLibwebsockets { ofEvent onerrorEvent; ofEvent onidleEvent; ofEvent onmessageEvent; - ofEvent onbroadcastEvent; bool defaultAllowPolicy; std::map allowRules; @@ -74,7 +70,6 @@ namespace ofxLibwebsockets { void _onerror (Event& args); void _onidle (Event& args); void _onmessage (Event& args); - void _onbroadcast (Event& args); bool _allowClient(const std::string name, const std::string ip) const; diff --git a/libs/ofxLibwebsockets/include/ofxLibwebsockets/Server.h b/libs/ofxLibwebsockets/include/ofxLibwebsockets/Server.h index eedf92c..ea32c9b 100644 --- a/libs/ofxLibwebsockets/include/ofxLibwebsockets/Server.h +++ b/libs/ofxLibwebsockets/include/ofxLibwebsockets/Server.h @@ -59,11 +59,7 @@ namespace ofxLibwebsockets { // close the server void close(); - // broadcast a message to all connections - void broadcast( string message ); - - // send to all connections - // (sends normal message instead of broadcast) + // send to all connections void send( string message ); // send anything that has pixels to all connections @@ -95,7 +91,6 @@ namespace ofxLibwebsockets { ofAddListener( serverProtocol.oncloseEvent, app, &T::onClose); ofAddListener( serverProtocol.onidleEvent, app, &T::onIdle); ofAddListener( serverProtocol.onmessageEvent, app, &T::onMessage); - ofAddListener( serverProtocol.onbroadcastEvent, app, &T::onBroadcast); } template @@ -105,7 +100,6 @@ namespace ofxLibwebsockets { ofRemoveListener( serverProtocol.oncloseEvent, app, &T::onClose); ofRemoveListener( serverProtocol.onidleEvent, app, &T::onIdle); ofRemoveListener( serverProtocol.onmessageEvent, app, &T::onMessage); - ofRemoveListener( serverProtocol.onbroadcastEvent, app, &T::onBroadcast); } //getters diff --git a/libs/ofxLibwebsockets/src/Protocol.cpp b/libs/ofxLibwebsockets/src/Protocol.cpp index 6899568..c852fde 100644 --- a/libs/ofxLibwebsockets/src/Protocol.cpp +++ b/libs/ofxLibwebsockets/src/Protocol.cpp @@ -20,7 +20,6 @@ namespace ofxLibwebsockets { ofAddListener(oncloseEvent, this, &Protocol::_onclose); ofAddListener(onidleEvent, this, &Protocol::_onidle); ofAddListener(onmessageEvent, this, &Protocol::_onmessage); - ofAddListener(onbroadcastEvent, this, &Protocol::_onbroadcast); ofAddListener(onerrorEvent, this, &Protocol::_onerror); rx_buffer_size = OFX_LWS_MAX_BUFFER; idle = false; @@ -33,7 +32,6 @@ namespace ofxLibwebsockets { ofRemoveListener(oncloseEvent, this, &Protocol::_onclose); ofRemoveListener(onidleEvent, this, &Protocol::_onidle); ofRemoveListener(onmessageEvent, this, &Protocol::_onmessage); - ofRemoveListener(onbroadcastEvent, this, &Protocol::_onbroadcast); ofRemoveListener(onerrorEvent, this, &Protocol::_onerror); rx_buffer_size = OFX_LWS_MAX_BUFFER; idle = false; @@ -94,24 +92,4 @@ namespace ofxLibwebsockets { } void Protocol::onmessage(Event&args){} - - //-------------------------------------------------------------- - void Protocol::_onbroadcast(Event& args){ onbroadcast(args); } - - void Protocol::onbroadcast(Event&args){ args.conn.send(args.message); } - - //-------------------------------------------------------------- - void Protocol::broadcast(const std::string& message){ - std::string buf(LWS_SEND_BUFFER_PRE_PADDING+message.size()+LWS_SEND_BUFFER_POST_PADDING, 0); - unsigned char *p = (unsigned char*)&buf[LWS_SEND_BUFFER_PRE_PADDING]; - - if (reactor != NULL) - { - memcpy(p, message.c_str(), message.size()); - //int n = libwebsockets_broadcast(&reactor->lws_protocols[idx], p, message.size()); - int n = libwebsocket_callback_on_writable_all_protocol(&reactor->lws_protocols[idx]); - if (n < 0) - fprintf(stderr, "ERROR writing to socket"); - } - } } diff --git a/libs/ofxLibwebsockets/src/Server.cpp b/libs/ofxLibwebsockets/src/Server.cpp index 56ee006..14c697f 100755 --- a/libs/ofxLibwebsockets/src/Server.cpp +++ b/libs/ofxLibwebsockets/src/Server.cpp @@ -149,14 +149,6 @@ namespace ofxLibwebsockets { } libwebsocket_context_destroy(context); } - - //-------------------------------------------------------------- - void Server::broadcast( string message ){ - // loop through all protocols and broadcast! - for (int i=0; ibroadcast( message ); - } - } //-------------------------------------------------------------- void Server::send( string message ){ From 648e1fe0cf3612fbca3a559a84b11714dba66e8f Mon Sep 17 00:00:00 2001 From: Brett Renfer Date: Mon, 21 Mar 2016 18:00:09 -0400 Subject: [PATCH 2/2] Passing ofBuffer as reference to avoid copies --- libs/ofxLibwebsockets/include/ofxLibwebsockets/Client.h | 2 +- libs/ofxLibwebsockets/include/ofxLibwebsockets/Connection.h | 2 +- libs/ofxLibwebsockets/include/ofxLibwebsockets/Server.h | 2 +- libs/ofxLibwebsockets/src/Client.cpp | 2 +- libs/ofxLibwebsockets/src/Connection.cpp | 2 +- libs/ofxLibwebsockets/src/Server.cpp | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libs/ofxLibwebsockets/include/ofxLibwebsockets/Client.h b/libs/ofxLibwebsockets/include/ofxLibwebsockets/Client.h index 6abdaa5..0f73db9 100644 --- a/libs/ofxLibwebsockets/include/ofxLibwebsockets/Client.h +++ b/libs/ofxLibwebsockets/include/ofxLibwebsockets/Client.h @@ -65,7 +65,7 @@ namespace ofxLibwebsockets { } // send any binary data - void sendBinary( ofBuffer buffer ); + void sendBinary( ofBuffer & buffer ); void sendBinary( unsigned char * data, int size ); void sendBinary( char * data, int size ); diff --git a/libs/ofxLibwebsockets/include/ofxLibwebsockets/Connection.h b/libs/ofxLibwebsockets/include/ofxLibwebsockets/Connection.h index d59e311..73c0a58 100644 --- a/libs/ofxLibwebsockets/include/ofxLibwebsockets/Connection.h +++ b/libs/ofxLibwebsockets/include/ofxLibwebsockets/Connection.h @@ -45,7 +45,7 @@ namespace ofxLibwebsockets { sendBinary( (char *) image.getPixels().getData(), size ); } - void sendBinary( ofBuffer buffer ); + void sendBinary( ofBuffer & buffer ); void sendBinary( unsigned char * data, unsigned int size ); void sendBinary( char * data, unsigned int size ); diff --git a/libs/ofxLibwebsockets/include/ofxLibwebsockets/Server.h b/libs/ofxLibwebsockets/include/ofxLibwebsockets/Server.h index ea32c9b..895b34f 100644 --- a/libs/ofxLibwebsockets/include/ofxLibwebsockets/Server.h +++ b/libs/ofxLibwebsockets/include/ofxLibwebsockets/Server.h @@ -77,7 +77,7 @@ namespace ofxLibwebsockets { } // send any binary data to all connections - void sendBinary( ofBuffer buffer ); + void sendBinary( ofBuffer & buffer ); void sendBinary( unsigned char * data, int size ); void sendBinary( char * data, int size ); diff --git a/libs/ofxLibwebsockets/src/Client.cpp b/libs/ofxLibwebsockets/src/Client.cpp index 380c561..40196aa 100755 --- a/libs/ofxLibwebsockets/src/Client.cpp +++ b/libs/ofxLibwebsockets/src/Client.cpp @@ -222,7 +222,7 @@ namespace ofxLibwebsockets { } //-------------------------------------------------------------- - void Client::sendBinary( ofBuffer buffer ){ + void Client::sendBinary( ofBuffer & buffer ){ if ( connection != NULL){ connection->sendBinary(buffer); } diff --git a/libs/ofxLibwebsockets/src/Connection.cpp b/libs/ofxLibwebsockets/src/Connection.cpp index 50da7f8..f06773a 100644 --- a/libs/ofxLibwebsockets/src/Connection.cpp +++ b/libs/ofxLibwebsockets/src/Connection.cpp @@ -82,7 +82,7 @@ namespace ofxLibwebsockets { } //-------------------------------------------------------------- - void Connection::sendBinary( ofBuffer buffer ){ + void Connection::sendBinary( ofBuffer & buffer ){ sendBinary(buffer.getData(), buffer.size()); } diff --git a/libs/ofxLibwebsockets/src/Server.cpp b/libs/ofxLibwebsockets/src/Server.cpp index 14c697f..83ea376 100755 --- a/libs/ofxLibwebsockets/src/Server.cpp +++ b/libs/ofxLibwebsockets/src/Server.cpp @@ -160,7 +160,7 @@ namespace ofxLibwebsockets { } //-------------------------------------------------------------- - void Server::sendBinary( ofBuffer buffer ){ + void Server::sendBinary( ofBuffer & buffer ){ sendBinary(buffer.getData(), buffer.size()); }