On Wed, Nov 15, 2023 at 08:05:25PM +0800, Qian Yun wrote:
> |sockGetStringFrom| uses a fixed buffer length of 10000,
> which is wasteful if the string is small, and is wrong if
> the string length exceeds it.

Yes, this is a known problem.  Concerning efficiency,
I do not think it is a significant problem for sizes below
10000.  But we it would be good to have version correct for
longer strings.

> 
> I think we can improve with things like:
> 
> char *
> sock_get_string_aux(int purpose, char * buf, int buf_len)
> {
>   if (accept_if_needed(purpose) != -1) {
>     val = fill_buf(purpose_table[purpose], buf, buf_len);
>     if (val == -1)
>       return NULL;
>     return buf;
>   }
>   return NULL;
> }
> 
> ====
> 
> (defun |sockGetStringFrom| (purpose)
>     (sockGetStringAux purpose (|sockGetInt| purpose)))
> 
> #+(and :clisp :ffi)
> (defun sockGetStringAux (purpose len)
>     (ffi:with-foreign-object (buf '(ffi:c-array-max ffi:character len))
>         (sock_get_string_aux purpose buf len)
>         (ffi:foreign-value buf)))


I am affraid it is a bit more complicated.  Sockets may deliver
data in pieces with pieces having limited relation to our
logical structure.  So we need to collect incoming data
waiting up to time when data (in this case string) is complete.
And FriCASsys may get data from multiple sources, we do not
want to block waiting for data from one source because
inbetween there may appear complete data from other source.

-- 
                              Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/ZVjCb4KIDl9wL5rB%40fricas.org.

Reply via email to