]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Expand the explanation of how to go and do useful work in non-blocking
authorMatt Caswell <matt@openssl.org>
Tue, 5 Sep 2023 14:17:29 +0000 (15:17 +0100)
committerMatt Caswell <matt@openssl.org>
Fri, 8 Sep 2023 14:44:37 +0000 (15:44 +0100)
Add additional commentary to the non-blocking examples explaining where to
add code to go and do other useful work.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/21950)

demos/guide/quic-client-block.c
demos/guide/quic-client-non-block.c
demos/guide/tls-client-non-block.c
doc/man7/ossl-guide-quic-client-non-block.pod
doc/man7/ossl-guide-tls-client-non-block.pod

index 3d5a56a8dfb26ec8e7d2e0cf6b996660cd310f3b..b63012829f1853a837ab0236e858994f39e30e23 100644 (file)
@@ -47,7 +47,7 @@ static BIO *create_socket_bio(const char *hostname, const char *port,
      */
     for (ai = res; ai != NULL; ai = BIO_ADDRINFO_next(ai)) {
         /*
-         * Create a TCP socket. We could equally use non-OpenSSL calls such
+         * Create a UDP socket. We could equally use non-OpenSSL calls such
          * as "socket" here for this and the subsequent connect and close
          * functions. But for portability reasons and also so that we get
          * errors on the OpenSSL stack in the event of a failure we use
index 870dd1c4fe6ec72264fa4b7dd678e31398828c1b..be4c9b19676acbea5659177f36e34106ac64c825 100644 (file)
@@ -48,7 +48,7 @@ static BIO *create_socket_bio(const char *hostname, const char *port,
      */
     for (ai = res; ai != NULL; ai = BIO_ADDRINFO_next(ai)) {
         /*
-         * Create a TCP socket. We could equally use non-OpenSSL calls such
+         * Create a UDP socket. We could equally use non-OpenSSL calls such
          * as "socket" here for this and the subsequent connect and close
          * functions. But for portability reasons and also so that we get
          * errors on the OpenSSL stack in the event of a failure we use
@@ -139,8 +139,21 @@ static void wait_for_activity(SSL *ssl)
     /*
      * Wait until the socket is writeable or readable. We use select here
      * for the sake of simplicity and portability, but you could equally use
-     * poll/epoll or similar functions. If we have a timeout we use it to
-     * ensure that OpenSSL is called when it wants to be.
+     * poll/epoll or similar functions
+     *
+     * NOTE: For the purposes of this demonstration code this effectively
+     * makes this demo block until it has something more useful to do. In a
+     * real application you probably want to go and do other work here (e.g.
+     * update a GUI, or service other connections).
+     *
+     * Let's say for example that you want to update the progress counter on
+     * a GUI every 100ms. One way to do that would be to use the timeout in
+     * the last parameter to "select" below. If the tvp value is greater
+     * than 100ms then use 100ms instead. Then, when select returns, you
+     * check if it did so because of activity on the file descriptors or
+     * because of the timeout. If the 100ms GUI timeout has expired but the
+     * tvp timeout has not then go and update the GUI and then restart the
+     * "select" (with updated timeouts).
      */
 
     select(width, &rfds, &wfds, NULL, tvp);
index 05db0f529e66b9036832e20261240cd964e46c9f..dc6ee4dce8985b85c3787740eba3c540cb9d1198 100644 (file)
@@ -111,9 +111,21 @@ static void wait_for_activity(SSL *ssl, int write)
     width = sock + 1;
 
     /*
-     * Wait until the socket is writeable or readable. We use select here for
-     * the sake of simplicity and portability, but you could equally use
+     * Wait until the socket is writeable or readable. We use select here
+     * for the sake of simplicity and portability, but you could equally use
      * poll/epoll or similar functions
+     *
+     * NOTE: For the purposes of this demonstration code this effectively
+     * makes this demo block until it has something more useful to do. In a
+     * real application you probably want to go and do other work here (e.g.
+     * update a GUI, or service other connections).
+     *
+     * Let's say for example that you want to update the progress counter on
+     * a GUI every 100ms. One way to do that would be to add a 100ms timeout
+     * in the last parameter to "select" below. Then, when select returns,
+     * you check if it did so because of activity on the file descriptors or
+     * because of the timeout. If it is due to the timeout then update the
+     * GUI and then restart the "select".
      */
     if (write)
         select(width, NULL, &fds, NULL, NULL);
index b015a6fbf1d1a0ffe45b2edd397edf30f3c5621e..8187bb9b77d54f0959a3da1257f3c1023d291350 100644 (file)
@@ -103,8 +103,21 @@ function C<wait_for_activity()>.
         /*
          * Wait until the socket is writeable or readable. We use select here
          * for the sake of simplicity and portability, but you could equally use
-         * poll/epoll or similar functions. If we have a timeout we use it to
-         * ensure that OpenSSL is called when it wants to be.
+         * poll/epoll or similar functions
+         *
+         * NOTE: For the purposes of this demonstration code this effectively
+         * makes this demo block until it has something more useful to do. In a
+         * real application you probably want to go and do other work here (e.g.
+         * update a GUI, or service other connections).
+         *
+         * Let's say for example that you want to update the progress counter on
+         * a GUI every 100ms. One way to do that would be to use the timeout in
+         * the last parameter to "select" below. If the tvp value is greater
+         * than 100ms then use 100ms instead. Then, when select returns, you
+         * check if it did so because of activity on the file descriptors or
+         * because of the timeout. If the 100ms GUI timeout has expired but the
+         * tvp timeout has not then go and update the GUI and then restart the
+         * "select" (with updated timeouts).
          */
 
         select(width, &rfds, &wfds, NULL, tvp);
@@ -389,7 +402,7 @@ finished with it.
 
 Even though we have received EOF on the stream that we were reading from above,
 this tell us nothing about the state of the underlying connection. Our demo
-applicaiton will initiate the connection shutdown process via
+application will initiate the connection shutdown process via
 L<SSL_shutdown(3)>.
 
 Since our application is initiating the shutdown then we might expect to see
index 8f31ac69fbf87c98f197e090077049f7d7fd18e2..ea5e40bd1cadb5714a22500bcb50a152574d2411 100644 (file)
@@ -99,9 +99,21 @@ the underlying socket has become readable or writeable when it wasn't before.
         width = sock + 1;
 
         /*
-         * Wait until the socket is writeable or readable. We use select here for
-         * the sake of simplicity and portability, but you could equally use
+         * Wait until the socket is writeable or readable. We use select here
+         * for the sake of simplicity and portability, but you could equally use
          * poll/epoll or similar functions
+         *
+         * NOTE: For the purposes of this demonstration code this effectively
+         * makes this demo block until it has something more useful to do. In a
+         * real application you probably want to go and do other work here (e.g.
+         * update a GUI, or service other connections).
+         *
+         * Let's say for example that you want to update the progress counter on
+         * a GUI every 100ms. One way to do that would be to add a 100ms timeout
+         * in the last parameter to "select" below. Then, when select returns,
+         * you check if it did so because of activity on the file descriptors or
+         * because of the timeout. If it is due to the timeout then update the
+         * GUI and then restart the "select".
          */
         if (write)
             select(width, NULL, &fds, NULL, NULL);
@@ -116,7 +128,7 @@ the underlying socket(s) to become readable/writeable before returning. It also
 supports a "timeout" (as do most other similar functions) so in your own
 applications you can make use of this to periodically wake up and perform work
 while waiting for the socket state to change. But we don't use that timeout
-capability in this example.
+capability in this example for the sake of simplicity.
 
 =head2 Handling errors from OpenSSL I/O functions