Module: kamailio
Branch: master
Commit: 35861261a4ef04cf785e9169aad0cde7ee7dd336
URL: 
https://github.com/kamailio/kamailio/commit/35861261a4ef04cf785e9169aad0cde7ee7dd336

Author: Camille Oudot <[email protected]>
Committer: Camille Oudot <[email protected]>
Date: 2016-10-06T16:42:40+02:00

core: dedicated struct for TCP closed events

this will allow to differentiate between the different reasons for
connection closed events

---

Modified: tcp_conn.h
Modified: tcp_read.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/35861261a4ef04cf785e9169aad0cde7ee7dd336.diff
Patch: 
https://github.com/kamailio/kamailio/commit/35861261a4ef04cf785e9169aad0cde7ee7dd336.patch

---

diff --git a/tcp_conn.h b/tcp_conn.h
index 7c4ef5d..771b744 100644
--- a/tcp_conn.h
+++ b/tcp_conn.h
@@ -335,6 +335,19 @@ typedef struct tcp_event_info {
        struct tcp_connection *con;
 } tcp_event_info_t;
 
+enum tcp_closed_reason {
+       TCP_CLOSED_EOF = 0,
+       TCP_CLOSED_TIMEOUT,
+       TCP_CLOSED_RESET,
+
+       _TCP_CLOSED_REASON_MAX /* /!\ keep this one always at the end */
+};
+
+typedef struct tcp_closed_event_info {
+       enum tcp_closed_reason reason;
+       struct tcp_connection *con;
+} tcp_closed_event_info_t;
+
 typedef struct ws_event_info {
        int type;
        char *buf;
diff --git a/tcp_read.c b/tcp_read.c
index 85dd4b1..e8b262b 100644
--- a/tcp_read.c
+++ b/tcp_read.c
@@ -186,17 +186,16 @@ int tcp_http11_continue(struct tcp_connection *c)
 }
 #endif /* HTTP11 */
 
-static int tcp_make_closed_event(struct receive_info* rcv_info, struct 
tcp_connection* con)
+static int tcp_emit_closed_event(struct tcp_connection *con, enum 
tcp_closed_reason reason)
 {
        int ret;
-       tcp_event_info_t tev;
+       tcp_closed_event_info_t tev;
 
        ret = 0;
        LM_DBG("TCP closed event creation triggered\n");
        if(likely(sr_event_enabled(SREV_TCP_CLOSED))) {
-               memset(&tev, 0, sizeof(tcp_event_info_t));
-               tev.type = SREV_TCP_CLOSED;
-               tev.rcv = rcv_info;
+               memset(&tev, 0, sizeof(tcp_closed_event_info_t));
+               tev.reason = reason;
                tev.con = con;
                ret = sr_event_exec(SREV_TCP_CLOSED, (void*)(&tev));
        } else {
@@ -291,19 +290,18 @@ int tcp_read_data(int fd, struct tcp_connection *c,
                                                strerror(errno), errno,
                                                ip_addr2a(&c->rcv.src_ip), 
c->rcv.src_port);
                                LOG(cfg_get(core, core_cfg, corelog),"-> 
[%s]:%u)\n", ip_addr2a(&c->rcv.dst_ip), c->rcv.dst_port);
-                               if((errno == ECONNRESET || errno == ETIMEDOUT) 
&& likely(c->rcv.proto_reserved1 != 0)){
-                                       tcp_make_closed_event(&c->rcv, c);
+                               if (errno == ETIMEDOUT) {
+                                       tcp_emit_closed_event(c, 
TCP_CLOSED_TIMEOUT);
+                               } else if (errno == ECONNRESET) {
+                                       tcp_emit_closed_event(c, 
TCP_CLOSED_RESET);
                                }
-
                                return -1;
                        }
                }else if (unlikely((bytes_read==0) || 
                                        (*flags & RD_CONN_FORCE_EOF))){
                        c->state=S_CONN_EOF;
                        *flags|=RD_CONN_EOF;
-                       if (likely(c->rcv.proto_reserved1 != 0)){
-                               tcp_make_closed_event(&c->rcv, c);
-                       }
+                       tcp_emit_closed_event(c, TCP_CLOSED_EOF);
                        LM_DBG("EOF on %p, FD %d ([%s]:%u ->", c, fd, 
ip_addr2a(&c->rcv.src_ip), c->rcv.src_port);
                        LM_DBG("-> [%s]:%u)\n", ip_addr2a(&c->rcv.dst_ip), 
c->rcv.dst_port);
                }else{


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to