diff mbox

[FFmpeg-devel] avformat/tls_schannel: fix handling of EOF after avio changes

Message ID 20180418183758.12824-1-h.leppkes@gmail.com
State Accepted
Commit 5c6365af454fb24f20d753ed99dd8e2b60e85035
Headers show

Commit Message

Hendrik Leppkes April 18, 2018, 6:37 p.m. UTC
---
 libavformat/tls_schannel.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Jan Ekström April 18, 2018, 7:10 p.m. UTC | #1
On Wed, Apr 18, 2018 at 9:37 PM, Hendrik Leppkes <h.leppkes@gmail.com> wrote:
> ---
>  libavformat/tls_schannel.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/libavformat/tls_schannel.c b/libavformat/tls_schannel.c
> index 9a6e0c92e3..f41b007773 100644
> --- a/libavformat/tls_schannel.c
> +++ b/libavformat/tls_schannel.c
> @@ -413,11 +413,13 @@ static int tls_read(URLContext *h, uint8_t *buf, int len)
>
>          ret = ffurl_read(s->tcp, c->enc_buf + c->enc_buf_offset,
>                           c->enc_buf_size - c->enc_buf_offset);
> -        if (ret < 0) {
> +        if (ret == AVERROR_EOF) {
> +            c->connection_closed = 1;
> +            ret = 0;
> +        } else if (ret < 0) {
>              av_log(h, AV_LOG_ERROR, "Unable to read from socket\n");
>              return ret;
> -        } else if (ret == 0)
> -            c->connection_closed = 1;
> +        }
>
>          c->enc_buf_offset += ret;
>      }
> @@ -515,7 +517,7 @@ cleanup:
>      if (ret == 0 && !c->connection_closed)
>          ret = AVERROR(EAGAIN);
>
> -    return ret < 0 ? ret : 0;
> +    return ret < 0 ? ret : AVERROR_EOF;
>  }
>
>  static int tls_write(URLContext *h, const uint8_t *buf, int len)
> --
> 2.17.0.windows.1
>

Ah yes, `retry_transfer_wrapper` which can return AVERROR_EOF :)
(which is what `ffurl_read` leads to). Funny how we have to convert
between zero and EOF upon entering and exiting due to the function's
initial design, but in general this gets a LGTM from me.

Jan
Hendrik Leppkes April 19, 2018, 11:32 a.m. UTC | #2
On Wed, Apr 18, 2018 at 9:10 PM, Jan Ekström <jeebjp@gmail.com> wrote:
> On Wed, Apr 18, 2018 at 9:37 PM, Hendrik Leppkes <h.leppkes@gmail.com> wrote:
>> ---
>>  libavformat/tls_schannel.c | 10 ++++++----
>>  1 file changed, 6 insertions(+), 4 deletions(-)
>>
>> diff --git a/libavformat/tls_schannel.c b/libavformat/tls_schannel.c
>> index 9a6e0c92e3..f41b007773 100644
>> --- a/libavformat/tls_schannel.c
>> +++ b/libavformat/tls_schannel.c
>> @@ -413,11 +413,13 @@ static int tls_read(URLContext *h, uint8_t *buf, int len)
>>
>>          ret = ffurl_read(s->tcp, c->enc_buf + c->enc_buf_offset,
>>                           c->enc_buf_size - c->enc_buf_offset);
>> -        if (ret < 0) {
>> +        if (ret == AVERROR_EOF) {
>> +            c->connection_closed = 1;
>> +            ret = 0;
>> +        } else if (ret < 0) {
>>              av_log(h, AV_LOG_ERROR, "Unable to read from socket\n");
>>              return ret;
>> -        } else if (ret == 0)
>> -            c->connection_closed = 1;
>> +        }
>>
>>          c->enc_buf_offset += ret;
>>      }
>> @@ -515,7 +517,7 @@ cleanup:
>>      if (ret == 0 && !c->connection_closed)
>>          ret = AVERROR(EAGAIN);
>>
>> -    return ret < 0 ? ret : 0;
>> +    return ret < 0 ? ret : AVERROR_EOF;
>>  }
>>
>>  static int tls_write(URLContext *h, const uint8_t *buf, int len)
>> --
>> 2.17.0.windows.1
>>
>
> Ah yes, `retry_transfer_wrapper` which can return AVERROR_EOF :)
> (which is what `ffurl_read` leads to). Funny how we have to convert
> between zero and EOF upon entering and exiting due to the function's
> initial design, but in general this gets a LGTM from me.
>

Applied, and ported to 4.0
diff mbox

Patch

diff --git a/libavformat/tls_schannel.c b/libavformat/tls_schannel.c
index 9a6e0c92e3..f41b007773 100644
--- a/libavformat/tls_schannel.c
+++ b/libavformat/tls_schannel.c
@@ -413,11 +413,13 @@  static int tls_read(URLContext *h, uint8_t *buf, int len)
 
         ret = ffurl_read(s->tcp, c->enc_buf + c->enc_buf_offset,
                          c->enc_buf_size - c->enc_buf_offset);
-        if (ret < 0) {
+        if (ret == AVERROR_EOF) {
+            c->connection_closed = 1;
+            ret = 0;
+        } else if (ret < 0) {
             av_log(h, AV_LOG_ERROR, "Unable to read from socket\n");
             return ret;
-        } else if (ret == 0)
-            c->connection_closed = 1;
+        }
 
         c->enc_buf_offset += ret;
     }
@@ -515,7 +517,7 @@  cleanup:
     if (ret == 0 && !c->connection_closed)
         ret = AVERROR(EAGAIN);
 
-    return ret < 0 ? ret : 0;
+    return ret < 0 ? ret : AVERROR_EOF;
 }
 
 static int tls_write(URLContext *h, const uint8_t *buf, int len)