Skip to content

Commit

Permalink
sips: fix non-read messages at shutdown
Browse files Browse the repository at this point in the history
Force received messages to be handled by application
before handling disconnected state event.
This fixed some later call failure event as SIP bye message
is read after the transport shutdown (causing failure).

Change-Id: I269c364927ad301cc6e067b582174e488bebd519
Tuleap: #466
  • Loading branch information
Guillaume Roguez authored and gerrit2 committed Mar 16, 2016
1 parent 6c92660 commit e716157
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/ringdht/sips_transport_ice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,31 @@ void
SipsIceTransport::handleEvents()
{
// Notify transport manager about state changes first
// Note: stop when disconnected event is encountered
// and differ its notification AFTER pending rx msg to let
// them a chance to be delivered to application before closing
// the transport.
decltype(stateChangeEvents_) eventDataQueue;
{
std::lock_guard<std::mutex> lk{stateChangeEventsMutex_};
eventDataQueue = std::move(stateChangeEvents_);
stateChangeEvents_.clear();
}

if (auto state_cb = pjsip_tpmgr_get_state_cb(trData_.base.tpmgr)) {
ChangeStateEventData disconnectedEvent;
bool disconnected = false;
auto state_cb = pjsip_tpmgr_get_state_cb(trData_.base.tpmgr);
if (state_cb) {
for (auto& evdata : eventDataQueue) {
evdata.tls_info.ssl_sock_info = &evdata.ssl_info;
evdata.state_info.ext_info = &evdata.tls_info;
(*state_cb)(&trData_.base, evdata.state, &evdata.state_info);
if (evdata.state != PJSIP_TP_STATE_DISCONNECTED) {
(*state_cb)(&trData_.base, evdata.state, &evdata.state_info);
} else {
disconnectedEvent = std::move(evdata);
disconnected = true;
break;
}
}
}

Expand Down Expand Up @@ -328,6 +341,10 @@ SipsIceTransport::handleEvents()
}
}
}

// Time to deliver disconnected event if exists
if (disconnected and state_cb)
(*state_cb)(&trData_.base, disconnectedEvent.state, &disconnectedEvent.state_info);
}

void
Expand Down

0 comments on commit e716157

Please sign in to comment.