poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[COMMITTED] poked: Enable `chan_send` to send multiple buffers


From: Mohammad-Reza Nabipoor
Subject: [COMMITTED] poked: Enable `chan_send` to send multiple buffers
Date: Mon, 14 Mar 2022 22:35:07 +0330

2022-03-14  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>

        * poked/poked.pk (__chan_send_chan): Changed to array.
        (__chan_send_buf): Likewise.
        (__chan_send_reset): Update.
        (chan_send): Push data and channel to buffer array.
        (__err_send): Remove comment.
        * poked/poked.c (poked_buf_send_one): New function to send a single
        buffer to a channel.
        (poked_buf_send): Changed to support array of buffers.
---
 ChangeLog      | 11 +++++++++++
 poked/poked.c  | 26 +++++++++++++++++++++-----
 poked/poked.pk | 15 +++++++--------
 3 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 934660c1..4d4cb3b1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2022-03-14  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
+
+       * poked/poked.pk (__chan_send_chan): Changed to array.
+       (__chan_send_buf): Likewise.
+       (__chan_send_reset): Update.
+       (chan_send): Push data and channel to buffer array.
+       (__err_send): Remove comment.
+       * poked/poked.c (poked_buf_send_one): New function to send a single
+       buffer to a channel.
+       (poked_buf_send): Changed to support array of buffers.
+
 2022-03-14  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
 
        * poked/poked.c (poked_init): Define `poked_libpoke_version`
diff --git a/poked/poked.c b/poked/poked.c
index 2cff5048..80a34757 100644
--- a/poked/poked.c
+++ b/poked/poked.c
@@ -88,13 +88,14 @@ srvthread (void *data)
 }
 
 static void
-poked_buf_send (void)
+poked_buf_send_one (pk_val arr, pk_val pchan)
 {
-  pk_val arr = pk_decl_val (pkc, "__chan_send_buf");
+  assert (arr != PK_NULL);
+  assert (pchan != PK_NULL);
+
   uint16_t nelem = (uint16_t)pk_uint_value (pk_array_nelem (arr));
-  uint8_t chan = pk_uint_value (pk_decl_val (pkc, "__chan_send_chan")) & 0x7f;
+  uint8_t chan = pk_uint_value (pchan) & 0x7f;
   uint8_t *mem;
-  pk_val exc;
 
   mem = malloc (nelem);
   if (mem == NULL)
@@ -103,11 +104,26 @@ poked_buf_send (void)
     mem[i] = pk_uint_value (pk_array_elem_value (arr, i));
   usock_out (srv, chan, /*no kind*/ 0, mem, nelem);
   free (mem);
+}
+
+static void
+poked_buf_send (void)
+{
+  pk_val buffers = pk_decl_val (pkc, "__chan_send_buf");
+  pk_val chans = pk_decl_val (pkc, "__chan_send_chan");
+  uint64_t buffers_nelem = pk_uint_value (pk_array_nelem (buffers));
+  uint64_t chans_nelem = pk_uint_value (pk_array_nelem (chans));
+  pk_val exc;
 
+  assert (buffers_nelem == chans_nelem);
+  for (uint64_t i = 0; i < buffers_nelem; ++i)
+    poked_buf_send_one (pk_array_elem_value (buffers, i),
+                        pk_array_elem_value (chans, i));
   (void)pk_call (pkc, pk_decl_val (pkc, "__chan_send_reset"), NULL, &exc, 0);
-  assert (exc == PK_NULL);
 }
 
+#define poked_buf_send_one private_
+
 static void
 iteration_send (struct usock *srv, uint64_t n_iteration, int begin_p)
 {
diff --git a/poked/poked.pk b/poked/poked.pk
index 6afc537b..eb417719 100644
--- a/poked/poked.pk
+++ b/poked/poked.pk
@@ -31,29 +31,28 @@ fun poked_defer = void: {}
 //--- send over channels
 
 var __chan_send_p = 0;
-var __chan_send_chan = 0x7f as uint<7>;
-var __chan_send_buf = byte[] ();
+var __chan_send_chan = uint<7>[] ();
+var __chan_send_buf = byte[][] ();
 
 fun __chan_send_reset = void:
   {
     __chan_send_p = 0;
-    __chan_send_chan = 0x7f as uint<7>;
-    __chan_send_buf = byte[] ();
+    __chan_send_chan = uint<7>[] ();
+    __chan_send_buf = byte[][] ();
   }
 
 fun chan_send = (uint<7> chan, byte[] data) void:
   {
     assert (0 < data'length && data'length <= 0xffff);
+    assert (0 < chan && chan <= 120);
 
-    __chan_send_chan = chan;
-    __chan_send_buf = data;
+    apush (__chan_send_chan, chan);
+    apush (__chan_send_buf, data);
     __chan_send_p = 1;
   }
 
 //--- default exception handler
 
-/* NOTE Due to current implementation limitation, you can call this
-   function only once in each iteration.  */
 fun __err_send = (string s) void:
   {
     var c = byte[s'length] ();
-- 
2.35.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]