Browse code

sip: propagate send flags down to transport layer

Raphael Coeffic authored on 13/11/2013 17:36:44
Showing 9 changed files
... ...
@@ -129,10 +129,10 @@ void sip_msg::release()
129 129
     local_socket = NULL;
130 130
 }
131 131
 
132
-int sip_msg::send()
132
+int sip_msg::send(unsigned int flags)
133 133
 {
134 134
     assert(local_socket);
135
-    return local_socket->send(&remote_ip,buf,len);
135
+    return local_socket->send(&remote_ip,buf,len,flags);
136 136
 }
137 137
 
138 138
 
... ...
@@ -137,7 +137,7 @@ struct sip_msg
137 137
     sip_msg(const char* msg_buf, int msg_len);
138 138
     ~sip_msg();
139 139
 
140
-    int send();
140
+    int send(unsigned flags);
141 141
 
142 142
     /**
143 143
      * Releases pointers otherwise deleted by the destructor
... ...
@@ -122,7 +122,7 @@ void sip_trans::retransmit()
122 122
     }
123 123
     assert(retr_socket);
124 124
 
125
-    int send_err = retr_socket->send(&retr_addr,retr_buf,retr_len);
125
+    int send_err = retr_socket->send(&retr_addr,retr_buf,retr_len,flags);
126 126
     if(send_err < 0){
127 127
 	ERROR("Error from transport layer\n");
128 128
     }
... ...
@@ -220,7 +220,7 @@ int tcp_trsp_socket::check_connection()
220 220
 }
221 221
 
222 222
 int tcp_trsp_socket::send(const sockaddr_storage* sa, const char* msg, 
223
-			  const int msg_len)
223
+			  const int msg_len, unsigned int flags)
224 224
 {
225 225
   AmLock _l(sock_mut);
226 226
 
... ...
@@ -567,12 +567,13 @@ void tcp_server_socket::on_accept(int sd, short ev)
567 567
     return;
568 568
   }
569 569
 
570
+  DBG("tcp_trsp_socket::create_connected");
570 571
   // in case of thread pooling, do following in worker thread
571 572
   tcp_trsp_socket::create_connected(this,connection_sd,&src_addr,evbase);
572 573
 }
573 574
 
574 575
 int tcp_server_socket::send(const sockaddr_storage* sa, const char* msg,
575
-			    const int msg_len)
576
+			    const int msg_len, unsigned int flags)
576 577
 {
577 578
   char host_buf[NI_MAXHOST];
578 579
   string dest = am_inet_ntop(sa,host_buf,NI_MAXHOST);
... ...
@@ -601,7 +602,7 @@ int tcp_server_socket::send(const sockaddr_storage* sa, const char* msg,
601 602
 
602 603
   // must be done outside from connections_mut
603 604
   // to avoid dead-lock with the event base
604
-  int ret = sock->send(sa,msg,msg_len);
605
+  int ret = sock->send(sa,msg,msg_len,flags);
605 606
   if((ret < 0) && new_conn) {
606 607
     remove_connection(sock);
607 608
   }
... ...
@@ -166,7 +166,8 @@ public:
166 166
    * Sends a message (push it to send-queue).
167 167
    * @return -1 if error(s) occured.
168 168
    */
169
-  int send(const sockaddr_storage* sa, const char* msg, const int msg_len);
169
+  int send(const sockaddr_storage* sa, const char* msg,
170
+	   const int msg_len, unsigned int flags);
170 171
 };
171 172
 
172 173
 class tcp_server_socket: public trsp_socket
... ...
@@ -204,7 +205,8 @@ public:
204 205
   void on_accept(int sd, short ev);
205 206
 
206 207
   int bind(const string& address, unsigned short port);
207
-  int send(const sockaddr_storage* sa, const char* msg, const int msg_len);
208
+  int send(const sockaddr_storage* sa, const char* msg,
209
+	   const int msg_len, unsigned int flags);
208 210
 
209 211
   void add_connection(tcp_trsp_socket* client_sock);
210 212
   void remove_connection(tcp_trsp_socket* client_sock);
... ...
@@ -467,7 +467,8 @@ int _trans_layer::send_reply(const trans_ticket* tt, const cstring& dialog_id,
467 467
 	ntohs(((sockaddr_in*)&remote_ip)->sin_port),
468 468
 	50 /* preview - instead of p_msg->len */,reply_buf);
469 469
 
