1 /*===========================================================================
2 *
3 *                            PUBLIC DOMAIN NOTICE
4 *               National Center for Biotechnology Information
5 *
6 *  This software/database is a "United States Government Work" under the
7 *  terms of the United States Copyright Act.  It was written as part of
8 *  the author's official duties as a United States Government employee and
9 *  thus cannot be copyrighted.  This software/database is freely available
10 *  to the public for use. The National Library of Medicine and the U.S.
11 *  Government have not placed any restriction on its use or reproduction.
12 *
13 *  Although all reasonable efforts have been taken to ensure the accuracy
14 *  and reliability of the software and data, the NLM and the U.S.
15 *  Government do not and cannot warrant the performance or results that
16 *  may be obtained by using this software or data. The NLM and the U.S.
17 *  Government disclaim all warranties, express or implied, including
18 *  warranties of performance, merchantability or fitness for any particular
19 *  purpose.
20 *
21 *  Please cite the author in any work or product based on this material.
22 *
23 * ==============================================================================
24 *
25 */
26 
27 #ifndef _h_stable_http_file_priv_
28 #define _h_stable_http_file_priv_
29 
30 #define KFILE_IMPL KStableHttpFile
31 typedef struct KStableHttpFile KStableHttpFile;
32 #include <kfs/impl.h> /* KFile_v1 */
33 
34 #include <klib/data-buffer.h>
35 
36 #include <kns/manager.h> /* quitting_t */
37 
38 /*--------------------------------------------------------------------------
39  * KStableHttpFile: retry wrapper on KHttpFile
40  */
41 
42 /* retrier states */
43 typedef enum {
44     eRSJustRetry, /* just retry read */
45     eRSReopen,    /* reopen the underlying file */
46     eRSIncTO,     /* increase sleep between calls to retry */
47     eRSMax,
48 } ERetryState;
49 
50 struct KStableHttpFile
51 {
52     KFile dad;
53 
54     /************************************************************************/
55     /* readWaitMillis and totalReadWaitMillis HAVE TO BE FIRST RIGHT AFTER dad
56     TO BE ABLE TO GET IT FROM BOTH KHttpFile AND KStableHttpFile:
57     SEE stable-http-file.c : HttpFileGetReadTimeouts() */
58     int32_t readWaitMillis;
59     int32_t totalReadWaitMillis;
60     /************************************************************************/
61 
62     const struct KFile * file; /* underlying file */
63 
64     int32_t totalConnectWaitMillis;
65 
66     /* arguments to reopen the underlying file */
67     const struct KNSManager * mgr;
68     struct KStream * conn;
69     ver_t vers;
70     bool reliable;
71     bool need_env_token;
72     bool payRequired;
73     char * url;
74     KDataBuffer buf;
75 
76     bool live; /* there was a successfull read on the file */
77 
78     /* retrier properties */
79     bool _failed;       /* KStableHttpFile is in failed state */
80     KTime_t _tFailed;   /* timestamp when retry loop started */
81     ERetryState _state; /* retrier state */
82     uint32_t _sleepTO;
83 
84     quitting_t quitting;
85 };
86 
87 #endif
88