diff mbox series

[FFmpeg-devel] avformat/tls_mbedtls: Pass FLAG_NONBLOCK to underlying transport

Message ID tencent_B82EBC05477311685F13E3136D15D5891C05@qq.com
State Accepted
Commit 65c1c83ca42540415516c37e21c9aeb7dd2c96d1
Headers show
Series [FFmpeg-devel] avformat/tls_mbedtls: Pass FLAG_NONBLOCK to underlying transport | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Zhao Zhili April 8, 2024, 1:26 p.m. UTC
From: Zhao Zhili <zhilizhao@tencent.com>

This fix rtmps failure since rtmps requires nonblocking read.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
---
 libavformat/tls_mbedtls.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Dennis Mungai April 8, 2024, 1:32 p.m. UTC | #1
On Mon, 8 Apr 2024 at 16:26, Zhao Zhili <quinkblack@foxmail.com> wrote:

> From: Zhao Zhili <zhilizhao@tencent.com>
>
> This fix rtmps failure since rtmps requires nonblocking read.
>
> Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
> ---
>  libavformat/tls_mbedtls.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/libavformat/tls_mbedtls.c b/libavformat/tls_mbedtls.c
> index 8503523b6d..f51cf43b1c 100644
> --- a/libavformat/tls_mbedtls.c
> +++ b/libavformat/tls_mbedtls.c
> @@ -309,6 +309,8 @@ static int tls_read(URLContext *h, uint8_t *buf, int
> size)
>      TLSContext *tls_ctx = h->priv_data;
>      int ret;
>
> +    tls_ctx->tls_shared.tcp->flags &= ~AVIO_FLAG_NONBLOCK;
> +    tls_ctx->tls_shared.tcp->flags |= h->flags & AVIO_FLAG_NONBLOCK;
>      if ((ret = mbedtls_ssl_read(&tls_ctx->ssl_context, buf, size)) > 0) {
>          // return read length
>          return ret;
> @@ -322,6 +324,8 @@ static int tls_write(URLContext *h, const uint8_t
> *buf, int size)
>      TLSContext *tls_ctx = h->priv_data;
>      int ret;
>
> +    tls_ctx->tls_shared.tcp->flags &= ~AVIO_FLAG_NONBLOCK;
> +    tls_ctx->tls_shared.tcp->flags |= h->flags & AVIO_FLAG_NONBLOCK;
>      if ((ret = mbedtls_ssl_write(&tls_ctx->ssl_context, buf, size)) > 0) {
>          // return written length
>          return ret;
> --
> 2.25.1
>

Are other TLS layers affected, say OpenSSL, etc?
Zhao Zhili April 8, 2024, 1:40 p.m. UTC | #2
> On Apr 8, 2024, at 21:32, Dennis Mungai <dmngaie@gmail.com> wrote:
> 
> On Mon, 8 Apr 2024 at 16:26, Zhao Zhili <quinkblack@foxmail.com> wrote:
> 
>> From: Zhao Zhili <zhilizhao@tencent.com>
>> 
>> This fix rtmps failure since rtmps requires nonblocking read.
>> 
>> Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
>> ---
>> libavformat/tls_mbedtls.c | 4 ++++
>> 1 file changed, 4 insertions(+)
>> 
>> diff --git a/libavformat/tls_mbedtls.c b/libavformat/tls_mbedtls.c
>> index 8503523b6d..f51cf43b1c 100644
>> --- a/libavformat/tls_mbedtls.c
>> +++ b/libavformat/tls_mbedtls.c
>> @@ -309,6 +309,8 @@ static int tls_read(URLContext *h, uint8_t *buf, int
>> size)
>>     TLSContext *tls_ctx = h->priv_data;
>>     int ret;
>> 
>> +    tls_ctx->tls_shared.tcp->flags &= ~AVIO_FLAG_NONBLOCK;
>> +    tls_ctx->tls_shared.tcp->flags |= h->flags & AVIO_FLAG_NONBLOCK;
>>     if ((ret = mbedtls_ssl_read(&tls_ctx->ssl_context, buf, size)) > 0) {
>>         // return read length
>>         return ret;
>> @@ -322,6 +324,8 @@ static int tls_write(URLContext *h, const uint8_t
>> *buf, int size)
>>     TLSContext *tls_ctx = h->priv_data;
>>     int ret;
>> 
>> +    tls_ctx->tls_shared.tcp->flags &= ~AVIO_FLAG_NONBLOCK;
>> +    tls_ctx->tls_shared.tcp->flags |= h->flags & AVIO_FLAG_NONBLOCK;
>>     if ((ret = mbedtls_ssl_write(&tls_ctx->ssl_context, buf, size)) > 0) {
>>         // return written length
>>         return ret;
>> --
>> 2.25.1
>> 
> 
> Are other TLS layers affected, say OpenSSL, etc?

openssl and gnutls don’t get affected, since they have done the same operation.
I don’t know about schannel and securetransport.

> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Zhao Zhili April 11, 2024, 12:19 p.m. UTC | #3
> On Apr 8, 2024, at 21:26, Zhao Zhili <quinkblack@foxmail.com> wrote:
> 
> From: Zhao Zhili <zhilizhao@tencent.com>
> 
> This fix rtmps failure since rtmps requires nonblocking read.
> 
> Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
> ---
> libavformat/tls_mbedtls.c | 4 ++++
> 1 file changed, 4 insertions(+)
> 
> diff --git a/libavformat/tls_mbedtls.c b/libavformat/tls_mbedtls.c
> index 8503523b6d..f51cf43b1c 100644
> --- a/libavformat/tls_mbedtls.c
> +++ b/libavformat/tls_mbedtls.c
> @@ -309,6 +309,8 @@ static int tls_read(URLContext *h, uint8_t *buf, int size)
>     TLSContext *tls_ctx = h->priv_data;
>     int ret;
> 
> +    tls_ctx->tls_shared.tcp->flags &= ~AVIO_FLAG_NONBLOCK;
> +    tls_ctx->tls_shared.tcp->flags |= h->flags & AVIO_FLAG_NONBLOCK;
>     if ((ret = mbedtls_ssl_read(&tls_ctx->ssl_context, buf, size)) > 0) {
>         // return read length
>         return ret;
> @@ -322,6 +324,8 @@ static int tls_write(URLContext *h, const uint8_t *buf, int size)
>     TLSContext *tls_ctx = h->priv_data;
>     int ret;
> 
> +    tls_ctx->tls_shared.tcp->flags &= ~AVIO_FLAG_NONBLOCK;
> +    tls_ctx->tls_shared.tcp->flags |= h->flags & AVIO_FLAG_NONBLOCK;
>     if ((ret = mbedtls_ssl_write(&tls_ctx->ssl_context, buf, size)) > 0) {
>         // return written length
>         return ret;
> -- 
> 2.25.1

Will apply tomorrow.

> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavformat/tls_mbedtls.c b/libavformat/tls_mbedtls.c
index 8503523b6d..f51cf43b1c 100644
--- a/libavformat/tls_mbedtls.c
+++ b/libavformat/tls_mbedtls.c
@@ -309,6 +309,8 @@  static int tls_read(URLContext *h, uint8_t *buf, int size)
     TLSContext *tls_ctx = h->priv_data;
     int ret;
 
+    tls_ctx->tls_shared.tcp->flags &= ~AVIO_FLAG_NONBLOCK;
+    tls_ctx->tls_shared.tcp->flags |= h->flags & AVIO_FLAG_NONBLOCK;
     if ((ret = mbedtls_ssl_read(&tls_ctx->ssl_context, buf, size)) > 0) {
         // return read length
         return ret;
@@ -322,6 +324,8 @@  static int tls_write(URLContext *h, const uint8_t *buf, int size)
     TLSContext *tls_ctx = h->priv_data;
     int ret;
 
+    tls_ctx->tls_shared.tcp->flags &= ~AVIO_FLAG_NONBLOCK;
+    tls_ctx->tls_shared.tcp->flags |= h->flags & AVIO_FLAG_NONBLOCK;
     if ((ret = mbedtls_ssl_write(&tls_ctx->ssl_context, buf, size)) > 0) {
         // return written length
         return ret;