Using GNU/Linux system call `splice` for zero-copy Socket to Socket data transfers in Haskell

后端 未结 2 450
日久生厌
日久生厌 2020-12-11 17:35

Update: Mr. Nemo\'s answer helped solve the problem! The code below contains the fix! See the nb False and nb True calls below.

相关标签:
2条回答
  • 2020-12-11 18:05

    Would the sendfile() syscall work for you? If so you can use the sendfile package.

    0 讨论(0)
  • 2020-12-11 18:11

    I don't know Haskell, but "resource temporarily unavailable" is EAGAIN.

    And it looks like Haskell sets its sockets to non-blocking mode by default. So if you try to read from one when there is no data, or try to write to one when its buffer is full, you will fail with EAGAIN.

    Figure out how to change the sockets to blocking mode, and I bet you will solve your problem.

    [update]

    Alternatively, call select or poll before attempting to read or write the socket. But you still need to handle EAGAIN, because there are rare corner cases where Linux select will indicate a socket is ready when actually it isn't.

    0 讨论(0)
提交回复
热议问题