aboutsummaryrefslogtreecommitdiff
path: root/libbutl/curl.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-12-14 14:24:38 +0200
committerKaren Arutyunov <karen@codesynthesis.com>2017-12-15 13:38:33 +0300
commit53b4f58c78e21cbc442891c2ce2a2b99a32e47bc (patch)
treef2b892650367a44332d7a169ede8aa9e60e6a3c8 /libbutl/curl.cxx
parentceb8f4abba2cfc7ac51385fa59693c641151c8d2 (diff)
Add process::pipe struct, extend process API
Diffstat (limited to 'libbutl/curl.cxx')
-rw-r--r--libbutl/curl.cxx40
1 files changed, 28 insertions, 12 deletions
diff --git a/libbutl/curl.cxx b/libbutl/curl.cxx
index 5ff81ab..ee61d6d 100644
--- a/libbutl/curl.cxx
+++ b/libbutl/curl.cxx
@@ -8,6 +8,8 @@
// C includes.
+#include <cassert>
+
#ifndef __cpp_lib_modules
#include <string>
@@ -40,7 +42,7 @@ using namespace std;
namespace butl
{
- int curl::
+ process::pipe curl::
map_in (nullfd_t, method_proto mp, io_data& d)
{
switch (mp)
@@ -53,16 +55,18 @@ namespace butl
case http_get:
{
d.pipe.in = fdnull (); // /dev/null
- return d.pipe.in.get ();
+ return pipe (d.pipe);
}
}
- return -1;
+ assert (false); // Can't be here.
+ return pipe ();
}
- int curl::
+ process::pipe curl::
map_in (const path& f, method_proto mp, io_data& d)
{
+ pipe r;
switch (mp)
{
case ftp_put:
@@ -84,12 +88,17 @@ namespace butl
if (f.string () == "-")
{
d.pipe = fdopen_pipe (fdopen_mode::binary);
+ r = pipe (d.pipe);
+
out.open (move (d.pipe.out));
}
else
+ {
d.pipe.in = fdnull (); // /dev/null
+ r = pipe (d.pipe);
+ }
- return d.pipe.in.get ();
+ return r;
}
case ftp_get:
case http_get:
@@ -98,10 +107,11 @@ namespace butl
}
}
- return -1;
+ assert (false); // Can't be here.
+ return r;
}
- int curl::
+ process::pipe curl::
map_out (nullfd_t, method_proto mp, io_data& d)
{
switch (mp)
@@ -113,16 +123,18 @@ namespace butl
case http_post: // May or may not produce output.
{
d.pipe.out = fdnull ();
- return d.pipe.out.get (); // /dev/null
+ return pipe (d.pipe); // /dev/null
}
}
- return -1;
+ assert (false); // Can't be here.
+ return pipe ();
}
- int curl::
+ process::pipe curl::
map_out (const path& f, method_proto mp, io_data& d)
{
+ pipe r;
switch (mp)
{
case ftp_get:
@@ -134,6 +146,8 @@ namespace butl
// Note: no need for any options, curl writes to stdout by default.
//
d.pipe = fdopen_pipe (fdopen_mode::binary);
+ r = pipe (d.pipe);
+
in.open (move (d.pipe.in));
}
else
@@ -141,9 +155,10 @@ namespace butl
d.options.push_back ("-o");
d.options.push_back (f.string ().c_str ());
d.pipe.out = fdnull (); // /dev/null
+ r = pipe (d.pipe);
}
- return d.pipe.out.get ();
+ return r;
}
case ftp_put:
{
@@ -151,7 +166,8 @@ namespace butl
}
}
- return -1;
+ assert (false); // Can't be here.
+ return r;
}
curl::method_proto curl::