<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<meta content="text/html; charset=US-ASCII" http-equiv="Content-Type">
<title>
GitLab
</title>
<style data-premailer="ignore" type="text/css">
a { color: #1068bf; }
</style>
<style>img {
max-width: 100%; height: auto;
}
body {
font-size: 0.875rem;
}
body {
-webkit-text-shadow: rgba(255,255,255,0.01) 0 0 1px;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Ubuntu, Cantarell, "Helvetica Neue", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; font-size: inherit;
}
</style>
</head>
<body style='font-size: inherit; -webkit-text-shadow: rgba(255,255,255,0.01) 0 0 1px; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Ubuntu, Cantarell, "Helvetica Neue", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";'>
<div class="content">
<p style="color: #777777;">
<a href="https://gitlab.com/cwwanner1967">Chuck Wanner</a>
<a href="https://gitlab.com/gnutls/gnutls/-/issues/1413#note_1135039277">commented</a>:
</p>
<div class="md" style="color: #303030; word-wrap: break-word;">
<p dir="auto" style="color: #303030; margin: 0 0 16px;" align="initial">I was reading the documentation for the <code style='font-size: 90%; color: #1f1f1f; word-wrap: break-word; background-color: #f0f0f0; border-radius: 4px; margin-top: 0; font-weight: inherit; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 2px 4px;'>gnutls_transport_set_pull_timeout_function</code> and <code style='font-size: 90%; color: #1f1f1f; word-wrap: break-word; background-color: #f0f0f0; border-radius: 4px; font-weight: inherit; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 2px 4px;'>gnutls_transport_set_pull_function</code>. I am a bit confused. If the <code style='font-size: 90%; color: #1f1f1f; word-wrap: break-word; background-color: #f0f0f0; border-radius: 4px; font-weight: inherit; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 2px 4px;'>GNUTLS_NONBLOCK</code> flag is set, the documentation indicates the pull timeout callback will not be invoked. But the <code style='font-size: 90%; color: #1f1f1f; word-wrap: break-word; background-color: #f0f0f0; border-radius: 4px; font-weight: inherit; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 2px 4px;'>gnutls_transport_set_pull_function</code> indicates that the pull callback should only return when data is received (number of bytes received), the connection is terminated (return 0), or connection error (return -1). The pull function does not have a return value to indicate there is no data and the connection is valid.</p>
<p dir="auto" style="color: #303030; margin: 0 0 16px;" align="initial">How is GNUTLS consider non-blocking, if only the pull function is invoked?</p>
<p dir="auto" style="color: #303030; margin: 0 0 16px;" align="initial">The <code style='font-size: 90%; color: #1f1f1f; word-wrap: break-word; background-color: #f0f0f0; border-radius: 4px; margin-top: 0; font-weight: inherit; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 2px 4px;'>gnutls_transport_set_pull_timeout_function</code> documentation indicates if the timeout is zero, the function should return 0 immediately if no data is available. I do not think this is correct. Reviewing the code, if the timeout is zero the pull timeout function will not be invoked. The pull function is invoked which will pend forever until data is received, the connection is terminated, or the connection has an error.</p>
<p dir="auto" style="color: #303030; margin: 0 0 16px;" align="initial">In the gnutls-3.6.16/lib/buffers.c, function <code style='font-size: 90%; color: #1f1f1f; word-wrap: break-word; background-color: #f0f0f0; border-radius: 4px; margin-top: 0; font-weight: inherit; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 2px 4px;'>_gnutls_dgram_read</code> at line 251 will not invoke the pull timeout function if the timeout is zero.</p>
<div class="gl-relative markdown-code-block js-markdown-code">
<pre class="code highlight js-syntax-highlight language-plaintext" lang="plaintext" data-canonical-lang="" v-pre="true" style='display: block; font-size: 13px; color: #303030; line-height: 1.6em; overflow-x: auto; border-radius: 4px; position: relative; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; word-break: break-all; word-wrap: break-word; background-color: #fafafa; margin: 0 0 16px; padding: 12px; border: 1px solid #dbdbdb;'><code style='font-size: inherit; color: inherit; word-wrap: normal; word-break: keep-all; background-color: inherit; border-radius: 4px; white-space: pre; margin-top: 0; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; overflow-wrap: normal; padding: unset;'><span id="LC1" class="line" lang="plaintext" style="margin-top: 0;"> if (ms && *ms > 0) {</span>
<span id="LC2" class="line" lang="plaintext"> ret = _gnutls_io_check_recv(session, *ms);</span>
<span id="LC3" class="line" lang="plaintext"> if (ret < 0)</span>
<span id="LC4" class="line" lang="plaintext"> return gnutls_assert_val(ret);</span>
<span id="LC5" class="line" lang="plaintext"> gnutls_gettime(&t1);</span>
<span id="LC6" class="line" lang="plaintext"> }</span>
<span id="LC7" class="line" lang="plaintext"> *bufel = _mbuffer_alloc_align16(max_size, get_total_headers(session));</span>
<span id="LC8" class="line" lang="plaintext"> if (*bufel == NULL)</span>
<span id="LC9" class="line" lang="plaintext"> return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);</span>
<span id="LC10" class="line" lang="plaintext"></span>
<span id="LC11" class="line" lang="plaintext"> ptr = (*bufel)->msg.data;</span>
<span id="LC12" class="line" lang="plaintext"></span>
<span id="LC13" class="line" lang="plaintext"> reset_errno(session);</span>
<span id="LC14" class="line" lang="plaintext"> i = pull_func(fd, ptr, recv_size);</span></code></pre>
<copy-code></copy-code>
</div>
<p dir="auto" style="color: #303030; margin: 0 0 16px;" align="initial">Note: Function <code style='font-size: 90%; color: #1f1f1f; word-wrap: break-word; background-color: #f0f0f0; border-radius: 4px; margin-top: 0; font-weight: inherit; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 2px 4px;'>_gnutls_io_check_recv</code> invokes the Pull Timeout function</p>
<div class="gl-relative markdown-code-block js-markdown-code" style="margin-bottom: 0;">
<pre class="code highlight js-syntax-highlight language-plaintext" lang="plaintext" data-canonical-lang="" v-pre="true" style='display: block; font-size: 13px; color: #303030; line-height: 1.6em; overflow-x: auto; border-radius: 4px; position: relative; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; word-break: break-all; word-wrap: break-word; background-color: #fafafa; margin: 0 0 16px; padding: 12px; border: 1px solid #dbdbdb;'><code style='font-size: inherit; color: inherit; word-wrap: normal; word-break: keep-all; background-color: inherit; border-radius: 4px; white-space: pre; margin-top: 0; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; overflow-wrap: normal; padding: unset;'><span id="LC1" class="line" lang="plaintext" style="margin-top: 0;">/* Checks whether there are received data within</span>
<span id="LC2" class="line" lang="plaintext"> * a timeframe.</span>
<span id="LC3" class="line" lang="plaintext"> *</span>
<span id="LC4" class="line" lang="plaintext"> * Returns 0 if data were received, GNUTLS_E_TIMEDOUT</span>
<span id="LC5" class="line" lang="plaintext"> * on timeout and a negative error code on error.</span>
<span id="LC6" class="line" lang="plaintext"> */</span>
<span id="LC7" class="line" lang="plaintext">int _gnutls_io_check_recv(gnutls_session_t session, unsigned int ms)</span>
<span id="LC8" class="line" lang="plaintext">{</span>
<span id="LC9" class="line" lang="plaintext"> gnutls_transport_ptr_t fd = session->internals.transport_recv_ptr;</span>
<span id="LC10" class="line" lang="plaintext"> int ret = 0, err;</span>
<span id="LC11" class="line" lang="plaintext"></span>
<span id="LC12" class="line" lang="plaintext"> if (NO_TIMEOUT_FUNC_SET(session)) {</span>
<span id="LC13" class="line" lang="plaintext"> _gnutls_debug_log("The pull function has been replaced but not the pull timeout.\n");</span>
<span id="LC14" class="line" lang="plaintext"> return gnutls_assert_val(GNUTLS_E_PULL_ERROR);</span>
<span id="LC15" class="line" lang="plaintext"> }</span>
<span id="LC16" class="line" lang="plaintext"></span>
<span id="LC17" class="line" lang="plaintext"> reset_errno(session);</span>
<span id="LC18" class="line" lang="plaintext"></span>
<span id="LC19" class="line" lang="plaintext"> ret = session->internals.pull_timeout_func(fd, ms);</span>
<span id="LC20" class="line" lang="plaintext"> if (ret == -1) {</span>
<span id="LC21" class="line" lang="plaintext"> err = get_errno(session);</span>
<span id="LC22" class="line" lang="plaintext"> _gnutls_read_log</span>
<span id="LC23" class="line" lang="plaintext"> ("READ_TIMEOUT: %d returned from %p, errno=%d (timeout: %u)\n",</span>
<span id="LC24" class="line" lang="plaintext"> (int) ret, fd, err, ms);</span>
<span id="LC25" class="line" lang="plaintext"> return errno_to_gerr(err, IS_DTLS(session));</span>
<span id="LC26" class="line" lang="plaintext"> }</span>
<span id="LC27" class="line" lang="plaintext"></span>
<span id="LC28" class="line" lang="plaintext"> if (ret > 0)</span>
<span id="LC29" class="line" lang="plaintext"> return 0;</span>
<span id="LC30" class="line" lang="plaintext"> else</span>
<span id="LC31" class="line" lang="plaintext"> return GNUTLS_E_TIMEDOUT;</span>
<span id="LC32" class="line" lang="plaintext">}</span></code></pre>
<copy-code></copy-code>
</div>
</div>
</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #666;">
—
<br>
Reply to this email directly or <a href="https://gitlab.com/gnutls/gnutls/-/issues/1413#note_1135039277">view it on GitLab</a>.
<br>
You're receiving this email because of your account on <a target="_blank" rel="noopener noreferrer" href="https://gitlab.com">gitlab.com</a>. <a href="https://gitlab.com/-/sent_notifications/7fe68e1096bf856e6faf6ddfc89e82d9/unsubscribe" target="_blank" rel="noopener noreferrer">Unsubscribe</a> from this thread · <a href="https://gitlab.com/-/profile/notifications" target="_blank" rel="noopener noreferrer" class="mng-notif-link">Manage all notifications</a> · <a href="https://gitlab.com/help" target="_blank" rel="noopener noreferrer" class="help-link">Help</a>
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Issue","url":"https://gitlab.com/gnutls/gnutls/-/issues/1413#note_1135039277"}}</script>
</p>
</div>
</body>
</html>