Commit 15b732f5 authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

ws: remove calls to recvMalloc

Remove the calls to `recvMalloc` in favour of using the (patched) `recv`
from the original nanomsg library, which shouldn't segfault anymore. The
reason for using `recv` are a few, but mostly the fact that `recv` can
allocated arbitrary-long payloads data (up to the 1MB limit) without an
hardcoded limit like `recvMalloc` was imposing. Furthermore, `recv` does
resource cleanup for us via `c_nn_freemsg`, whereas `recvMalloc` is not
thread/exception safe. Consider the implementation:

```
recvMalloc :: Receiver a => Socket a -> Int -> IO ByteString
recvMalloc (Socket t sid) numBytes = do
  ptr <- mallocBytes numBytes
  -- receive by blocking the thread
  len <- c_nn_recv sid ptr (#const NN_MSG) 0 -- (#const NN_DONTWAIT)
  str <- C.packCStringLen (castPtr ptr, fromIntegral len)
  free ptr
  return str
```

If any exception (synchronous or asynchronous) strikes _before_ the call
to `free`, we would be leaking C memory.
parent 7c0d6ba0
Pipeline #6569 failed with stages
in 12 minutes and 40 seconds