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

Function handle_write_jsonrpc

modules/event_stream/stream_send.c:589–657  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

587}
588
589static void handle_write_jsonrpc(struct stream_con *con)
590{
591 struct list_head *it, *tmp;
592 struct jsonrpc_cmd *cmd;
593 int bytes_written;
594 int bytes_written_total = 0;
595
596 /* the buffer is free to write - write as much as possible */
597 list_for_each_safe(it, tmp, &con->cmds) {
598 cmd = list_entry(it, struct jsonrpc_cmd, list);
599
600 if (cmd->state != JSONRPC_REQ_NEW)
601 continue;
602
603 /* try to write */
604 do {
605 bytes_written = send(con->fd,
606 cmd->job->message.s, cmd->job->message.len, 0);
607 } while (bytes_written < -1 && errno == EINTR);
608 if (bytes_written < 0) {
609 if (errno != EAGAIN && errno != EWOULDBLOCK) {
610 LM_ERR("error while writing on connection to %s:%hu\n",
611 STREAM_ADDR(con));
612 goto error_free;
613 } else
614 break; /* check to see if there was anything written */
615 } else if (bytes_written == 0) {
616 LM_ERR("remote connection closed while trying to write to %s:%hu!\n",
617 STREAM_ADDR(con));
618 }
619 /* there was a success */
620 bytes_written_total += bytes_written;
621 cmd->job->message.s += bytes_written;
622 cmd->job->message.len -= bytes_written;
623
624 /* if there's more to write from this command, return now */
625 if (cmd->job->message.len)
626 return;
627
628 /* otherwise, reply to this command and try a different command */
629 cmd->state = JSONRPC_REQ_SENT;
630 con->pending_writes--;
631
632 /* if reliable mode was not used, we don't really care about the reply,
633 * so we simply discard the job right here */
634 if (!stream_reliable_mode) {
635 list_del(&cmd->list);
636 jsonrpc_cmd_free(cmd);
637 }
638 }
639
640 if (bytes_written_total == 0) {
641 LM_ERR("con fd %d in reactor but nothing was written to %s:%hu!\n",
642 con->fd, STREAM_ADDR(con));
643 goto error_free;
644 }
645
646 /* if there were no writes pending, remove from reactor and don't do

Callers 1

handle_ioFunction · 0.85

Calls 5

list_for_each_safeFunction · 0.85
list_delFunction · 0.85
jsonrpc_cmd_freeFunction · 0.85
stream_con_freeFunction · 0.85
list_entryClass · 0.50

Tested by

no test coverage detected