+static void
+_event_cb (struct bufferevent *bev, short events, void *ctx)
+{
+ struct rs_packet *pkt = (struct rs_packet *) ctx;
+
+ assert (pkt);
+ assert (pkt->conn);
+ if (events & BEV_EVENT_CONNECTED)
+ {
+#if defined (DEBUG)
+ fprintf (stderr, "%s: connected\n", __func__);
+#endif
+ rad_encode (pkt->rpkt, NULL, pkt->conn->active_peer->secret);
+#if defined (DEBUG)
+ fprintf (stderr, "%s: about to send this to %s:\n", __func__, "<fixme>");
+ rs_dump_packet (pkt);
+#endif
+ if (bufferevent_write(bev, pkt->rpkt->data, pkt->rpkt->data_len))
+ rs_conn_err_push_fl (pkt->conn, RSE_EVENT, __FILE__, __LINE__,
+ "bufferevent_write");
+ /* Packet will be freed in write callback. */
+ }
+ else if (events & BEV_EVENT_ERROR)
+ rs_conn_err_push_fl (pkt->conn, RSE_CONNERR, __FILE__, __LINE__, NULL);
+}
+
+void
+rs_packet_destroy(struct rs_packet *pkt)
+{
+ rad_free (&pkt->rpkt);
+ rs_free (pkt->conn->ctx, pkt);
+}
+
+static void
+_write_cb (struct bufferevent *bev, void *ctx)
+{
+ struct rs_packet *pkt = (struct rs_packet *) ctx;
+
+ assert (pkt);
+ assert (pkt->conn);
+#if defined (DEBUG)
+ fprintf (stderr, "%s: packet written, breaking event loop\n", __func__);
+#endif
+ if (event_base_loopbreak (pkt->conn->evb) < 0)
+ abort (); /* FIXME */
+ rs_packet_destroy (pkt);
+}
+