Andreea Costinas | e45d54b | 2020-03-10 09:21:14 +0100 | [diff] [blame^] | 1 | // Copyright 2020 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | #ifndef SYSTEM_PROXY_CURL_SOCKET_H_ |
| 5 | #define SYSTEM_PROXY_CURL_SOCKET_H_ |
| 6 | |
| 7 | #include <memory> |
| 8 | |
| 9 | #include <curl/curl.h> |
| 10 | #include <curl/easy.h> |
| 11 | |
| 12 | #include <arc/network/socket.h> |
| 13 | #include <base/files/scoped_file.h> |
| 14 | |
| 15 | namespace system_proxy { |
| 16 | |
| 17 | // Frees the resources allocated by curl_easy_init. |
| 18 | struct FreeCurlEasyhandle { |
| 19 | void operator()(CURL* ptr) const { curl_easy_cleanup(ptr); } |
| 20 | }; |
| 21 | |
| 22 | typedef std::unique_ptr<CURL, FreeCurlEasyhandle> ScopedCurlEasyhandle; |
| 23 | |
| 24 | // CurlSocket wraps a socket opened by curl in an arc_networkd::Socket object |
| 25 | // with an owned CURL handle. |
| 26 | class CurlSocket : public arc_networkd::Socket { |
| 27 | public: |
| 28 | CurlSocket(base::ScopedFD fd, ScopedCurlEasyhandle curl_easyhandle); |
| 29 | CurlSocket(const CurlSocket&) = delete; |
| 30 | CurlSocket& operator=(const CurlSocket&) = delete; |
| 31 | ~CurlSocket() override; |
| 32 | |
| 33 | private: |
| 34 | ScopedCurlEasyhandle curl_easyhandle_; |
| 35 | }; |
| 36 | } // namespace system_proxy |
| 37 | |
| 38 | #endif // SYSTEM_PROXY_CURL_SOCKET_H_ |