From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id DD2CC138350 for ; Thu, 30 Apr 2020 06:31:37 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id EB39FE090A; Thu, 30 Apr 2020 06:31:36 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id CC996E090A for ; Thu, 30 Apr 2020 06:31:36 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 3D70634EEE4 for ; Thu, 30 Apr 2020 06:31:35 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id C02EF1DD for ; Thu, 30 Apr 2020 06:31:32 +0000 (UTC) From: "Robin H. Johnson" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Robin H. Johnson" Message-ID: <1588228193.a8b0ba36853eea23c0e07bcc680bdbe877dcd68e.robbat2@gentoo> Subject: [gentoo-commits] proj/gentoo-mirrorstats:master commit in: / X-VCS-Repository: proj/gentoo-mirrorstats X-VCS-Files: probe-mirmon X-VCS-Directories: / X-VCS-Committer: robbat2 X-VCS-Committer-Name: Robin H. Johnson X-VCS-Revision: a8b0ba36853eea23c0e07bcc680bdbe877dcd68e X-VCS-Branch: master Date: Thu, 30 Apr 2020 06:31:32 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 56828a40-3f1a-43d2-ab11-2e7682a61363 X-Archives-Hash: b9be3de3726e83f46a924bf320b62a00 commit: a8b0ba36853eea23c0e07bcc680bdbe877dcd68e Author: Robin H. Johnson gentoo org> AuthorDate: Thu Apr 30 06:29:53 2020 +0000 Commit: Robin H. Johnson gentoo org> CommitDate: Thu Apr 30 06:29:53 2020 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-mirrorstats.git/commit/?id=a8b0ba36 probe-mirmon: use libcurl instead of exec wget Signed-off-by: Robin H. Johnson gentoo.org> probe-mirmon | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/probe-mirmon b/probe-mirmon index 8c57691..6d67fbf 100755 --- a/probe-mirmon +++ b/probe-mirmon @@ -21,6 +21,7 @@ use strict; use warnings; use Date::Parse (); # dev-perl/TimeDate use File::Tempdir; # dev-perl/File-Tempdir +use WWW::Curl::Easy; sub main { my ( $timeout, $url ) = @_; @@ -28,10 +29,45 @@ sub main { handle_rsync( $timeout, $url ); } else { - handle_wget( $timeout, $url ); + handle_libcurl( $timeout, $url ); } } +sub handle_libcurl { + my ( $timeout, $url ) = @_; + + my $curl = WWW::Curl::Easy->new; + + $curl->setopt(CURLOPT_HEADER, 0); + $curl->setopt(CURLOPT_CONNECTTIMEOUT, $timeout); + $curl->setopt(CURLOPT_TIMEOUT, $timeout); + $curl->setopt(CURLOPT_FTP_USE_EPSV, 1); + $curl->setopt(CURLOPT_URL, $url); + + # A filehandle, reference to a scalar or reference to a typeglob can be used here. + my $response_body; + $curl->setopt(CURLOPT_WRITEDATA,\$response_body); + + # Starts the actual request + my $retcode = $curl->perform; + + # Looking at the results... + if ($retcode == 0) { + #print("Transfer went ok\n"); + my $response_code = $curl->getinfo(CURLINFO_HTTP_CODE); + # judge result and next action based on $response_code + #print("Received response: $response_code $response_body\n"); + chomp $response_body; + #print("s='$response_body'\n"); + print(munge_date($response_body), "\n"); + } else { + # Error code, type of error, error message + #print("An error happened: $retcode ".$curl->strerror($retcode)." ".$curl->errbuf."\n"); + exit 800; + } + +} + sub handle_wget { my ( $timeout, $url ) = @_; # TODO: replace this with native HTTP