
I'm trying to write a program whose network behaviour is analogous to a web proxy. A client connects to my server and gives me some data, my server connects to an upstream server and gives data to it, my server gets data from upstream, and gives data to the client. I'd like to write this using the enumerator library, since it seems like it should be possible to do that cleanly. Now, the guts of an echo server are pretty easy: runIteratee $ enumSocket cs sock $$ iterSocket sock That's just plain pretty. You can even put interesting data tranformations (Enumeratees) in there to make it behave a bit differently. What I'd like to do is have an Enumeratee that connects to the upstream server, forwards the request, and then uses one of the Data.Enumerator.List functions to generate a response that is the response from the upstream server. It doesn't look like this is possible though, since Enumeratees are pretty much one output per input. Is my basic model broken here? It's occurred to me that what I actually want to do is tie the enumSocket clientSock to an iterSocket upstreamSock, do the reverse, and then do two runIteratee calls (one in a forkIO, I guess?). That seems uglier, I'm not sure if there would be complications in making sure both Iteratees stop running correctly. Is that the right way to do, or am I just missing some capability that Enumeratees have?

On Sun, Sep 4, 2011 at 6:03 PM, tsuraan
Is my basic model broken here? It's occurred to me that what I actually want to do is tie the enumSocket clientSock to an iterSocket upstreamSock, do the reverse, and then do two runIteratee calls (one in a forkIO, I guess?). That seems uglier, I'm not sure if there would be complications in making sure both Iteratees stop running correctly. Is that the right way to do, or am I just missing some capability that Enumeratees have?
For this specific problem I recommend using a forkIO'd
Iteratee/Enumerator pair with a Chan to shuttle data between them, I
think it's probably the best way of doing it.
G
--
Gregory Collins

For this specific problem I recommend using a forkIO'd Iteratee/Enumerator pair with a Chan to shuttle data between them, I think it's probably the best way of doing it.
Googling for "enumerator chan" gives me this gist (written by you in April): https://gist.github.com/932384 . Is that what you're thinking? Have each socket's read and write tied to a chan enumerator or iterator as appropriate, and steer the data around as desired? My actual problem involved multiple upstream server and merging the data from all of them, so I think, assuming I'm understanding you correctly, that this would make a lot of sense.

On Sun, Sep 4, 2011 at 7:09 PM, tsuraan
For this specific problem I recommend using a forkIO'd Iteratee/Enumerator pair with a Chan to shuttle data between them, I think it's probably the best way of doing it.
Googling for "enumerator chan" gives me this gist (written by you in April): https://gist.github.com/932384 . Is that what you're thinking? Have each socket's read and write tied to a chan enumerator or iterator as appropriate, and steer the data around as desired? My actual problem involved multiple upstream server and merging the data from all of them, so I think, assuming I'm understanding you correctly, that this would make a lot of sense.
I think that's roughly what I had in mind, yes.
G
--
Gregory Collins
participants (2)
-
Gregory Collins
-
tsuraan