Module: kamailio
Branch: master
Commit: b57c83c936bf729bda3174803cacbf006552f2dc
URL:
https://github.com/kamailio/kamailio/commit/b57c83c936bf729bda3174803cacbf0…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2017-10-23T14:35:43+02:00
jsonrpcs: use select on udp socket to work on non-blocking mode
---
Modified: src/modules/jsonrpcs/jsonrpcs_sock.c
---
Diff:
https://github.com/kamailio/kamailio/commit/b57c83c936bf729bda3174803cacbf0…
Patch:
https://github.com/kamailio/kamailio/commit/b57c83c936bf729bda3174803cacbf0…
---
diff --git a/src/modules/jsonrpcs/jsonrpcs_sock.c b/src/modules/jsonrpcs/jsonrpcs_sock.c
index 4dc4740e90..3529941f1d 100644
--- a/src/modules/jsonrpcs/jsonrpcs_sock.c
+++ b/src/modules/jsonrpcs/jsonrpcs_sock.c
@@ -30,6 +30,7 @@
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/un.h>
+#include <sys/select.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@@ -560,16 +561,29 @@ void jsonrpc_dgram_server(int rx_sock)
int ret;
str scmd;
jsonrpc_plain_reply_t* jr = NULL;
+ fd_set readfds;
+ int n;
ret = 0;
while(1) { /*read the datagram*/
/* update the local config framework structures */
cfg_update();
-
memset(jsonrpc_dgram_buf, 0, JSONRPC_DGRAM_BUF_SIZE);
jsonrpc_dgram_reply_addr_len = sizeof(jsonrpc_dgram_reply_addr);
+ FD_ZERO(&readfds);
+ FD_SET(rx_sock, &readfds);
+ n = select(rx_sock+1, &readfds, 0, 0, 0);
+ if(n < 0) {
+ LM_ERR("failure in select: (%d) %s\n", errno, strerror(errno));
+ continue;
+ }
+ if(!FD_ISSET(rx_sock, &readfds)) {
+ /* no data on udp socket */
+ continue;
+ }
+
/* get the client's address */
ret = recvfrom(rx_sock, jsonrpc_dgram_buf, JSONRPC_DGRAM_BUF_SIZE, 0,
(struct sockaddr*)&jsonrpc_dgram_reply_addr,