kazu-yamamoto / network-run

Simple network runner library in Haskell
BSD 3-Clause "New" or "Revised" License
10 stars 5 forks source link

runTCPServerWithListenSocket #7

Closed kazu-yamamoto closed 4 months ago

kazu-yamamoto commented 4 months ago

I think that the essential issue of #6 is there is no way to pass a socket to the run function. With a recent discussion with @khibino, I realized that a resource acquire mechanism and a protocol run function should be separated.

@edsko @FinleyMcIlwaine I believe that this is a smarter approach than #6. What do you think?

edsko commented 4 months ago

Sorry, I'm not sure I understand. Let me try to explain:

As far as I can tell, this PR (#7) is therefore entirely orthogonal to #6: it is still not possible to reuse openServerSocket to create a socket for which, say, TCP_NODELAY is set, nor is it possible to run the client with a socket initialized in a user-specified manner.

Personally I don't have a strong preference for runTCPServerWithSocket versus runTCPServerWithListenSocket; they are mostly equivalent as far as I can see, with the other minor proviso that with runTCPServerWithListenSocket the user is more likely to forget to bracket the call to openServerSocket.

Perhaps one aspect of #6 that muddled the waters a bit was that we also added runTCPServerWithSocketOptions and runTCPClientWithSocketOptions; that might have confused matters and suggested that in fact we do not separate a "resource acquire mechanism" from a "protocol run function"; but that's not really the case, those functions were added for a more convenient API only. They could easily be removed (and arguably should be removed), leaving only runTCPServerWithSocket and runTCPClientWithSocket (the protocol run function), and then open{Server,Client}Socket{,WithOptions} as the ways to construct the socket (acquire the resource).

This is a lot of text, sorry. Perhaps the following helps:

runTCPServer                         runTCPClient

runTCPServerWithSocket        (#3)   runTCPClientWithSocket       (#6)
runTCPServerWithListenSocket  (#7)   ------

openServerSocket                     openClientSocket
openServerSocketWithOptions   (#6)   openClientSocketWithOptions  (#6)

-- OPTIONAL, for convenience only --

runTCPServerWithSocketOptions (#6)  runTCPClientWithSocketOptions (#6)