XRootD
Loading...
Searching...
No Matches
XrdClHttpFactory.hh
Go to the documentation of this file.
1/******************************************************************************/
2/* Copyright (C) 2025, Pelican Project, Morgridge Institute for Research */
3/* */
4/* This file is part of the XrdClHttp client plugin for XRootD. */
5/* */
6/* XRootD is free software: you can redistribute it and/or modify it under */
7/* the terms of the GNU Lesser General Public License as published by the */
8/* Free Software Foundation, either version 3 of the License, or (at your */
9/* option) any later version. */
10/* */
11/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
12/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
13/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
14/* License for more details. */
15/* */
16/* The copyright holder's institutional names and contributor's names may not */
17/* be used to endorse or promote products derived from this software without */
18/* specific prior written permission of the institution or contributor. */
19/******************************************************************************/
20
21#ifndef XRDCLHTTP_FACTORY_HH
22#define XRDCLHTTP_FACTORY_HH
23
25
26#include <condition_variable>
27#include <memory>
28#include <mutex>
29#include <string>
30#include <time.h>
31#include <thread>
32#include <vector>
33
34namespace XrdCl {
35 class Log;
36}
37
38namespace XrdClHttp {
39
40class CurlOperation;
41class CurlWorker;
42class HandlerQueue;
43
44class Factory final : public XrdCl::PlugInFactory {
45public:
47
48 virtual XrdCl::FilePlugIn *CreateFile(const std::string &url) override;
49 virtual XrdCl::FileSystemPlugIn *CreateFileSystem(const std::string &url) override;
50
51 // Get the header timeout value, taking into consideration the provided command timeout, and XrdCl's default values
52 static struct timespec GetHeaderTimeoutWithDefault(time_t oper_timeout);
53
54 // Hand off a given curl operation to the factory's worker pool.
55 void Produce(std::unique_ptr<XrdClHttp::CurlOperation> operation);
56
57private:
58 // Actual initialization of the factory. Only done when the first filesystem/file
59 // is created to allow a parent process to fork first.
60 void Initialize();
61
62 // Set the various X509 credential variables in the default environment.
63 void SetupX509();
64
65 // Monitoring loop for XrdClHttp statistics
66 void Monitor();
67
68 // Invoked by the destructor of a static member, to know when the
69 // the library is shutting down or is unloaded from the process.
70 static void Shutdown();
71
72 static bool m_initialized;
73 static std::shared_ptr<XrdClHttp::HandlerQueue> m_queue;
74 static XrdCl::Log *m_log;
75 const static unsigned m_poll_threads{8};
76 static std::once_flag m_init_once;
77 // Location for the client to dump its runtime statistics.
78 static std::string m_stats_location;
79
80 // Start time of the factory
81 static std::chrono::system_clock::time_point m_start;
82
83 // Mutex for managing the shutdown of the background thread
84 static std::mutex m_shutdown_lock;
85 // The background thread
86 static std::thread m_monitor_tid;
87 // Condition variable managing the requested shutdown of the background thread.
88 static std::condition_variable m_shutdown_requested_cv;
89 // Flag indicating that a shutdown was requested.
90 static bool m_shutdown_requested;
91 // shutdown trigger
92 static struct shutdown_s {
93 ~shutdown_s() { Shutdown(); }
94 } m_shutdowns;
95};
96
97}
98
99#endif // XRDCLHTTP_FACTORY_HH
void Produce(std::unique_ptr< XrdClHttp::CurlOperation > operation)
virtual XrdCl::FileSystemPlugIn * CreateFileSystem(const std::string &url) override
Create a file system plug-in for the given URL.
virtual XrdCl::FilePlugIn * CreateFile(const std::string &url) override
Create a file plug-in for the given URL.
static struct timespec GetHeaderTimeoutWithDefault(time_t oper_timeout)
An interface for file plug-ins.
An interface for file plug-ins.
Handle diagnostics.
Definition XrdClLog.hh:101