예제 #1
0
static struct io_plan *write_json(struct io_conn *conn,
				  struct json_connection *jcon)
{
	struct json_output *out;
	
	out = list_pop(&jcon->output, struct json_output, list);
	if (!out) {
		if (jcon->stop) {
			log_unusual(jcon->log, "JSON-RPC shutdown");
			/* Return us to toplevel lightningd.c */
			io_break(jcon->dstate);
			return io_close(conn);
		}

		/* Reader can go again now. */
		io_wake(jcon);
		return io_out_wait(conn, jcon, write_json, jcon);
	}

	jcon->outbuf = tal_steal(jcon, out->json);
	tal_free(out);

	log_io(jcon->log, false, jcon->outbuf, strlen(jcon->outbuf));
	return io_write(conn,
			jcon->outbuf, strlen(jcon->outbuf), write_json, jcon);
}
예제 #2
0
static void queue_raw_pkt(struct peer *peer, Pkt *pkt)
{
	size_t n = tal_count(peer->outpkt);
	tal_resize(&peer->outpkt, n+1);
	peer->outpkt[n] = pkt;

	log_debug(peer->log, "Queued pkt %s", pkt_name(pkt->pkt_case));

	/* In case it was waiting for output. */
	io_wake(peer);
}
예제 #3
0
파일: packets.c 프로젝트: dooglus/lightning
static void queue_raw_pkt(struct peer *peer, Pkt *pkt,
			  void (*ack_cb)(struct peer *peer, void *arg),
			  void *ack_arg)
{
	size_t n = tal_count(peer->outpkt);
	tal_resize(&peer->outpkt, n+1);
	peer->outpkt[n].pkt = pkt;
	peer->outpkt[n].ack_cb = ack_cb;
	peer->outpkt[n].ack_arg = ack_arg;

	/* In case it was waiting for output. */
	io_wake(peer);
}
예제 #4
0
static void json_result(struct json_connection *jcon,
			const char *id, const char *res, const char *err)
{
	struct json_output *out = tal(jcon, struct json_output);

	out->json = tal_fmt(out,
			    "{ \"result\" : %s,"
			    " \"error\" : %s,"
			    " \"id\" : %s }\n",
			    res, err, id);

	/* Queue for writing, and wake writer (and maybe reader). */
	list_add_tail(&jcon->output, &out->list);
	io_wake(jcon);
}
예제 #5
0
static void finish_waker(struct io_conn *conn, struct data *d)
{
	io_wake(d);
	ok1(d->state == 1);
	d->state++;
}
예제 #6
0
static struct io_plan wake_it(struct io_conn *conn, struct io_conn *reader)
{
	io_wake(reader, io_read(inbuf, 8, io_close_cb, NULL));
	return io_close();
}