static void try_send_reply(struct client *c)
{
- struct fastbuf fb;
- fbbuf_init_write(&fb, packet_buffer, MAX_PACKET_SIZE);
+ int len;
TRANS_TRY
{
+ struct fastbuf fb;
+ fbbuf_init_write(&fb, packet_buffer, MAX_PACKET_SIZE);
+ fb_tie(&fb);
json_write(c->json, &fb, c->reply);
+ len = fbbuf_count_written(&fb);
}
TRANS_CATCH(x)
{
msg(L_ERROR, "Unable to construct reply, it is probably too long");
- fbbuf_init_write(&fb, packet_buffer, MAX_PACKET_SIZE);
- bputs(&fb, "{ \"error\": \"Reply too long\" }\n");
+ struct fastbuf fb2;
+ fbbuf_init_write(&fb2, packet_buffer, MAX_PACKET_SIZE);
+ bputs(&fb2, "{ \"error\": \"Reply too long\" }\n");
+ len = fbbuf_count_written(&fb2);
}
TRANS_END;
- int len = fbbuf_count_written(&fb);
DBG("Sending reply of %d bytes", len);
if (send(c->socket.fd, packet_buffer, len, 0) < 0)
{