print ubyte[] as (ascii) string
frame
frame86 at live.com
Sat Jan 8 02:38:55 UTC 2022
On Friday, 7 January 2022 at 22:04:28 UTC, eugene wrote:
> There are 2 buffers (RX one and TX one, both of 'reasonable'
> size)
> (it's the effing echo-server, nothing more)
>
> * print content of RX-buffer, ommiting terminating '\n' ('\n'
> is the 'end of request') to (log/journal file)/stdout/
>
> * ouptut received 'message' back to client, _with_ terminating
> '\n'
However, you should not rely on a terminating '\n' even you are
the source. You determine the length of string trough '\n' but
maybe your buffer doesn't contain it (yet) if the connection
wasn't blocking or the message is longer as the buffer size or
you received just error data.
Then, accessing the ubyte[] data directly via `.ptr`/ casting it
to char* without knowing the possible content seems not a good
idea - if you are using any function that returns bytes till it
finds a needle or terminating '\0'.
I know it's a little bit off topic but if the question is about
the best concise way, the solution you choose should respect that
too.
More information about the Digitalmars-d-learn
mailing list