Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

channel.read has side effect without type representation #206

Open
ubourdon opened this issue May 27, 2020 · 3 comments
Open

channel.read has side effect without type representation #206

ubourdon opened this issue May 27, 2020 · 3 comments

Comments

@ubourdon
Copy link

ubourdon commented May 27, 2020

I talk from zio.nio part of the lib (not core)
If i understand correclty, channel.read

def f(channel: AsynchronousSocketChannel) = {
   val _first3: IO[Exception, Chunk[Byte]] = channel.read(3)
   val _second3: IO[Exception, Chunk[Byte]] = channel.read(3)
}

read 3 first byte of the buffer link to the channel, and if we redo channel.read(3) that read the next 3 byte of the buffer for this channel right ?

From a FP/ZIO point of view is it not a huge issue ?

How can I simply perform for example, an recursive/fold read of the channel with chunk of byte ?
What i mean, i have channel with X bytes, i decide to use 80 byte buffer, to be sure i read all, i need to iterate on my channel until it say me "ok you read all" (equivalent to buffer return -1).

@tusharmath
Copy link

@ubourdon I don't think there is any concept of "read all" from a Socket's point of view.
Socket's keep sending and receiving messages until they are closed. Buffer's, on the other hand, have a finite capacity and so have a concept of "final" and "end of file".

Typically if you are implementing an HTTP server, you "reading" any message that comes in, until a \r\n is received, which will mark the end of an HTTP request.

@ubourdon
Copy link
Author

To do that, you must specify a buffer size and read this size several time until you find \r\n no ?

@ubourdon
Copy link
Author

But beyond that,

channel.read mutate the state of channel without any type returned by the action.

channel.read don't return same result if i call it 2 or moe times, that brake the Referential transparency principle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants