uint32_t accept_stat;
};
+/* Routines for XDR-encoding to a growable string. */
+static bool_t xdr_string_putlong(XDR *xdrs, const long *lp)
+{
+ GString *str = (GString *)xdrs->x_private;
+ uint32_t data = htonl(*lp);
+ g_string_set_size(str, str->len + 4);
+ memcpy(str->str + str->len - 4, &data, 4);
+ return TRUE;
+}
+
+static bool_t xdr_string_putbytes(XDR *xdrs, const char *addr, u_int len)
+{
+ GString *str = (GString *)xdrs->x_private;
+ g_string_set_size(str, str->len + len);
+ memcpy(str->str + str->len - len, addr, len);
+ return TRUE;
+}
+
+static u_int xdr_string_getpos(const XDR *xdrs)
+{
+ GString *str = (GString *)xdrs->x_private;
+ return str->len;
+}
+
+static bool_t xdr_string_putint32(XDR *xdrs, const int32_t *ip)
+{
+ GString *str = (GString *)xdrs->x_private;
+ uint32_t data = htonl(*ip);
+ g_string_set_size(str, str->len + 4);
+ memcpy(str->str + str->len - 4, &data, 4);
+ return TRUE;
+}
+
+static int32_t *xdr_string_inline(XDR *xdrs, u_int len)
+{
+ GString *str = (GString *)xdrs->x_private;
+ g_string_set_size(str, str->len + len);
+ return (int32_t *)(str->str + str->len - len);
+}
+
+static void xdr_string_destroy(XDR *xdrs)
+{
+}
+
+static struct xdr_ops xdr_string_ops = {
+ .x_putlong = xdr_string_putlong,
+ .x_putbytes = xdr_string_putbytes,
+ .x_getpostn = xdr_string_getpos,
+ .x_putint32 = xdr_string_putint32,
+ .x_inline = xdr_string_inline,
+ .x_destroy = xdr_string_destroy,
+};
+
+static void xdr_string_create(XDR *xdrs, GString *string, enum xdr_op op)
+{
+ xdrs->x_op = op;
+ xdrs->x_ops = &xdr_string_ops;
+ xdrs->x_private = (char *)string;
+ xdrs->x_base = NULL;
+ xdrs->x_handy = 0;
+}
+
static void
async_rpc_send_failure(RPCRequest *req, enum accept_stat stat)
{
void
async_rpc_send_reply(RPCRequest *req, void *result)
{
- static char reply_buf[MAX_RPC_MSGSIZE];
+ GString *str = g_string_new("");
XDR xdr_out;
- xdrmem_create(&xdr_out, reply_buf, MAX_RPC_MSGSIZE, XDR_ENCODE);
+ xdr_string_create(&xdr_out, str, XDR_ENCODE);
if (!req->xdr_result(&xdr_out, result)) {
async_rpc_send_failure(req, SYSTEM_ERR);
+ g_string_free(str, TRUE);
return;
}
header.verf_len = 0;
header.accept_stat = 0;
- gsize msg_size = xdr_out.x_ops->x_getpostn(&xdr_out);
+ gsize msg_size = str->len;
printf("Have an RPC reply of size %zd bytes\n", msg_size);
uint32_t fragment = htonl((msg_size + sizeof(header)) | 0x80000000);
async_rpc_write(req->connection, (const char *)&fragment, sizeof(fragment));
async_rpc_write(req->connection, (const char *)&header, sizeof(header));
- async_rpc_write(req->connection, reply_buf, msg_size);
+ async_rpc_write(req->connection, str->str, str->len);
g_io_channel_flush(req->connection->channel, NULL);
/* Clean up. */
+ g_string_free(str, TRUE);
+
if (req->args != NULL) {
char buf[4];
XDR xdr;