Skip to content

Commit d1eb995

Browse files
committed
Bug in reconnectChannels().
1 parent 6f82af4 commit d1eb995

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

websocket-rails-client/websocket_rails.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ WebsocketRails::connection WebsocketRails::reconnect() {
7272
std::string oldconnection_id = this->conn != 0 ? this->conn->getConnectionId() : "";
7373
this->disconnect();
7474
if(this->connect() == "connected") {
75-
for(auto& x: this->queue) {
75+
for(auto& x: this->event_queue) {
7676
Event event = x.second;
7777
if(event.getConnectionId() == oldconnection_id && !event.isResult()) {
7878
this->triggerEvent(event);
@@ -118,10 +118,10 @@ void WebsocketRails::newMessage(jsonxx::Array data) {
118118
jsonxx::Array socket_message = data.get<jsonxx::Array>(_i);
119119
Event event(socket_message);
120120
if(event.isResult()) {
121-
if(this->queue.find(event.getId()) != this->queue.end()) {
122-
this->queue[event.getId()].runCallbacks(event.getSuccess(), event.getData());
121+
if(this->event_queue.find(event.getId()) != this->event_queue.end()) {
122+
this->event_queue[event.getId()].runCallbacks(event.getSuccess(), event.getData());
123123
}
124-
this->queue.erase(event.getId());
124+
this->event_queue.erase(event.getId());
125125
} else if(event.isChannel()) {
126126
this->dispatchChannel(event);
127127
} else if(event.isPing()) {
@@ -199,8 +199,8 @@ void WebsocketRails::trigger(std::string event_name, jsonxx::Object event_data,
199199

200200

201201
void WebsocketRails::triggerEvent(Event event) {
202-
if(this->queue.find(event.getId()) == this->queue.end()) {
203-
this->queue[event.getId()] = event;
202+
if(this->event_queue.find(event.getId()) == this->event_queue.end()) {
203+
this->event_queue[event.getId()] = event;
204204
}
205205
if(this->conn != 0) {
206206
this->conn->trigger(event);
@@ -214,55 +214,55 @@ void WebsocketRails::triggerEvent(Event event) {
214214
************************************/
215215

216216
Channel WebsocketRails::subscribe(std::string channel_name) {
217-
if(this->channels.find(channel_name) == this->channels.end()) {
217+
if(this->channel_queue.find(channel_name) == this->channel_queue.end()) {
218218
Channel channel(channel_name, *this, false);
219-
this->channels[channel_name] = channel;
219+
this->channel_queue[channel_name] = channel;
220220
return channel;
221221
} else {
222-
return this->channels[channel_name];
222+
return this->channel_queue[channel_name];
223223
}
224224
}
225225

226226

227227
Channel WebsocketRails::subscribe(std::string channel_name, cb_func success_callback, cb_func failure_callback) {
228-
if(this->channels.find(channel_name) == this->channels.end()) {
228+
if(this->channel_queue.find(channel_name) == this->channel_queue.end()) {
229229
Channel channel(channel_name, *this, false, success_callback, failure_callback);
230-
this->channels[channel_name] = channel;
230+
this->channel_queue[channel_name] = channel;
231231
return channel;
232232
} else {
233-
return this->channels[channel_name];
233+
return this->channel_queue[channel_name];
234234
}
235235
}
236236

237237

238238
Channel WebsocketRails::subscribePrivate(std::string channel_name) {
239-
if(this->channels.find(channel_name) == this->channels.end()) {
239+
if(this->channel_queue.find(channel_name) == this->channel_queue.end()) {
240240
Channel channel(channel_name, *this, true);
241-
this->channels[channel_name] = channel;
241+
this->channel_queue[channel_name] = channel;
242242
return channel;
243243
} else {
244-
return this->channels[channel_name];
244+
return this->channel_queue[channel_name];
245245
}
246246
}
247247

248248

249249
Channel WebsocketRails::subscribePrivate(std::string channel_name, cb_func success_callback, cb_func failure_callback) {
250-
if(this->channels.find(channel_name) == this->channels.end()) {
250+
if(this->channel_queue.find(channel_name) == this->channel_queue.end()) {
251251
Channel channel(channel_name, *this, true, success_callback, failure_callback);
252-
this->channels[channel_name] = channel;
252+
this->channel_queue[channel_name] = channel;
253253
return channel;
254254
} else {
255-
return this->channels[channel_name];
255+
return this->channel_queue[channel_name];
256256
}
257257
}
258258

259259

260260
void WebsocketRails::unsubscribe(std::string channel_name) {
261-
if(this->channels.find(channel_name) == this->channels.end()) {
261+
if(this->channel_queue.find(channel_name) == this->channel_queue.end()) {
262262
return;
263263
}
264-
this->channels[channel_name].destroy();
265-
this->channels.erase(channel_name);
264+
this->channel_queue[channel_name].destroy();
265+
this->channel_queue.erase(channel_name);
266266
}
267267

268268

@@ -296,10 +296,10 @@ void WebsocketRails::dispatch(Event event) {
296296

297297

298298
void WebsocketRails::dispatchChannel(Event event) {
299-
if(this->channels.find(event.getChannel()) == this->channels.end()) {
299+
if(this->channel_queue.find(event.getChannel()) == this->channel_queue.end()) {
300300
return;
301301
}
302-
this->channels[event.getChannel()].dispatch(event.getName(), event.getData());
302+
this->channel_queue[event.getChannel()].dispatch(event.getName(), event.getData());
303303
}
304304

305305

@@ -318,14 +318,14 @@ bool WebsocketRails::connectionStale() {
318318

319319
std::vector<Channel> WebsocketRails::reconnectChannels() {
320320
std::vector<Channel> results;
321-
for (auto& x: this->channels) {
321+
for (auto& x: this->channel_queue) {
322322
Channel channel = x.second;
323-
this->callbacks = channel.getCallbacks();
323+
map_vec_cb_func callbacks = channel.getCallbacks();
324324
channel.destroy();
325325
std::string channel_name = channel.getName();
326-
this->channels.erase(channel_name);
326+
this->channel_queue.erase(channel_name);
327327
channel = channel.isPrivate() ? this->subscribePrivate(channel_name) : this->subscribe(channel_name);
328-
channel.setCallbacks(this->callbacks);
328+
channel.setCallbacks(callbacks);
329329
results.push_back(channel);
330330
}
331331
return results;

websocket-rails-client/websocket_rails.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ class WebsocketRails {
9999
cb_func on_close_callback;
100100
cb_func on_fail_callback;
101101
map_vec_cb_func callbacks; /* Map<key,value>: Event Name, Callback Array */
102-
std::tr1::unordered_map<std::string, Channel> channels; /* Map<key,value>: Channel Name, Channel Object */
103-
std::tr1::unordered_map<std::string, Event> queue; /* Map<key,value>: Event UUID, Event Object */
102+
std::tr1::unordered_map<std::string, Channel> channel_queue; /* Map<key,value>: Channel Name, Channel Object */
103+
std::tr1::unordered_map<std::string, Event> event_queue; /* Map<key,value>: Event UUID, Event Object */
104104
WebsocketConnection * conn;
105105

106106
/**

0 commit comments

Comments
 (0)