From patchwork Fri Nov 3 08:27:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jeyapal, Karthick" X-Patchwork-Id: 5841 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.90 with SMTP id m26csp3080629jah; Fri, 3 Nov 2017 01:27:28 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QiJoX+j2FXNokhg1udZO8FC7cg260IjeTeXaiyTzReWdGqZJqWTy88N/7ICl5qHquB4/EW X-Received: by 10.223.187.65 with SMTP id x1mr5055042wrg.26.1509697648302; Fri, 03 Nov 2017 01:27:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509697648; cv=none; d=google.com; s=arc-20160816; b=gbzrqvMsv2QIljmZhGg56+eZwGG6l3q6IyxXUoUeoVarASzwOIMAcyvi+FHhrjcMTk A6l2C2yc8vBT5llEqsMVv5RM5Ql/sy66odLuZ3gwUjixyXVfRKnVkACZnetGFBNo79bd W9H40ZOUgadfXW+F6mVpzmW72LEnHHVnXWhkW6eYoXy4pdVp21CgTJJuZJj+AWU7AT1g 4WoZCzP5ra6n0KLEJ+iZoNQmdCdHQTgiTcW6NJKWIT3wgkBAIGNeslMSxMS7Kt4Vooph aDw7LztsIR755LmN+dk4a1Sj3pEMZJo/WxQwvD0Tz6UWPcSJCK0RXZrNrsAhGJLoeU7k pO/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:feedback-id:message-id:date:to:from :dkim-signature:delivered-to:arc-authentication-results; bh=kiGt1Cs2CMqoSScIBSDHpEGE0LN0TZdHTWXxgMorcbc=; b=NgbroHl5Wdfp/RzdujnFCr5iX5WSFdbEHwnkP6JPoe/2b17M73lqwqQmXko0aNluNq 7X+9850rT12YE5OJJ5vyU+tuauwz8w8OJuo9bwQXhZ0Qloh1TjfGGNwVde2VK0KvJ3aH Xib33V1CPJ/A2E46nbJGLW7H4WosLNdifzU31W0A+SzgUjDagIVo5iChT4gz0dn9VFtk F4Kq+IeoGVQuQREoo8wpG/h6sY6jqxVQMv3NoN7N3Oe0uR+gXL/SWaPYB2nsKCVQ9aam EOQBx0Qjox5AZBASowHGjUUxc2ZAPXr2wW6HmPeXbO7RJiYA2fkPisqzw1NheSl3OB3E wXLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@smtpservice.net header.s=m78bu0.a1-4.dyn header.b=DeUuly0T; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=akamai.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f5si4609424wrg.35.2017.11.03.01.27.27; Fri, 03 Nov 2017 01:27:28 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@smtpservice.net header.s=m78bu0.a1-4.dyn header.b=DeUuly0T; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=akamai.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2D01268A165; Fri, 3 Nov 2017 10:27:15 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from a2i831.smtp2go.com (a2i831.smtp2go.com [103.47.207.63]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B652A68A12A for ; Fri, 3 Nov 2017 10:27:07 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=m78bu0.a1-4.dyn; x=1509698544; h=Feedback-ID: X-Smtpcorp-Track:Message-Id:Date:Subject:To:From:Reply-To:Sender: List-Unsubscribe; bh=6YNighIUPVfzpix5MfqKMjPZTMepvVssI71N32VO7yQ=; b=DeUuly0T MtTeAsbegwHN1CBLo7RwwIMc3dth56hDrMTbhhBU1lmQoOZInSIcERl0sb9Tf2YaRrFrYUnrubAzT 8x9sMT1ywGWBU2sCKZ2/hPiMx7yL7PrR+/ESZIZRawdWGYOBjtiZBIKb8vdiZkSrxJaSdnOVlGtLB m3LIEYwCrX228xbdgoxIX2y6ewIK37lTpCOdnM22jQPHAR9D2RepGUK7fwOTILpJ3GPUUQcTJXMiB IWTRib+06cUpYwWhMQkCqqOfqC8EzsgkAADm85/BSe9XwUzR3jqBYYrXPnbQSsL8HzXmGqJx4TwUr Z0qpb7bM3yT2JaV5PlLLn8iNwg==; From: Karthick J To: ffmpeg-devel@ffmpeg.org Date: Fri, 3 Nov 2017 13:57:00 +0530 Message-Id: <1509697623-2745-1-git-send-email-kjeyapal@akamai.com> X-Mailer: git-send-email 1.9.1 X-Smtpcorp-Track: 1-jbJpRyIebb5J.BGhg52nId Feedback-ID: 337386m:337386asVRLGB:337386sV-UVM3Z1P:SMTPCORP X-Report-Abuse: Please forward a copy of this message, including all headers, to Subject: [FFmpeg-devel] [PATCH 1/4] libformat/tcp: Moved all options to a separate structure X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Karthick J MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavformat/tcp.c | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/libavformat/tcp.c b/libavformat/tcp.c index 07b4ed9..06368ff 100644 --- a/libavformat/tcp.c +++ b/libavformat/tcp.c @@ -32,18 +32,22 @@ #include #endif -typedef struct TCPContext { - const AVClass *class; - int fd; +typedef struct TCPOptions { int listen; - int open_timeout; int rw_timeout; int listen_timeout; int recv_buffer_size; int send_buffer_size; +} TCPOptions; + +typedef struct TCPContext { + const AVClass *class; + int fd; + int open_timeout; + TCPOptions options; } TCPContext; -#define OFFSET(x) offsetof(TCPContext, x) +#define OFFSET(x) (offsetof(TCPContext, options) + offsetof(TCPOptions, x)) #define D AV_OPT_FLAG_DECODING_PARAM #define E AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { @@ -87,26 +91,26 @@ static int tcp_open(URLContext *h, const char *uri, int flags) if (p) { if (av_find_info_tag(buf, sizeof(buf), "listen", p)) { char *endptr = NULL; - s->listen = strtol(buf, &endptr, 10); + s->options.listen = strtol(buf, &endptr, 10); /* assume if no digits were found it is a request to enable it */ if (buf == endptr) - s->listen = 1; + s->options.listen = 1; } if (av_find_info_tag(buf, sizeof(buf), "timeout", p)) { - s->rw_timeout = strtol(buf, NULL, 10); + s->options.rw_timeout = strtol(buf, NULL, 10); } if (av_find_info_tag(buf, sizeof(buf), "listen_timeout", p)) { - s->listen_timeout = strtol(buf, NULL, 10); + s->options.listen_timeout = strtol(buf, NULL, 10); } } - if (s->rw_timeout >= 0) { + if (s->options.rw_timeout >= 0) { s->open_timeout = - h->rw_timeout = s->rw_timeout; + h->rw_timeout = s->options.rw_timeout; } hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; snprintf(portstr, sizeof(portstr), "%d", port); - if (s->listen) + if (s->options.listen) hints.ai_flags |= AI_PASSIVE; if (!hostname[0]) ret = getaddrinfo(NULL, portstr, &hints, &ai); @@ -142,21 +146,21 @@ static int tcp_open(URLContext *h, const char *uri, int flags) /* Set the socket's send or receive buffer sizes, if specified. If unspecified or setting fails, system default is used. */ - if (s->recv_buffer_size > 0) { - setsockopt (fd, SOL_SOCKET, SO_RCVBUF, &s->recv_buffer_size, sizeof (s->recv_buffer_size)); + if (s->options.recv_buffer_size > 0) { + setsockopt (fd, SOL_SOCKET, SO_RCVBUF, &s->options.recv_buffer_size, sizeof (s->options.recv_buffer_size)); } - if (s->send_buffer_size > 0) { - setsockopt (fd, SOL_SOCKET, SO_SNDBUF, &s->send_buffer_size, sizeof (s->send_buffer_size)); + if (s->options.send_buffer_size > 0) { + setsockopt (fd, SOL_SOCKET, SO_SNDBUF, &s->options.send_buffer_size, sizeof (s->options.send_buffer_size)); } - if (s->listen == 2) { + if (s->options.listen == 2) { // multi-client if ((ret = ff_listen(fd, cur_ai->ai_addr, cur_ai->ai_addrlen)) < 0) goto fail1; - } else if (s->listen == 1) { + } else if (s->options.listen == 1) { // single client if ((ret = ff_listen_bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen, - s->listen_timeout, h)) < 0) + s->options.listen_timeout, h)) < 0) goto fail1; // Socket descriptor already closed here. Safe to overwrite to client one. fd = ret; @@ -198,11 +202,11 @@ static int tcp_accept(URLContext *s, URLContext **c) TCPContext *sc = s->priv_data; TCPContext *cc; int ret; - av_assert0(sc->listen); + av_assert0(sc->options.listen); if ((ret = ffurl_alloc(c, s->filename, s->flags, &s->interrupt_callback)) < 0) return ret; cc = (*c)->priv_data; - ret = ff_accept(sc->fd, sc->listen_timeout, s); + ret = ff_accept(sc->fd, sc->options.listen_timeout, s); if (ret < 0) return ret; cc->fd = ret;