summaryrefslogtreecommitdiff
path: root/methods/connect.h
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2017-06-28 10:55:08 +0200
committerJulian Andres Klode <jak@debian.org>2017-06-28 15:52:38 +0200
commit5666084ecfe140aaa3f89388de557c2f875b4244 (patch)
tree49bae823b0473e72d58db10033de2329a71d4c80 /methods/connect.h
parentb4afd84a59578965120f175b410ea325d60bcb58 (diff)
methods: connect: Switch from int fds to new MethodFd
Use std::unique_ptr<MethodFd> everywhere we used an integer-based file descriptor before. This allows us to implement stuff like TLS support easily. Gbp-Dch: ignore
Diffstat (limited to 'methods/connect.h')
-rw-r--r--methods/connect.h25
1 files changed, 24 insertions, 1 deletions
diff --git a/methods/connect.h b/methods/connect.h
index 44473a07c..5eae77d09 100644
--- a/methods/connect.h
+++ b/methods/connect.h
@@ -10,12 +10,35 @@
#ifndef CONNECT_H
#define CONNECT_H
+#include <memory>
+#include <stddef.h>
#include <string>
class aptMethod;
+/**
+ * \brief Small representation of a file descriptor for network traffic.
+ *
+ * This provides support for TLS, SOCKS, and HTTP CONNECT proxies.
+ */
+struct MethodFd
+{
+ /// \brief Returns -1 for unusable, or an fd to select() on otherwise
+ virtual int Fd() = 0;
+ /// \brief Should behave like read(2)
+ virtual ssize_t Read(void *buf, size_t count) = 0;
+ /// \brief Should behave like write(2)
+ virtual ssize_t Write(void *buf, size_t count) = 0;
+ /// \brief Closes the file descriptor. Can be called multiple times.
+ virtual int Close() = 0;
+ /// \brief Destructor
+ virtual ~MethodFd(){};
+ /// \brief Construct a MethodFd from a UNIX file descriptor
+ static std::unique_ptr<MethodFd> FromFd(int iFd);
+};
+
bool Connect(std::string To, int Port, const char *Service, int DefPort,
- int &Fd, unsigned long TimeOut, aptMethod *Owner);
+ std::unique_ptr<MethodFd> &Fd, unsigned long TimeOut, aptMethod *Owner);
void RotateDNS();