-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage with Mirage #105
Comments
I've looked further into this, and it appears to be quite easy, actually. Here's the diff between ------ lwt/websocket_lwt.ml
++++++ mirage/websocket_mirage.ml
@|-23,1 +23,1 ============================================================
-|module Lwt_IO = IO(Cohttp_lwt_unix.IO)
+|module Lwt_IO = IO(Cohttp_lwt.IO)
@|-26,2 +26,2 ============================================================
-|module Request = Cohttp.Request.Make(Cohttp_lwt_unix.IO)
+|module Request = Cohttp.Request.Make(Cohttp_lwt.IO)
-|module Response = Cohttp.Response.Make(Cohttp_lwt_unix.IO)
+|module Response = Cohttp.Response.Make(Cohttp_lwt.IO)
@|-35,1 +35,1 ============================================================
-| flow: Conduit_lwt_unix.flow;
+| flow: Conduit_mirage.Flow.flow;
@|-95,1 +95,1 ============================================================
-| | Vchan of Conduit_lwt_unix.vchan_flow
+| | Vchan of Conduit_mirage.vchan_flow
@|-99,3 +99,3 ============================================================
-| | Conduit_lwt_unix.TCP tcp_flow ->
+| | Conduit_mirage.TCP tcp_flow ->
-| TCP (tcp_flow.Conduit_lwt_unix.ip, tcp_flow.Conduit_lwt_unix.port)
+| TCP (tcp_flow.Conduit_mirage.ip, tcp_flow.Conduit_mirage.port)
-| | Conduit_lwt_unix.Domain_socket { path; _ } ->
+| | Conduit_mirage.Domain_socket { path; _ } ->
@|-103,1 +103,1 ============================================================
-| | Conduit_lwt_unix.Vchan flow ->
+| | Conduit_mirage.Vchan flow ->
@|-110,1 +110,1 ============================================================
-| let open Conduit_lwt_unix in
+| let open Conduit_mirage in
@|-144,1 +144,1 ============================================================
-| ?(ctx=Conduit_lwt_unix.default_ctx)
+| ?(ctx=Conduit_mirage.default_ctx)
@|-155,1 +155,1 ============================================================
-| Conduit_lwt_unix.connect ~ctx client >>= fun (flow, ic, oc) ->
+| Conduit_mirage.connect ~ctx client >>= fun (flow, ic, oc) ->
@|-214,1 +214,1 ============================================================
-| ?(ctx=Conduit_lwt_unix.default_ctx) ~mode react =
+| ?(ctx=Conduit_mirage.default_ctx) ~mode react =
@|-256,1 +256,1 ============================================================
-| Conduit_lwt_unix.serve ?on_exn ?timeout ?stop ~ctx ~mode begin fun flow ic oc ->
+| Conduit_mirage.serve ?on_exn ?timeout ?stop ~ctx ~mode begin fun flow ic oc ->
@|-273,1 +273,1 ============================================================
-| ?on_exn ?check_request ?(ctx=Conduit_lwt_unix.default_ctx) ~mode react =
+| ?on_exn ?check_request ?(ctx=Conduit_mirage.default_ctx) ~mode react =
------ lwt/websocket_cohttp_lwt.ml
++++++ mirage/websocket_cohttp_mirage.ml
@|-21,1 +21,1 ============================================================
-|module Lwt_IO = Websocket.IO(Cohttp_lwt_unix.IO)
+|module Lwt_IO = Websocket.IO(Cohttp_mirage.IO)
@|-63,1 +63,1 ============================================================
-| | Conduit_lwt_unix.TCP tcp ->
+| | Mirage_conduit.TCP tcp -> Though we can certainly duplicate a bit of code, the question is whether this warrants extracting the common code to a functor. @vbmithr, how would you prefer to approach this? I'm happy to help with the implementation. Finally, |
I just happened to look into this right now. I'm trying to see what I can. |
|
Ok, I have refactored to the maximum. Either copy |
Thanks for the refactoring, @vbmithr! So my initial diff was terribly wrong, and this turned out be a much bigger rabbit hole than I anticipated 😅 After looking more closely at the code from a perspective of adding a Mirage-compatible websocket server without duplicating code, I made the following observations:
I might be missing something, or maybe there's a reason why the API and implementation has ended up like this. I'd be curious to learn if you have the time to elaborate. I've started dabbling with implementing some changes to address the above, but it's still unfinished. Unfortunately these changes are quite intrusive and can probably not be backwards-compatible 😞 |
On 10/24/18 7:27 PM, Andreas Garnaes wrote:
Unfortunately these changes are quite intrusive and can probably not be
backwards-compatible 😞
I don't care about backward compat.
If your changes are good I will merge them.
Best,
Vincent
|
On 10/24/18 7:27 PM, Andreas Garnaes wrote:
I might be missing something, or maybe there's a reason why the API and
implementation has ended up like this.
I have not written the cohttp lwt part. They guy that wrote it probably
needed something for him and did not try to be compatible with the rest
of the code, I guess.
|
A quick follow-up on this issue... I've worked on adding "response actions" to Cohttp (merged PR), which exposes the underlying input/output channels to the request handler. For the websocket server part of this repo, it means:
Instead of trying to make modifications directly to this repo, I've included an edited version of websocket handling logic in If you have any input or ideas, I'd be happy to hear. |
Currently
websocket-lwt
depends oncohttp-lwt-unix
, which makes it incompatible with Mirage. Do you have any thoughts on what it would take to implement a version that's compatible with Mirage, i.e. usingcohttp-lwt
andmirage-conduit
?The text was updated successfully, but these errors were encountered: