xrootd
XrdTpcState.hh
Go to the documentation of this file.
1
7#include <memory>
8#include <vector>
9
10// Forward dec'ls
11class XrdSfsFile;
12class XrdHttpExtReq;
13typedef void CURL;
14struct curl_slist;
15
16namespace TPC {
17class Stream;
18
19class State {
20public:
21
23 m_push(true),
24 m_recv_status_line(false),
25 m_recv_all_headers(false),
26 m_offset(0),
28 m_status_code(-1),
29 m_error_code(0),
31 m_stream(NULL),
32 m_curl(NULL),
33 m_headers(NULL)
34 {}
35
36 // Note that we are "borrowing" a reference to the curl handle;
37 // it is not owned / freed by the State object. However, we use it
38 // as if there's only one handle per State.
39 State (off_t start_offset, Stream &stream, CURL *curl, bool push) :
40 m_push(push),
41 m_recv_status_line(false),
42 m_recv_all_headers(false),
43 m_offset(0),
44 m_start_offset(start_offset),
45 m_status_code(-1),
46 m_error_code(0),
48 m_stream(&stream),
49 m_curl(curl),
50 m_headers(NULL)
51 {
52 InstallHandlers(curl);
53 }
54
56
57 void SetTransferParameters(off_t offset, size_t size);
58
60
61 off_t BytesTransferred() const {return m_offset;}
62
63 off_t GetContentLength() const {return m_content_length;}
64
65 int GetErrorCode() const {return m_error_code;}
66
67 int GetStatusCode() const {return m_status_code;}
68
69 std::string GetErrorMessage() const {return m_error_buf;}
70
72
73 CURL *GetHandle() const {return m_curl;}
74
75 int AvailableBuffers() const;
76
77 void DumpBuffers() const;
78
79 // Returns true if at least one byte of the response has been received,
80 // but not the entire contents of the response.
82
83 // Duplicate the current state; all settings are copied over, but those
84 // related to the transient state are reset as if from a constructor.
86
87 // Move the contents of a State object. To be replaced by a move
88 // constructor once C++11 is allowed in XRootD.
89 void Move (State &other);
90
91 // Flush and finalize a transfer state. Eventually calls close() on the underlying
92 // file handle, which should hopefully synchronize the file metadata across
93 // all readers (even other load-balanced servers on the same distributed file
94 // system).
95 //
96 // Returns true on success; false otherwise. Failures can happen, for example, if
97 // not all buffers have been reordered by the underlying stream.
98 bool Finalize();
99
100 // Flush the data in memory to disk, even if it may cause unaligned or short
101 // writes. Typically, only done while shutting down the transfer (note some
102 // backends may be unable to handle unaligned writes unless it's the last write).
103 int Flush();
104
105 // Retrieve the description of the remote connection; is of the form:
106 // tcp:129.93.3.4:1234
107 // tcp:[2600:900:6:1301:268a:7ff:fef6:a590]:2345
108 // This is meant to facilitate the monitoring via the performance markers.
110
111private:
113
114 State(const State&);
115 // Add back once C++11 is available
116 //State(State &&) noexcept;
117
118 // libcurl callback functions, along with the corresponding class methods.
119 static size_t HeaderCB(char *buffer, size_t size, size_t nitems,
120 void *userdata);
121 int Header(const std::string &header);
122 static size_t WriteCB(void *buffer, size_t size, size_t nitems, void *userdata);
123 ssize_t Write(char *buffer, size_t size);
124 static size_t ReadCB(void *buffer, size_t size, size_t nitems, void *userdata);
125 int Read(char *buffer, size_t size);
126
127 bool m_push; // whether we are transferring in "push-mode"
128 bool m_recv_status_line; // whether we have received a status line in the response from the remote host.
129 bool m_recv_all_headers; // true if we have seen the end of headers.
130 off_t m_offset; // number of bytes we have received.
131 off_t m_start_offset; // offset where we started in the file.
132 int m_status_code; // status code from HTTP response.
133 int m_error_code; // error code from underlying stream operations.
134 off_t m_content_length; // value of Content-Length header, if we received one.
135 Stream *m_stream; // stream corresponding to this transfer.
136 CURL *m_curl; // libcurl handle
137 struct curl_slist *m_headers; // any headers we set as part of the libcurl request.
138 std::vector<std::string> m_headers_copy; // Copies of custom headers.
139 std::string m_resp_protocol; // Response protocol in the HTTP status line.
140 std::string m_error_buf; // Any error associated with a response.
141};
142
143};
void CURL
Definition: XrdTpcState.hh:12
Definition: XrdTpcState.hh:19
off_t m_offset
Definition: XrdTpcState.hh:130
int m_status_code
Definition: XrdTpcState.hh:132
State * Duplicate()
static size_t WriteCB(void *buffer, size_t size, size_t nitems, void *userdata)
bool m_recv_status_line
Definition: XrdTpcState.hh:128
State(const State &)
std::string m_resp_protocol
Definition: XrdTpcState.hh:139
void SetTransferParameters(off_t offset, size_t size)
bool m_push
Definition: XrdTpcState.hh:127
bool m_recv_all_headers
Definition: XrdTpcState.hh:129
int m_error_code
Definition: XrdTpcState.hh:133
int GetStatusCode() const
Definition: XrdTpcState.hh:67
void Move(State &other)
bool Finalize()
CURL * GetHandle() const
Definition: XrdTpcState.hh:73
int Read(char *buffer, size_t size)
std::string m_error_buf
Definition: XrdTpcState.hh:140
State(off_t start_offset, Stream &stream, CURL *curl, bool push)
Definition: XrdTpcState.hh:39
CURL * m_curl
Definition: XrdTpcState.hh:136
off_t BytesTransferred() const
Definition: XrdTpcState.hh:61
bool BodyTransferInProgress() const
Definition: XrdTpcState.hh:81
struct curl_slist * m_headers
Definition: XrdTpcState.hh:137
int AvailableBuffers() const
void DumpBuffers() const
int GetErrorCode() const
Definition: XrdTpcState.hh:65
Stream * m_stream
Definition: XrdTpcState.hh:135
std::string GetConnectionDescription()
off_t m_content_length
Definition: XrdTpcState.hh:134
std::vector< std::string > m_headers_copy
Definition: XrdTpcState.hh:138
State()
Definition: XrdTpcState.hh:22
std::string GetErrorMessage() const
Definition: XrdTpcState.hh:69
off_t m_start_offset
Definition: XrdTpcState.hh:131
void CopyHeaders(XrdHttpExtReq &req)
off_t GetContentLength() const
Definition: XrdTpcState.hh:63
int Header(const std::string &header)
static size_t ReadCB(void *buffer, size_t size, size_t nitems, void *userdata)
static size_t HeaderCB(char *buffer, size_t size, size_t nitems, void *userdata)
bool InstallHandlers(CURL *curl)
ssize_t Write(char *buffer, size_t size)
void ResetAfterRequest()
Definition: XrdTpcStream.hh:22
Definition: XrdHttpExtHandler.hh:45
Definition: XrdSfsInterface.hh:652
Definition: XrdTpcState.hh:16