MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / jsonrpc_get_fd

Function jsonrpc_get_fd

modules/jsonrpc/jsonrpc.c:210–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

208}
209
210static int jsonrpc_get_fd(union sockaddr_union *addr)
211{
212 int fd;
213 int flags;
214
215 /* writing the iov on the network */
216 if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
217 LM_ERR("cannot create socket\n");
218 return -1;
219 }
220
221 /* mark the socket as non-blocking after connect :) */
222 flags = fcntl(fd, F_GETFL);
223 if (flags == -1) {
224 LM_ERR("fcntl failed: %s\n", strerror(errno));
225 goto close;
226 }
227 if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
228 LM_ERR("fcntl: set non-blocking failed: %s\n", strerror(errno));
229 goto close;
230 }
231
232 if (tcp_connect_blocking_timeout(fd, &addr->s,
233 sockaddru_len(*addr), jrpc_connect_timeout) < 0) {
234 LM_ERR("cannot connect to %s[%d:%s]\n",
235 inet_ntoa(addr->sin.sin_addr),
236 errno, strerror(errno));
237 goto close;
238 }
239 return fd;
240close:
241 shutdown(fd, SHUT_RDWR);
242 close(fd);
243 return -1;
244}
245
246/**
247 * Runs a JSON-RPC command (request or notification)

Callers 1

jsonrpc_handle_cmdFunction · 0.85

Calls 1

Tested by

no test coverage detected