@@ -18,19 +18,20 @@ namespace drachtio {
18
18
19
19
IIP::IIP (nta_leg_t * leg, nta_incoming_t * irq, const std::string& transactionId, std::shared_ptr<SipDialog> dlg) :
20
20
m_leg (leg), m_irq(irq), m_orq(nullptr ), m_strTransactionId(transactionId), m_dlg(dlg),
21
- m_role (uas_role),m_rel( nullptr ), m_bCanceled(false ), m_tmCreated(sip_now()), m_ppSelf(nullptr ), m_timerCancel(nullptr ) {
21
+ m_role (uas_role), m_bCanceled(false ), m_tmCreated(sip_now()), m_ppSelf(nullptr ), m_timerCancel(nullptr ) {
22
22
DR_LOG (log_debug) << " adding IIP " << *this ;
23
23
}
24
24
25
25
IIP::IIP (nta_leg_t * leg, nta_outgoing_t * orq, const string& transactionId, std::shared_ptr<SipDialog> dlg) :
26
26
m_leg (leg), m_irq(nullptr ), m_orq(orq), m_strTransactionId(transactionId), m_dlg(dlg),
27
- m_role (uac_role),m_rel( nullptr ), m_bCanceled(false ), m_tmCreated(sip_now()), m_ppSelf(nullptr ), m_timerCancel(nullptr ) {
27
+ m_role (uac_role), m_bCanceled(false ), m_tmCreated(sip_now()), m_ppSelf(nullptr ), m_timerCancel(nullptr ) {
28
28
DR_LOG (log_debug) << " adding IIP " << *this ;
29
29
}
30
30
31
31
IIP::~IIP () {
32
- stopCancelTimer () ;
33
- if ( m_ppSelf) delete m_ppSelf ;
32
+ stopCancelTimer ();
33
+ destroyAllReliables ();
34
+ if ( m_ppSelf) delete m_ppSelf;
34
35
}
35
36
36
37
void IIP::doCancelTimerHandling (void ) {
@@ -66,7 +67,11 @@ namespace drachtio {
66
67
" leg:" << iip.leg () <<
67
68
" irq:" << iip.irq () <<
68
69
" orq:" << iip.orq () <<
69
- " rel:" << iip.rel () ;
70
+ " reliables:[" ;
71
+ for (auto rel : iip.reliables ()) {
72
+ os << rel << " " ;
73
+ }
74
+ os << " ]" ;
70
75
return os;
71
76
}
72
77
@@ -119,12 +124,16 @@ namespace drachtio {
119
124
}
120
125
121
126
bool IIP_FindByReliable (const InvitesInProgress_t& iips, nta_reliable_t * rel, std::shared_ptr<IIP>& iip) {
122
- std::lock_guard<std::mutex> lock (iip_mutex) ;
123
- auto &idx = iips.get <RelTag>();
124
- auto it = idx.find (rel);
125
- if (it == idx.end ()) return false ;
126
- iip = *it;
127
- return true ;
127
+ std::lock_guard<std::mutex> lock (iip_mutex);
128
+ auto &idx = iips.get <TransactionIdTag>();
129
+ for (auto it = idx.begin (); it != idx.end (); ++it) {
130
+ const auto & reliables = (*it)->reliables ();
131
+ if (std::find (reliables.begin (), reliables.end (), rel) != reliables.end ()) {
132
+ iip = *it;
133
+ return true ;
134
+ }
135
+ }
136
+ return false ;
128
137
}
129
138
130
139
bool IIP_FindByTransactionId (const InvitesInProgress_t& iips, const std::string& transactionId, std::shared_ptr<IIP>& iip) {
@@ -144,21 +153,20 @@ namespace drachtio {
144
153
}
145
154
146
155
void IIP_Clear (InvitesInProgress_t& iips, std::shared_ptr<IIP>& iip) {
147
- std::lock_guard<std::mutex> lock (iip_mutex) ;
156
+ std::lock_guard<std::mutex> lock (iip_mutex);
148
157
149
158
nta_incoming_t * irq = const_cast <nta_incoming_t *>(iip->irq ());
150
159
nta_outgoing_t * orq = const_cast <nta_outgoing_t *>(iip->orq ());
151
- nta_reliable_t * rel = const_cast <nta_reliable_t *>(iip->rel ());
152
- if (irq) nta_incoming_destroy (irq) ;
160
+ if (irq) nta_incoming_destroy (irq);
153
161
154
- // DH: tmp commented this out as it appears to cause a crash
155
- // https://github.com/davehorton/drachtio-server/issues/76#event-2662761148
156
- // this needs investigation, because it also causes a memory leak
157
- // if( orq ) nta_outgoing_destroy( orq ) ;
158
- //
159
- // later note: the orq of the uac INVITE (as well as orq of uac ACK) is destroyed in SipDialog destructor
162
+ // DH: tmp commented this out as it appears to cause a crash
163
+ // https://github.com/davehorton/drachtio-server/issues/76#event-2662761148
164
+ // this needs investigation, because it also causes a memory leak
165
+ // if( orq ) nta_outgoing_destroy( orq ) ;
166
+ //
167
+ // later note: the orq of the uac INVITE (as well as orq of uac ACK) is destroyed in SipDialog destructor
160
168
161
- if (rel) nta_reliable_destroy (rel) ;
169
+ iip-> destroyAllReliables () ;
162
170
163
171
auto &idx = iips.get <LegTag>();
164
172
idx.erase (iip->leg ());
@@ -170,14 +178,23 @@ namespace drachtio {
170
178
return idx.size ();
171
179
}
172
180
173
- /* since we are changing a key of the multiindex we need to use modify on the index */
174
- void IIP_SetReliable (InvitesInProgress_t& iips, std::shared_ptr<IIP>& iip, nta_reliable_t * rel) {
175
- std::lock_guard<std::mutex> lock (iip_mutex) ;
181
+ void IIP_AddReliable (InvitesInProgress_t& iips, std::shared_ptr<IIP>& iip, nta_reliable_t * rel) {
182
+ std::lock_guard<std::mutex> lock (iip_mutex);
183
+ const std::string& transactionId = iip->getTransactionId ();
184
+ auto &idx = iips.get <TransactionIdTag>();
185
+ auto it = idx.find (transactionId);
186
+ idx.modify (it, [rel](std::shared_ptr<IIP>& iip) {
187
+ iip->addReliable (rel);
188
+ });
189
+ }
190
+
191
+ void IIP_DestroyReliable (InvitesInProgress_t& iips, std::shared_ptr<IIP>& iip, nta_reliable_t * rel) {
192
+ std::lock_guard<std::mutex> lock (iip_mutex);
176
193
const std::string& transactionId = iip->getTransactionId ();
177
194
auto &idx = iips.get <TransactionIdTag>();
178
195
auto it = idx.find (transactionId);
179
196
idx.modify (it, [rel](std::shared_ptr<IIP>& iip) {
180
- iip->setReliable (rel);
197
+ iip->destroyReliable (rel);
181
198
});
182
199
}
183
200
0 commit comments