From 2b588340af501825f3ab03f2e76dba0353c98fae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 4 Jun 2018 12:59:26 +0200 Subject: Update documentation for Gun 1.0 --- docs/en/gun/1.0/guide/connect/index.html | 57 +++++++++----------------------- 1 file changed, 16 insertions(+), 41 deletions(-) (limited to 'docs/en/gun/1.0/guide/connect') diff --git a/docs/en/gun/1.0/guide/connect/index.html b/docs/en/gun/1.0/guide/connect/index.html index 1e35e16b..ac1e6eb3 100644 --- a/docs/en/gun/1.0/guide/connect/index.html +++ b/docs/en/gun/1.0/guide/connect/index.html @@ -7,8 +7,6 @@ - - Nine Nines: Connection @@ -89,7 +87,7 @@ to reconnect automatically.

Opening a new connection

-

The gun:open/{2,3} function must be used to open a connection.

+

The gun:open/2,3 function must be used to open a connection.

Opening a connection to example.org on port 443
{ok, ConnPid} = gun:open("example.org", 443).

If the port given is 443, Gun will attempt to connect using -SSL. The protocol will be selected automatically using the +TLS. The protocol will be selected automatically using the ALPN extension for TLS. By default Gun supports HTTP/2 -and HTTP/1.1 when connecting using SSL.

-

For any other port, Gun will attempt to connect using TCP -and will use the HTTP/1.1 protocol.

-

The transport and protocol used can be overriden using +and HTTP/1.1 when connecting using TLS.

+

For any other port, Gun will attempt to connect using +plain TCP and will use the HTTP/1.1 protocol.

+

The transport and protocol used can be overriden via options. The manual documents all available options.

Options can be provided as a third argument, and take the form of a map.

-
Opening an SSL connection to example.org on port 8443
+
Opening a TLS connection to example.org on port 8443
-
{ok, ConnPid} = gun:open("example.org", 8443, #{transport=>ssl}).
+
{ok, ConnPid} = gun:open("example.org", 8443, #{transport => tls}).
@@ -122,7 +120,7 @@ http://www.gnu.org/software/src-highlite -->

When Gun successfully connects to the server, it sends a gun_up message with the protocol that has been selected for the connection.

-

Gun provides the functions gun:await_up/{1,2,3} that wait +

Gun provides the functions gun:await_up/1,2,3 that wait for the gun_up message. They can optionally take a monitor reference and/or timeout value. If no monitor is provided, one will be created for the duration of the function call.

@@ -141,7 +139,7 @@ http://www.gnu.org/software/src-highlite -->

When the connection is lost, Gun will send a gun_down message indicating the current protocol, the reason the -connection was lost and two list of stream references.

+connection was lost and two lists of stream references.

The first list indicates open streams that may have been processed by the server. The second list indicates open streams that the server did not process.

@@ -150,18 +148,17 @@ streams that the server did not process.

Monitoring the connection process

-

@todo Gun should detect the owner process being killed

Because software errors are unavoidable, it is important to detect when the Gun process crashes. It is also important to detect when it exits normally. Erlang provides two ways to do that: links and monitors.

Gun leaves you the choice as to which one will be used. -However, if you use the gun:await/{2,3} or gun:await_body/{2,3} +However, if you use the gun:await/2,3 or gun:await_body/2,3 functions, a monitor may be used for you to avoid getting stuck waiting for a message that will never come.

If you choose to monitor yourself you can do it on a permanent basis rather than on every message you will receive, saving -resources. Indeed, the gun:await/{3,4} and gun:await_body/{3,4} +resources. Indeed, the gun:await/3,4 and gun:await_body/3,4 functions both accept a monitor argument if you have one already.

Monitoring the connection process
@@ -180,10 +177,10 @@ by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite -->
receive
-        %% Receive Gun messages here...
-        {'DOWN', Mref, process, ConnPid, Reason} ->
-                error_logger:error_msg("Oops!"),
-                exit(Reason);
+    %% Receive Gun messages here...
+    {'DOWN', Mref, process, ConnPid, Reason} ->
+        error_logger:error_msg("Oops!"),
+        exit(Reason)
 end.

What to do when you receive a DOWN message is entirely up to you.

@@ -204,28 +201,6 @@ http://www.gnu.org/software/src-highlite --> perform the protocol’s closing handshake, if any.

-
-

Closing the connection gracefully

-
-

The connection can also be stopped gracefully by calling the -gun:shutdown/1 function.

-
-
Graceful shutdown of the connection
-
-
gun:shutdown(ConnPid).
-

Gun will refuse any new requests or messages after you call -this function. It will however continue to send you messages -for existing streams until they are all completed.

-

For example if you performed a GET request just before calling -gun:shutdown/1, you will still receive the response before -Gun closes the connection.

-

If you set a monitor beforehand, you will receive a message -when the connection has been closed.

-
-
-- cgit v1.2.3