This repository has been archived by the owner on Sep 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
NfsConnection.h
80 lines (66 loc) · 1.73 KB
/
NfsConnection.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#pragma once
#include <sys/time.h>
#include <nfsc/libnfs.h>
#include <memory>
#include <mutex>
#include <thread>
#include "logger.h"
#include "ClientStats.h"
/// @brief NfsConnection represents an active connection to a NFS server.
///
/// This object includes the thread (ioLoop_) which handles I/O with the
/// server.
class NfsConnection {
public:
NfsConnection(std::shared_ptr<nfusr::Logger> logger,
std::shared_ptr<ClientStats> stats,
int timeoutMs);
~NfsConnection();
int open(std::shared_ptr<std::string> url);
int close();
void get() {
lock_.lock();
}
void put();
struct nfs_context* getNfsCtx() {
return ctx_;
}
std::shared_ptr<std::string> getUrl() const {
return url_;
}
/// @brief a user-friendy description of the connection, for debugging.
std::string const &describe() const {
return description_;
}
bool closed() const {
return closed_;
}
int getQueuedRequests() {
std::unique_lock<std::mutex> guard(lock_);
return nfs_queue_length(ctx_);
}
private:
void ioLoop();
int serviceConnection(int fd);
int makeWakeable();
std::shared_ptr<nfusr::Logger> logger_;
std::shared_ptr<ClientStats> stats_;
std::shared_ptr<std::string> url_;
std::mutex lock_;
struct nfs_context* ctx_;
int wake_fd_;
std::thread ioLoop_;
bool opened_;
bool closed_;
bool terminate_;
std::string description_;
int timeoutMs_;
};