XRootD
XrdClHttpParseTimeout.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_PARSETIMEOUT_HH
22 #define XRDCLHTTP_PARSETIMEOUT_HH
23 
24 #include <string>
25 
26 #include <time.h>
27 
28 namespace XrdClHttp {
29 
30 // Parse a given string as a duration, returning the parsed value as a timespec.
31 //
32 // The implementation is based on the Go duration format which is a signed sequence of
33 // decimal numbers with a unit suffix.
34 //
35 // Examples:
36 // - 30ms
37 // - 1h5m
38 // Valid time units are "ns", "us", "ms", "s", "m", "h". Unlike go, UTF-8 for microsecond is not accepted
39 //
40 // If an invalid value is given, false is returned and the errmsg is set.
41 bool ParseTimeout(const std::string &duration, struct timespec &, std::string &errmsg);
42 
43 // Given a time value, marshal it to a string (based on the Go duration format)
44 //
45 // Result will be of the form XYZsABCms (or 1s500ms for 1.5 seconds).
46 std::string MarshalDuration(const struct timespec &timeout);
47 
48 }
49 
50 #endif // XRDCLHTTP_PARSETIMEOUT_HH
bool ParseTimeout(const std::string &duration, struct timespec &, std::string &errmsg)
std::string MarshalDuration(const struct timespec &timeout)