470
-    err = local_socket->send(&remote_ip,reply_buf,reply_len);
470
+    //TODO: pass send-flags down to here
471
+    err = local_socket->send(&remote_ip,reply_buf,reply_len,0);
471 472
     if(err < 0){
472 473
 	ERROR("could not send to %s:%i <%.*s...>\n",
473 474
 	      get_addr_str(&remote_ip).c_str(),
... ...
@@ -676,7 +677,7 @@ int _trans_layer::send_sl_reply(sip_msg* req, int reply_code,
676 677
 
677 678
     assert(req->local_socket);
678 679
 
679
-    int err = req->local_socket->send(&req->remote_ip,reply_buf,reply_len);
680
+    int err = req->local_socket->send(&req->remote_ip,reply_buf,reply_len,0);
680 681
     delete [] reply_buf;
681 682
 
682 683
     stats.inc_sent_replies();
... ...
@@ -1305,7 +1306,7 @@ int _trans_layer::send_request(sip_msg* msg, trans_ticket* tt,
1305 1306
 				   get_cseq(p_msg)->num_str);
1306 1307
     tt->_bucket->lock();
1307 1308
     
1308
-    int send_err = p_msg->send();
1309
+    int send_err = p_msg->send(flags);
1309 1310
     if(send_err < 0){
1310 1311
 	ERROR("Error from transport layer\n");
1311 1312
 	delete p_msg;
... ...
@@ -1494,7 +1495,7 @@ int _trans_layer::cancel(trans_ticket* tt, const cstring& hdrs)
1494 1495
 	ntohs(((sockaddr_in*)&p_msg->remote_ip)->sin_port),
1495 1496
 	p_msg->len,p_msg->buf);
1496 1497
 
1497
-    int send_err = p_msg->send();
1498
+    int send_err = p_msg->send(t->flags);
1498 1499
     if(send_err < 0){
1499 1500
 	ERROR("Error from transport layer\n");
1500 1501
 	delete p_msg;
... ...
@@ -2201,7 +2202,8 @@ void _trans_layer::send_non_200_ack(sip_msg* reply, sip_trans* t)
2201 2202
     DBG("About to send ACK\n");
2202 2203
 
2203 2204
     assert(inv->local_socket);
2204
-    int send_err = inv->local_socket->send(&inv->remote_ip,ack_buf,ack_len);
2205
+    int send_err = inv->local_socket->send(&inv->remote_ip,ack_buf,
2206
+					   ack_len,t->flags);
2205 2207
     if(send_err < 0){
2206 2208
 	ERROR("Error from transport layer\n");
2207 2209
     }
... ...
@@ -2228,7 +2230,7 @@ void _trans_layer::timer_expired(trans_timer* t, trans_bucket* bucket,
2228 2230
     case STIMER_A:  // Calling: (re-)send INV
2229 2231
 
2230 2232
 	n++;
2231
-	tr->msg->send();
2233
+	tr->msg->send(tr->flags);
2232 2234
         stats.inc_sent_request_retrans();
2233 2235
 	
2234 2236
 	if(tr->logger) {
... ...
@@ -2383,7 +2385,7 @@ void _trans_layer::timer_expired(trans_timer* t, trans_bucket* bucket,
2383 2385
 	else {
2384 2386
 
2385 2387
 	    // re-transmit request
2386
-	    tr->msg->send();
2388
+	    tr->msg->send(tr->flags);
2387 2389
             stats.inc_sent_request_retrans();
2388 2390
 
2389 2391
 	    if(tr->logger) {
... ...
@@ -2653,7 +2655,7 @@ int _trans_layer::try_next_ip(trans_bucket* bucket, sip_trans* tr,
2653 2655
     stats.inc_sent_requests();
2654 2656
 
2655 2657
     // and re-send
2656
-    tr->msg->send();
2658
+    tr->msg->send(tr->flags);
2657 2659
     
2658 2660
     if(tr->logger) {
2659 2661
 	sockaddr_storage src_ip;
... ...
@@ -148,7 +148,8 @@ public:
148 148
      * Sends a message.
149 149
      * @return -1 if error(s) occured.
150 150
      */
151
-    virtual int send(const sockaddr_storage* sa, const char* msg, const int msg_len)=0;
151
+    virtual int send(const sockaddr_storage* sa, const char* msg, 
152
+		     const int msg_len, unsigned int flags)=0;
152 153
 };
153 154
 
154 155
 class transport: public AmThread
... ...
@@ -248,7 +248,8 @@ int udp_trsp_socket::sendmsg(const sockaddr_storage* sa,
248 248
 
249 249
 int udp_trsp_socket::send(const sockaddr_storage* sa, 
250 250
 			  const char* msg, 
251
-			  const int msg_len)
251
+			  const int msg_len,
252
+			  unsigned int flags)
252 253
 {
253 254
     if (log_level_raw_msgs >= 0) {
254 255
 	_LOG(log_level_raw_msgs, 
... ...
@@ -69,7 +69,8 @@ public:
69 69
      * Sends a message.
70 70
      * @return -1 if error(s) occured.
71 71
      */
72
-    int send(const sockaddr_storage* sa, const char* msg, const int msg_len);
72
+    int send(const sockaddr_storage* sa, const char* msg,
73
+	     const int msg_len, unsigned int flags);
73 74
 };
74 75
 
75 76
 class udp_trsp: public transport