Closed spiralman closed 8 years ago
Sounds mostly reasonable. I am not a fan of interrupting a http request in general, but I can see it's the easiest way sometimes. Manually merged it with my WiP, i'm working on some stuff like this anyway.
@Spritetm thanks for taking a look and merging it in.
Out of curiosity, what would you recommend instead of interrupting the request?
FWIW, this seems very close to how most modern asynchronous web frameworks and servers (node.js/Tornado/Netty/NGINX) work. Although, they usually have an outer event loop controlling continuation, rather than relying on direct callbacks. That felt like overkill for this change, though.
I would say either AJAX polling or websockets, but I can imagine that's a bit overkill for a simple interface.
Ah, this should be in the repos already. Closing.
Hopefully the change to the README makes the usage clear, but to provide a little more detail on my use-case:
I'm writing some firmware that proxies HTTP requests back to a device that uses a line-oriented TCP protocol with a persistent connection (a la Telnet). When I get an HTTP request, I need to issue a command to the other device, "pause" the HTTP connection, then resume it when I receive the response back from the other device, returning the received data.
Currently, I'm doing this by backing-up
connData->conn
,connData->remote_ip
andconnData->remote_port
, then callinghttpdSentCb
with those values. This feels like I'm relying too much on an internal implementation detail, and it also results in an unnecessary call tohttpdFindConnData
.This change just makes the resumption of a suspended connection an explicit function, and updates the sent callback to use that function. I'm not sure if there's any value in checking the send backlog when explicitly resuming like this, but it looks like it's not hurting anything, so feels like the most straightforward change.
(BTW, thanks for a great library. It's shaved many nights of work off my little toy project, and got me going quickly!)