diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-09-27 17:33:10 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-27 17:33:10 -0400 |
commit | d38ccfc6dcb8643daa4f9e695d47a79cf068f90e (patch) | |
tree | d36ad2934e8550242d50e866f4ad2b6c303646b7 /libdeno/deno.h | |
parent | bf93ca54dd85686c7b93a6189913e48e10de8dcf (diff) |
Support zero-copy data in libdeno.send(). (#838)
This is a large API refactor of deno.h which replaces
deno_send() and deno_set_response() with deno_respond().
It also adds a req_id parameter to the deno_recv_cb.
Make writeFile/writeFileSync use it.
Diffstat (limited to 'libdeno/deno.h')
-rw-r--r-- | libdeno/deno.h | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/libdeno/deno.h b/libdeno/deno.h index 90edca3d9..b0248b7ad 100644 --- a/libdeno/deno.h +++ b/libdeno/deno.h @@ -20,9 +20,11 @@ typedef struct { struct deno_s; typedef struct deno_s Deno; -// A callback to receive a message from deno.send javascript call. -// buf is valid only for the lifetime of the call. -typedef void (*deno_recv_cb)(Deno* d, deno_buf buf); +// A callback to receive a message from a libdeno.send() javascript call. +// control_buf is valid for only for the lifetime of this callback. +// data_buf is valid until deno_respond() is called. +typedef void (*deno_recv_cb)(Deno* d, int32_t req_id, deno_buf control_buf, + deno_buf data_buf); void deno_init(); const char* deno_v8_version(); @@ -39,21 +41,25 @@ void* deno_get_data(Deno*); // 0 = fail, 1 = success int deno_execute(Deno* d, const char* js_filename, const char* js_source); -// Routes message to the javascript callback set with deno.recv(). A false -// return value indicates error. Check deno_last_exception() for exception text. -// 0 = fail, 1 = success -// After calling deno_send(), the caller no longer owns `buf` and must not use -// it; deno_send() is responsible for releasing it's memory. -// TODO(piscisaureus) In C++ and/or Rust, use a smart pointer or similar to -// enforce this rule. -int deno_send(Deno* d, deno_buf buf); - -// Call this inside a deno_recv_cb to respond synchronously to messages. -// If this is not called during the life time of a deno_recv_cb callback -// the deno.send() call in javascript will return null. -// After calling deno_set_response(), the caller no longer owns `buf` and must -// not access it; deno_set_response() is responsible for releasing it's memory. -void deno_set_response(Deno* d, deno_buf buf); +// deno_respond sends up to one message back for every deno_recv_cb made. +// +// If this is called during deno_recv_cb, the issuing libdeno.send() in +// javascript will synchronously return the specified buf as an ArrayBuffer (or +// null if buf is empty). +// +// If this is called after deno_recv_cb has returned, the deno_respond +// will call into the JS callback specified by libdeno.recv(). +// +// (Ideally, but not currently: After calling deno_respond(), the caller no +// longer owns `buf` and must not use it; deno_respond() is responsible for +// releasing its memory.) +// +// Calling this function more than once with the same req_id will result in +// an error. +// +// A non-zero return value, means a JS exception was encountered during the +// libdeno.recv() callback. Check deno_last_exception() for exception text. +int deno_respond(Deno* d, int32_t req_id, deno_buf buf); const char* deno_last_exception(Deno* d); |