[sr-dev] git:master:1980c79d: core: trigger event_route execution for unexpectedly-closed and client-closed tcp connections
Daniel-Constantin Mierla
miconda at gmail.com
Mon Jan 4 23:12:02 CET 2016
Module: kamailio
Branch: master
Commit: 1980c79d4fb2111c8c245045035f4ecb5d17fd7f
URL: https://github.com/kamailio/kamailio/commit/1980c79d4fb2111c8c245045035f4ecb5d17fd7f
Author: Armen Babikyan <armen at firespotter.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2016-01-04T23:05:30+01:00
core: trigger event_route execution for unexpectedly-closed and client-closed tcp connections
---
Modified: tcp_read.c
---
Diff: https://github.com/kamailio/kamailio/commit/1980c79d4fb2111c8c245045035f4ecb5d17fd7f.diff
Patch: https://github.com/kamailio/kamailio/commit/1980c79d4fb2111c8c245045035f4ecb5d17fd7f.patch
---
diff --git a/tcp_read.c b/tcp_read.c
index bf07574..84ddf90 100644
--- a/tcp_read.c
+++ b/tcp_read.c
@@ -186,6 +186,25 @@ 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)
+{
+ int ret;
+ tcp_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;
+ tev.con = con;
+ ret = sr_event_exec(SREV_TCP_CLOSED, (void*)(&tev));
+ } else {
+ LM_DBG("no callback registering for handling TCP closed event - dropping!\n");
+ }
+ return ret;
+}
+
/** reads data from an existing tcp connection.
* Side-effects: blacklisting, sets connection state to S_CONN_OK, tcp stats.
@@ -272,12 +291,20 @@ int tcp_read_data(int fd, struct tcp_connection *c,
strerror(errno), errno,
ip_addr2a(&c->rcv.src_ip), c->rcv.src_port,
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);
+ }
+
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);
+ }
LM_DBG("EOF on %p, FD %d ([%s]:%u -> [%s]:%u)\n", c, fd,
ip_addr2a(&c->rcv.src_ip), c->rcv.src_port,
ip_addr2a(&c->rcv.dst_ip), c->rcv.dst_port);
More information about the sr-dev
mailing list