blob: 99a22a5bf951cdaee3c5cbea34a0503856b7e8ce [file] [log] [blame]
Andreea Costinase45d54b2020-03-10 09:21:14 +01001// 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
15namespace system_proxy {
16
17// Frees the resources allocated by curl_easy_init.
18struct FreeCurlEasyhandle {
19 void operator()(CURL* ptr) const { curl_easy_cleanup(ptr); }
20};
21
22typedef 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.
26class 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_