Browse code

sip: tcp: small fixes to avoid libevent errors

Raphael Coeffic authored on 18/11/2013 13:51:08
Showing 1 changed files
... ...
@@ -225,6 +225,11 @@ int tcp_trsp_socket::check_connection()
225 225
     if(ret < 0) {
226 226
       add_write_event_ul(server_sock->get_connect_timeout());
227 227
       DBG("connect event added...");
228
+
229
+      // because of unlock in ad_write_event_ul,
230
+      // on_connect() might already have been scheduled
231
+      if(closed)
232
+	return -1;
228 233
     }
229 234
     else {
230 235
       // connect succeeded immediatly
... ...
@@ -246,9 +251,11 @@ int tcp_trsp_socket::send(const sockaddr_storage* sa, const char* msg,
246 251
 
247 252
   send_q.push_back(new msg_buf(sa,msg,msg_len));
248 253
 
249
-  add_write_event_ul();
250
-  DBG("write event added...");
251
-    
254
+  if(connected) {
255
+    add_write_event_ul();
256
+    DBG("write event added...");
257
+  }
258
+
252 259
   return 0;
253 260
 }
254 261