Skip to content

Commit 4204626

Browse files
Fixed one-to-many sending
1 parent 6290bc8 commit 4204626

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed

libs/ofxLibwebsockets/include/ofxLibwebsockets/Connection.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ namespace ofxLibwebsockets {
7070
// MUST be called from main thread (e.g. client or server)
7171
void update();
7272

73+
bool isIdle();
74+
7375
protected:
7476
std::string client_ip;
7577
std::string client_name;
@@ -84,6 +86,11 @@ namespace ofxLibwebsockets {
8486
// threading stuff
8587
std::deque<TextPacket> messages_text;
8688
std::deque<BinaryPacket> messages_binary;
89+
90+
void setIdle( bool isIdle=true );
91+
92+
private:
93+
bool idle;
8794
};
8895

8996

libs/ofxLibwebsockets/include/ofxLibwebsockets/Protocol.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ namespace ofxLibwebsockets {
3737

3838
void broadcast(const std::string& message);
3939

40-
bool isIdle();
41-
4240
unsigned int idx;
4341
unsigned int rx_buffer_size;
4442

libs/ofxLibwebsockets/src/Connection.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace ofxLibwebsockets {
2424
buf = (unsigned char*)calloc(LWS_SEND_BUFFER_PRE_PADDING+bufferSize+LWS_SEND_BUFFER_POST_PADDING, sizeof(unsigned char));
2525
binaryBuf = (unsigned char*)calloc(LWS_SEND_BUFFER_PRE_PADDING+bufferSize+LWS_SEND_BUFFER_POST_PADDING, sizeof(unsigned char));
2626
}
27+
idle = false;
2728
}
2829

2930
//--------------------------------------------------------------
@@ -109,7 +110,7 @@ namespace ofxLibwebsockets {
109110
//--------------------------------------------------------------
110111
void Connection::update(){
111112
// process standard ws messages
112-
if ( messages_text.size() > 0 && protocol->idle ){
113+
if ( messages_text.size() > 0 && idle ){
113114
// grab first packet
114115
TextPacket & packet = messages_text[0];
115116

@@ -131,7 +132,7 @@ namespace ofxLibwebsockets {
131132

132133
// actual write to libwebsockets
133134
memcpy(&buf[LWS_SEND_BUFFER_PRE_PADDING], packet.message.c_str() + packet.index, dataSize );
134-
protocol->idle = false;
135+
idle = false;
135136

136137
int n = libwebsocket_write(ws, &buf[LWS_SEND_BUFFER_PRE_PADDING], dataSize, (libwebsocket_write_protocol) writeMode );
137138

@@ -152,7 +153,7 @@ namespace ofxLibwebsockets {
152153
}
153154

154155
// process binary messages
155-
if ( messages_binary.size() > 0 && protocol->idle ){
156+
if ( messages_binary.size() > 0 && idle ){
156157
if ( messages_binary.size() > 0 ){
157158
BinaryPacket & packet = messages_binary[0];
158159

@@ -170,7 +171,7 @@ namespace ofxLibwebsockets {
170171
memcpy(&binaryBuf[LWS_SEND_BUFFER_PRE_PADDING], packet.data + packet.index, dataSize );
171172

172173
// this sets the protocol to wait until "idle"
173-
protocol->idle = false; // todo: this should be automatic on write!
174+
idle = false; // todo: this should be automatic on write!
174175

175176
int n = libwebsocket_write(ws, &binaryBuf[LWS_SEND_BUFFER_PRE_PADDING], dataSize, (libwebsocket_write_protocol) writeMode );
176177
libwebsocket_callback_on_writable(context, ws);
@@ -189,6 +190,18 @@ namespace ofxLibwebsockets {
189190
libwebsocket_callback_on_writable(context, ws);
190191
}
191192
}
193+
//--------------------------------------------------------------
194+
void Connection::setIdle( bool isIdle ){
195+
idle = isIdle;
196+
static string dum ="";
197+
Event args(*this, dum);
198+
ofNotifyEvent(protocol->onidleEvent, args);
199+
}
200+
201+
//--------------------------------------------------------------
202+
bool Connection::isIdle(){
203+
return idle;
204+
}
192205

193206
//--------------------------------------------------------------
194207
bool Connection::operator==( const Connection &other ){

libs/ofxLibwebsockets/src/Protocol.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ namespace ofxLibwebsockets {
8080
void Protocol::_onerror(Event& args){ onerror(args); }
8181

8282
void Protocol::onerror(Event&args){}
83-
84-
//--------------------------------------------------------------
85-
bool Protocol::isIdle(){
86-
return idle;
87-
}
8883

8984
void Protocol::_onidle(Event& args){
9085
idle = true;

libs/ofxLibwebsockets/src/Reactor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ namespace ofxLibwebsockets {
173173
case LWS_CALLBACK_SERVER_WRITEABLE:
174174
case LWS_CALLBACK_CLIENT_WRITEABLE:
175175
// idle is good! means you can write again
176-
ofNotifyEvent(conn->protocol->onidleEvent, args);
176+
conn->setIdle();
177177
break;
178178

179179
case LWS_CALLBACK_RECEIVE: // server receive

0 commit comments

Comments
 (0)