commit | 8b2d844d6fcd4c8f4e77d1455781e8ea68747eb7 | [log] [tgz] |
---|---|---|
author | Nick Vatamaniuc <vatamane@gmail.com> | Thu Aug 31 12:14:41 2023 -0400 |
committer | Nick Vatamaniuc <vatamane@gmail.com> | Thu Aug 31 13:00:54 2023 -0400 |
tree | a8f36b27126f1fb83438b44e4a4e258640ca55bf | |
parent | 073349423408e4bae08c90f8d16fee5317e45263 [diff] |
Add mochiweb_request:is_closed/1 function This function can used during long running request callbacks to detect if the client connection is closed. If the request callback periodically streams data back to the client, the act of writting to the client socket will detect if it is closed or not. However, in cases when no data is sent back, and the client times-out and closes the connection, it may be useful to be able to find out early and stop processing the request on the server. It turns out there is no easy way to detect if a passive mode socket is closed in Erlang/OTP [1]. Neither one of inet:monitor/1, inet:info/1, inet:getstat/1 work. However, it is possible to do it by querying the TCP state info of the socket. That option available in Linux since kernel 2.4 and on other Unix-like OSes (NetBSD, OpenBSD, FreeBSD and MacOS). Windows also has a tcp info query method however it is not reacheable via the gensockopts(2) standard socket API, so it can't be queried from Erlang's inet:getopts/2 API. [1] Using the newer socket module it's possible to detect if a socket is closed by attempting a recv with a MSG_PEEK option. However, the regular gen_tcp OTP module doesn't have a recv() variant which takes extra options. In addition, the new socket implementation still feels rather experimental. (It's not the default even in the latest OTP 26 release).
MochiWeb is an Erlang library for building lightweight HTTP servers.
MochiWeb provides a lightweight and fast solution for building HTTP servers in Erlang. The library provides features for building robust and scalable HTTP servers.
Before you can use MochiWeb, you'll need to have Erlang OTP installed. Once you have Erlang OTP installed, you can download the latest version of MochiWeb from the GitHub repository.
For a MochiWeb project, first obtain a copy of MochiWeb using Git by running the command.
$ git clone git://github.com/mochi/mochiweb.git.
To create a project.
$ cd mochiweb $ make app PROJECT=exampleName
You can now start the project with.
$ cd ../exampleName/ $ make $ ./start-dev.sh
You can access the app by navigating to http://localhost:8080 in your browser.
For an example, view the example_project
in the examples/
folder.
Lightweight: MochiWeb is designed to be lightweight and fast, making it ideal for use in resource-constrained environments.
Easy to use: MochiWeb provides a simple and intuitive API that makes it easy to get started with building HTTP servers.
Robust: MochiWeb provides a comprehensive set of features for building robust and scalable HTTP servers.
Information about Rebar (Erlang build tool)
OTP 21.2 (up to and including 21.2.2) introduced an SSL regression that makes these releases unsafe to use. See ERL-830. This issue was resolved in OTP 21.2.3.
MochiWeb is an open-source project and welcomes contributions from the community.