X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=server%2Fsubauthd.c;h=bdfe295930a57373f8df8d9452166bbd51c61476;hb=2e5a931dd18959b88675bccd844b0226ec1f1099;hp=df6d5e8ebf64005e6dc1b33c1d1874c17e9289cf;hpb=0f6143135fb26b8fd26ce555eaccb19fa647cb1d;p=subauth.git diff --git a/server/subauthd.c b/server/subauthd.c index df6d5e8..bdfe295 100644 --- a/server/subauthd.c +++ b/server/subauthd.c @@ -58,22 +58,26 @@ static void socket_timeout_handler(struct main_timer *tm) 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) {