| 170 | } |
| 171 | |
| 172 | int stream_init_writer(void) |
| 173 | { |
| 174 | int flags; |
| 175 | |
| 176 | if (stream_pipe[0] != -1) { |
| 177 | close(stream_pipe[0]); |
| 178 | stream_pipe[0] = -1; |
| 179 | } |
| 180 | |
| 181 | if (stream_reliable_mode) { |
| 182 | /* initilize indexes */ |
| 183 | jrpc_id_index = my_pid() & USHRT_MAX; |
| 184 | jrpc_id_index |= rand() << sizeof(unsigned short); |
| 185 | } |
| 186 | |
| 187 | /* Turn non-blocking mode on for sending*/ |
| 188 | flags = fcntl(stream_pipe[1], F_GETFL); |
| 189 | if (flags == -1) { |
| 190 | LM_ERR("fcntl failed: %s\n", strerror(errno)); |
| 191 | goto error; |
| 192 | } |
| 193 | if (fcntl(stream_pipe[1], F_SETFL, flags | O_NONBLOCK) == -1) { |
| 194 | LM_ERR("fcntl: set non-blocking failed: %s\n", strerror(errno)); |
| 195 | goto error; |
| 196 | } |
| 197 | |
| 198 | return 0; |
| 199 | error: |
| 200 | close(stream_pipe[1]); |
| 201 | stream_pipe[1] = -1; |
| 202 | return -1; |
| 203 | } |
| 204 | |
| 205 | static void jsonrpc_init_reader(void) |
| 206 | { |