-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
session.h
77 lines (59 loc) · 2.99 KB
/
session.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
#pragma once
#include <cstdint>
#include <map>
#include <optional>
#include "com.h"
#include "gen.h"
#include "iscsi.h"
class iscsi_pdu_scsi_cmd;
class session
{
private:
com_client *const connected_to { nullptr }; // e.g. for retrieving the local address
const std::string target_name;
uint32_t data_sn_itt { 0 }; // itt == initiator transfer tag
uint32_t data_sn { 0 };
uint32_t block_size { 0 };
struct {
uint64_t bytes_rx { 0 };
uint64_t bytes_tx { 0 };
unsigned error_count { 0 };
io_stats_t is;
} statistics;
uint32_t max_seg_len { MAX_DATA_SEGMENT_SIZE };
const bool allow_digest { false };
bool header_digest { false };
bool data_digest { false };
std::optional<uint32_t> ack_interval;
std::map<uint32_t, r2t_session *> r2t_sessions; // r2t sessions
public:
session(com_client *const connected_to, const std::string & target_name, const bool allow_digest);
virtual ~session();
std::string get_target_name () const { return target_name; }
std::string get_local_address() const { return connected_to->get_local_address(); }
std::string get_endpoint_name() const { return connected_to->get_endpoint_name(); }
void set_header_digest(const bool v) { header_digest = v; }
void set_data_digest (const bool v) { data_digest = v; }
bool get_header_digest() const { return header_digest & allow_digest; }
bool get_data_digest () const { return data_digest & allow_digest; }
void set_max_seg_len(const uint32_t v) { max_seg_len = v; }
uint32_t get_max_seg_len() const { return max_seg_len; }
void add_bytes_rx(const uint64_t n) { statistics.bytes_rx += n; }
uint64_t get_bytes_rx() const { return statistics.bytes_rx; }
void reset_bytes_rx() { statistics.bytes_rx = 0; }
void add_bytes_tx(const uint64_t n) { statistics.bytes_tx += n; }
uint64_t get_bytes_tx() const { return statistics.bytes_tx; }
void reset_bytes_tx() { statistics.bytes_tx = 0; }
io_stats_t *get_io_stats() { return &statistics.is; }
void reset_io_stats() { statistics.is.reset(); }
void inc_error_count() { statistics.error_count++; }
unsigned get_error_count() const { return statistics.error_count; }
uint32_t get_inc_datasn(const uint32_t itt);
void set_block_size(const uint32_t block_size_in) { block_size = block_size_in; }
uint32_t get_block_size() const { return block_size; }
void set_ack_interval(const uint32_t bytes) { ack_interval = bytes; }
std::optional<uint32_t> get_ack_interval() { return ack_interval; }
void init_r2t_session(const r2t_session & rs, const bool fua, iscsi_pdu_scsi_cmd *const pdu, const uint32_t transfer_tag);
r2t_session *get_r2t_sesion(const uint32_t ttt);
void remove_r2t_session(const uint32_t ttt);
};