X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Ftls_schannel.c;h=d4959f75fa63609bdda230600c04b3ac6b131b1f;hb=cb789fd2b34864df30bc4b664cfee632dca0a1e4;hp=9a6e0c92e37af7dd2278f6391ef3bba212a16ab6;hpb=87faeb1e685eedc49d9cb6de14bab1cfc88ab655;p=ffmpeg diff --git a/libavformat/tls_schannel.c b/libavformat/tls_schannel.c index 9a6e0c92e37..d4959f75fa6 100644 --- a/libavformat/tls_schannel.c +++ b/libavformat/tls_schannel.c @@ -138,8 +138,7 @@ static int tls_close(URLContext *h) av_freep(&c->dec_buf); c->dec_buf_size = c->dec_buf_offset = 0; - if (c->tls_shared.tcp) - ffurl_close(c->tls_shared.tcp); + ffurl_closep(&c->tls_shared.tcp); return 0; } @@ -148,7 +147,7 @@ static int tls_client_handshake_loop(URLContext *h, int initial) TLSContext *c = h->priv_data; TLSShared *s = &c->tls_shared; SECURITY_STATUS sspi_ret; - SecBuffer outbuf[3]; + SecBuffer outbuf[3] = { 0 }; SecBufferDesc outbuf_desc; SecBuffer inbuf[2]; SecBufferDesc inbuf_desc; @@ -392,7 +391,12 @@ static int tls_read(URLContext *h, uint8_t *buf, int len) int size, ret; int min_enc_buf_size = len + SCHANNEL_FREE_BUFFER_SIZE; - if (len <= c->dec_buf_offset) + /* If we have some left-over data from previous network activity, + * return it first in case it is enough. It may contain + * data that is required to know whether this connection + * is still required or not, esp. in case of HTTP keep-alive + * connections. */ + if (c->dec_buf_offset > 0) goto cleanup; if (c->sspi_close_notify) @@ -413,16 +417,18 @@ 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; } - while (c->enc_buf_offset > 0 && sspi_ret == SEC_E_OK && c->dec_buf_offset < len) { + while (c->enc_buf_offset > 0 && sspi_ret == SEC_E_OK) { /* input buffer */ init_sec_buffer(&inbuf[0], SECBUFFER_DATA, c->enc_buf, c->enc_buf_offset); @@ -515,7 +521,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) @@ -583,6 +589,12 @@ static int tls_get_file_handle(URLContext *h) return ffurl_get_file_handle(c->tls_shared.tcp); } +static int tls_get_short_seek(URLContext *h) +{ + TLSContext *s = h->priv_data; + return ffurl_get_short_seek(s->tls_shared.tcp); +} + static const AVOption options[] = { TLS_COMMON_OPTIONS(TLSContext, tls_shared), { NULL } @@ -602,6 +614,7 @@ const URLProtocol ff_tls_protocol = { .url_write = tls_write, .url_close = tls_close, .url_get_file_handle = tls_get_file_handle, + .url_get_short_seek = tls_get_short_seek, .priv_data_size = sizeof(TLSContext), .flags = URL_PROTOCOL_FLAG_NETWORK, .priv_data_class = &tls_class,