• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/ucode/lib/debug_proto.h

  1 #ifndef _UCODE_DEBUG_PROTO_H
  2 #define _UCODE_DEBUG_PROTO_H
  3 
  4 #include <stddef.h>
  5 
  6 #include <ucode/types.h>
  7 #include <ucode/vm.h>
  8 
  9 /*
 10  * Line-based debug protocol framing.
 11  *
 12  * One message per line: an uppercase VERB, optionally followed by a single
 13  * space and a JSON-encoded object payload, terminated by '\n'. Used for both
 14  * directions of traffic (client commands and server responses/events), and
 15  * by every transport (local socketpair, remote Unix domain socket).
 16  */
 17 
 18 /* Incremental read buffer, one per connection. Zero-initialize (or use
 19  * debug_proto_buf_init()) before first use; release with
 20  * debug_proto_buf_free() once the connection is done. */
 21 typedef struct {
 22         char *data;
 23         size_t len;
 24         size_t cap;
 25 } debug_proto_buf_t;
 26 
 27 void debug_proto_buf_init(debug_proto_buf_t *buf);
 28 void debug_proto_buf_free(debug_proto_buf_t *buf);
 29 
 30 /* Write a single "VERB json\n" (or "VERB\n" if payload is NULL) message to
 31  * fd. Best-effort: I/O errors are silently swallowed, matching the previous
 32  * debug_write_response() semantics - a dead/blocked peer must never be fatal
 33  * to the caller. payload is not consumed/freed. */
 34 void debug_proto_write(int fd, uc_vm_t *vm, const char *verb, uc_value_t *payload);
 35 
 36 /* Read a single message from fd, using buf to hold data already read from
 37  * fd but not yet consumed as a full line (refilled from fd as needed).
 38  * Blocks until a full line is available, EOF, or an I/O error occurs.
 39  *
 40  * On success (return 1), *verb_out is set to a newly heap-allocated,
 41  * NUL-terminated verb string (caller must free()) and *payload_out to the
 42  * parsed JSON payload, or NULL if the line carried no payload.
 43  *
 44  * Returns 0 on clean EOF, -1 on I/O error, -2 if the line's payload could
 45  * not be parsed as JSON (verb/payload are left untouched in both error
 46  * cases).
 47  */
 48 int debug_proto_read(int fd, debug_proto_buf_t *buf, uc_vm_t *vm,
 49                       char **verb_out, uc_value_t **payload_out);
 50 
 51 #endif
 52 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt