[FFmpeg-devel] [PATCH 5/8] lavf/tcp: increase range for listen and call the underlying socket operations accordingly

Nicolas George george at nsup.org
Tue Jul 21 11:26:26 CEST 2015


Le tridi 3 thermidor, an CCXXIII, Stephan Holljes a écrit :
> Signed-off-by: Stephan Holljes <klaxa1337 at googlemail.com>
> ---
>  libavformat/tcp.c | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/libavformat/tcp.c b/libavformat/tcp.c
> index 6f5e175..5505945 100644
> --- a/libavformat/tcp.c
> +++ b/libavformat/tcp.c
> @@ -45,7 +45,7 @@ typedef struct TCPContext {
>  #define D AV_OPT_FLAG_DECODING_PARAM
>  #define E AV_OPT_FLAG_ENCODING_PARAM
>  static const AVOption options[] = {
> -    { "listen",          "Listen for incoming connections",  OFFSET(listen),         AV_OPT_TYPE_INT, { .i64 = 0 },     0,       1,       .flags = D|E },
> +    { "listen",          "Listen for incoming connections",  OFFSET(listen),         AV_OPT_TYPE_INT, { .i64 = 0 },     0,       2,       .flags = D|E },
>      { "timeout",     "set timeout (in microseconds) of socket I/O operations", OFFSET(rw_timeout),     AV_OPT_TYPE_INT, { .i64 = -1 },         -1, INT_MAX, .flags = D|E },
>      { "listen_timeout",  "Connection awaiting timeout (in milliseconds)",      OFFSET(listen_timeout), AV_OPT_TYPE_INT, { .i64 = -1 },         -1, INT_MAX, .flags = D|E },
>      { NULL }
> @@ -126,12 +126,18 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
>          goto fail;
>      }
>  
> -    if (s->listen) {
> -        if ((ret = ff_listen_bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
> -                                  s->listen_timeout, h)) < 0) {
> +    if (s->listen == 2) {
> +        // multi-client

> +        if ((ret = ff_listen(fd, cur_ai->ai_addr, cur_ai->ai_addrlen)) < 0) {
> +            goto fail1;
> +        }

Nit: braces are unnecessary.

> +    } else if (s->listen == 1) {
> +        // single client
> +        if ((fd = ff_listen_bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
> +                                 s->listen_timeout, h)) < 0) {
> +            ret = fd;
>              goto fail1;
>          }
> -        fd = ret;
>      } else {
>          if ((ret = ff_listen_connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
>                                       s->open_timeout / 1000, h, !!cur_ai->ai_next)) < 0) {

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150721/4a2f377b/attachment.sig>


More information about the ffmpeg-devel mailing list