]> mj.ucw.cz Git - subauth.git/blobdiff - server/subauthd.c
Server: Fixed handling of exceptions during packet constructions
[subauth.git] / server / subauthd.c
index df6d5e8ebf64005e6dc1b33c1d1874c17e9289cf..bdfe295930a57373f8df8d9452166bbd51c61476 100644 (file)
@@ -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)
     {