• 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
..
AsyncUpdates Loading commit data...
Config Loading commit data...
Ext Loading commit data...
Flow Loading commit data...
Mail Loading commit data...
Methods Loading commit data...
NodeStory Loading commit data...
Text Loading commit data...
Types Loading commit data...
Utils Loading commit data...
Viz Loading commit data...
AsyncUpdates.hs Loading commit data...
Config.hs Loading commit data...
Mail.hs Loading commit data...
NLP.hs Loading commit data...
NodeStory.hs Loading commit data...
NodeStoryFile.hs.old Loading commit data...
Statistics.hs Loading commit data...
Text.hs Loading commit data...
Types.hs Loading commit data...
Utils.hs Loading commit data...
Viz.hs Loading commit data...