[sr-dev] git:5.0:c7dc3f9d: evapi: do close() on client socket if libev detects it is gone

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[sr-dev] git:5.0:c7dc3f9d: evapi: do close() on client socket if libev detects it is gone

Victor Seva
Module: kamailio
Branch: 5.0
Commit: c7dc3f9dbd691323bb65c549c6578adfb03392c6
URL: https://github.com/kamailio/kamailio/commit/c7dc3f9dbd691323bb65c549c6578adfb03392c6

Author: Daniel-Constantin Mierla <[hidden email]>
Committer: Victor Seva <[hidden email]>
Date: 2017-11-29T13:53:10+01:00

evapi: do close() on client socket if libev detects it is gone

- handle socket values for valid range >=0

(cherry picked from commit bb91d6c4fa88324c31d3b7a91687057e0ae8bfa0)

---

Modified: src/modules/evapi/evapi_dispatch.c

---

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

---

diff --git a/src/modules/evapi/evapi_dispatch.c b/src/modules/evapi/evapi_dispatch.c
index 47fc6a0052..3aa5288c7f 100644
--- a/src/modules/evapi/evapi_dispatch.c
+++ b/src/modules/evapi/evapi_dispatch.c
@@ -154,10 +154,10 @@ int evapi_close_connection(int cidx)
  if(cidx<0 || cidx>=EVAPI_MAX_CLIENTS)
  return -1;
  if(_evapi_clients[cidx].connected==1
- && _evapi_clients[cidx].sock > 0) {
+ && _evapi_clients[cidx].sock >= 0) {
  close(_evapi_clients[cidx].sock);
  _evapi_clients[cidx].connected = 0;
- _evapi_clients[cidx].sock = 0;
+ _evapi_clients[cidx].sock = -1;
  return 0;
  }
  return -2;
@@ -196,7 +196,7 @@ int evapi_set_tag(sip_msg_t* msg, str* stag)
  return -1;
 
  if(!(_evapi_clients[evenv->conidx].connected==1
- && _evapi_clients[evenv->conidx].sock > 0)) {
+ && _evapi_clients[evenv->conidx].sock >= 0)) {
  LM_ERR("connection not established\n");
  return -1;
  }
@@ -221,7 +221,8 @@ int evapi_init_notify_sockets(void)
  LM_ERR("opening notify stream socket pair\n");
  return -1;
  }
- LM_DBG("inter-process event notification sockets initialized\n");
+ LM_DBG("inter-process event notification sockets initialized: %d ~ %d\n",
+ _evapi_notify_sockets[0], _evapi_notify_sockets[1]);
  return 0;
 }
 
@@ -256,7 +257,7 @@ int evapi_dispatch_notify(evapi_msg_t *emsg)
 
  n = 0;
  for(i=0; i<EVAPI_MAX_CLIENTS; i++) {
- if(_evapi_clients[i].connected==1 && _evapi_clients[i].sock>0) {
+ if(_evapi_clients[i].connected==1 && _evapi_clients[i].sock>=0) {
  if(emsg->tag.s==NULL || (emsg->tag.len = _evapi_clients[i].stag.len
  && strncmp(_evapi_clients[i].stag.s,
  emsg->tag.s, emsg->tag.len)==0)) {
@@ -329,7 +330,10 @@ void evapi_recv_client(struct ev_loop *loop, struct ev_io *watcher, int revents)
  evenv.conidx = i;
  evapi_run_cfg_route(&evenv, _evapi_rts.con_closed);
  _evapi_clients[i].connected = 0;
- _evapi_clients[i].sock = 0;
+ if(_evapi_clients[i].sock>=0) {
+ close(_evapi_clients[i].sock);
+ }
+ _evapi_clients[i].sock = -1;
  _evapi_clients[i].rpos = 0;
  ev_io_stop(loop, watcher);
  free(watcher);
@@ -565,11 +569,14 @@ int evapi_run_dispatcher(char *laddr, int lport)
  struct ev_io io_notify;
  int yes_true = 1;
  int fflags = 0;
+ int i;
 
  LM_DBG("starting dispatcher processing\n");
 
  memset(_evapi_clients, 0, sizeof(evapi_client_t) * EVAPI_MAX_CLIENTS);
-
+ for(i=0; i<EVAPI_MAX_CLIENTS; i++) {
+ _evapi_clients[i].sock = -1;
+ }
  loop = ev_default_loop(0);
 
  if(loop==NULL) {
@@ -843,7 +850,7 @@ int pv_get_evapi(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
  return pv_get_null(msg, param, res);
 
  if(_evapi_clients[evenv->conidx].connected==0
- && _evapi_clients[evenv->conidx].sock <= 0)
+ && _evapi_clients[evenv->conidx].sock < 0)
  return pv_get_null(msg, param, res);
 
  switch(param->pvn.u.isname.name.n)


_______________________________________________
Kamailio (SER) - Development Mailing List
[hidden email]
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev