-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
session.cpp
70 lines (57 loc) · 1.79 KB
/
session.cpp
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
#include "iscsi-pdu.h"
#include "log.h"
#include "random.h"
#include "session.h"
session::session(com_client *const connected_to, const std::string & target_name, const bool allow_digest):
connected_to(connected_to),
target_name(target_name),
allow_digest(allow_digest)
{
}
session::~session()
{
for(auto & it: r2t_sessions) {
delete [] it.second->PDU_initiator.data;
delete it.second;
}
}
uint32_t session::get_inc_datasn(const uint32_t data_sn_itt)
{
if (data_sn_itt == this->data_sn_itt)
return data_sn++;
this->data_sn_itt = data_sn_itt;
this->data_sn = 0;
return data_sn++;
}
void session::init_r2t_session(const r2t_session & rs, const bool fua, iscsi_pdu_scsi_cmd *const pdu, const uint32_t transfer_tag)
{
auto it = r2t_sessions.find(transfer_tag);
if (it != r2t_sessions.end())
return;
r2t_session *copy = new r2t_session;
*copy = rs;
copy->fua = fua;
copy->PDU_initiator = pdu->get_raw();
DOLOG(logging::ll_debug, "session::init_r2t_session", get_endpoint_name(), "register transfer tag %08x", transfer_tag);
r2t_sessions.insert({ transfer_tag, copy });
}
r2t_session *session::get_r2t_sesion(const uint32_t ttt)
{
DOLOG(logging::ll_debug, "session::get_r2t_session", get_endpoint_name(), "get TTT %08x", ttt);
auto it = r2t_sessions.find(ttt);
if (it == r2t_sessions.end())
return nullptr;
return it->second;
}
void session::remove_r2t_session(const uint32_t ttt)
{
auto it = r2t_sessions.find(ttt);
if (it == r2t_sessions.end())
DOLOG(logging::ll_error, "session::remove_r2t_session", get_endpoint_name(), "unexpected TTT (%x)", ttt);
else {
DOLOG(logging::ll_debug, "session::remove_r2t_session", get_endpoint_name(), "removing TTT %x", ttt);
delete [] it->second->PDU_initiator.data;
delete it->second;
r2t_sessions.erase(it);
}
}