• Alfredo Di Napoli's avatar
    ws: remove calls to recvMalloc · 15b732f5
    Alfredo Di Napoli authored
    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.
    15b732f5
Name
Last commit
Last update
bench Loading commit data...
bench-data/phylo Loading commit data...
bin Loading commit data...
devops Loading commit data...
docs Loading commit data...
ekg-assets Loading commit data...
nix Loading commit data...
src Loading commit data...
src-doctest Loading commit data...
test Loading commit data...
test-data Loading commit data...
.clippy.dhall Loading commit data...
.envrc Loading commit data...
.gitignore Loading commit data...
.gitlab-ci.yml Loading commit data...
.mailmap Loading commit data...
CHANGELOG.md Loading commit data...
CODE_OF_CONDUCT.md Loading commit data...
DEVELOPER_GUIDELINES.md Loading commit data...
LICENSE Loading commit data...
README.md Loading commit data...
cabal.project Loading commit data...
cabal.project.freeze Loading commit data...
cabal.project.local_toCopy Loading commit data...
gargantext-settings.toml Loading commit data...
gargantext.cabal Loading commit data...
gargantext.ini_toModify Loading commit data...
run Loading commit data...
server Loading commit data...
shell.nix Loading commit data...
stack.yaml Loading commit data...
start Loading commit data...
weeder.dhall Loading commit data...