| 208 | } |
| 209 | |
| 210 | static 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; |
| 240 | close: |
| 241 | shutdown(fd, SHUT_RDWR); |
| 242 | close(fd); |
| 243 | return -1; |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Runs a JSON-RPC command (request or notification) |
no test coverage detected