Skip to content

Commit 4dff670

Browse files
Error checking, no longer passing message as reference for more thread safety
1 parent 4204626 commit 4dff670

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

libs/ofxLibwebsockets/include/ofxLibwebsockets/Events.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ namespace ofxLibwebsockets {
1616

1717
class Event {
1818
public:
19-
Event(Connection& _conn, std::string& _message, bool isBinary=false);
19+
Event(Connection& _conn, std::string _message, bool isBinary=false);
2020

2121
Connection& conn;
22-
std::string& message; // message from ws OR error message if error
22+
std::string message; // message from ws OR error message if error
2323
Json::Value json;
2424

2525
// binary data

libs/ofxLibwebsockets/src/Connection.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ namespace ofxLibwebsockets {
3131
Connection::~Connection(){
3232
free(buf);
3333
free(binaryBuf);
34+
35+
// delete all pending frames
36+
messages_binary.clear();
37+
messages_text.clear();
3438
}
3539
//--------------------------------------------------------------
3640
void Connection::close() {
@@ -194,8 +198,10 @@ namespace ofxLibwebsockets {
194198
void Connection::setIdle( bool isIdle ){
195199
idle = isIdle;
196200
static string dum ="";
197-
Event args(*this, dum);
198-
ofNotifyEvent(protocol->onidleEvent, args);
201+
if ( protocol != NULL ){
202+
Event args(*this, dum);
203+
ofNotifyEvent(protocol->onidleEvent, args);
204+
}
199205
}
200206

201207
//--------------------------------------------------------------

libs/ofxLibwebsockets/src/Events.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace ofxLibwebsockets {
1111

1212
//--------------------------------------------------------------
13-
Event::Event(Connection& _conn, std::string& _message, bool isBinary)
13+
Event::Event(Connection& _conn, std::string _message, bool isBinary)
1414
: conn(_conn)
1515
, message(_message)
1616
, isBinary(isBinary)

libs/ofxLibwebsockets/src/Reactor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ namespace ofxLibwebsockets {
105105

106106
// this happens with events that don't use the connection
107107
// so not always a problem
108-
if (conn == NULL || conn->protocol == NULL){
108+
if (conn == NULL || conn->protocol == NULL || conn->ws == NULL ){
109109
if (conn == NULL){
110110
ofLog(OF_LOG_WARNING, "[ofxLibwebsockets] connection is null ");
111111
} else {

0 commit comments

Comments
 (0)