I am attempting to write a simple TCP server using Aleph. Everything works fine, except I am unsure of how I should detect when a channel has been closed.
From the documentation:
When the client closes the connection, both sides of the channel will be immediately sealed. The final message from the channel will be nil
However, I never seem to receive this final nil message. If I inspect the channel, I do see that it has been closed. Here is my code:
(use 'lamina.core 'aleph.tcp 'gloss.core)
(defn process-msg [ch msg]
(if (closed? ch)
(println "Channel has been closed") ;This never happens
(do-some-processing msg)))
(start-tcp-server
(fn [ch client-info]
(receive-all ch
(partial process-msg ch))
{:port 10000, :frame (string :utf-8 :delimiters ["\n"])})
Should I be doing something differently? Is my frame keeping the nil message from being processed? I could have a separate thread monitoring my channels and checking whether or not they have been closed, but this seems like a poor design. I would prefer to use Aleph, but right now its looking like I will need to use a raw Netty handler. Using Netty directly would be fine, but I’d prefer to use Aleph if possible since it feels a little more idiomatic.
https://github.com/ztellman/lamina/wiki/Channels