-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
sctpthread.h
81 lines (69 loc) · 2.11 KB
/
sctpthread.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
81
/*
* This file is part of cannelloni, a SocketCAN over Ethernet tunnel.
*
* Copyright (C) 2014-2017 Maximilian Güntner <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#pragma once
#include "udpthread.h"
#include <netinet/sctp.h>
#include <sys/socket.h>
namespace cannelloni {
enum SCTPThreadRole {SCTP_SERVER, SCTP_CLIENT};
struct SCTPThreadParams {
struct sockaddr_storage &remoteAddr;
struct sockaddr_storage &localAddr;
int addressFamily;
bool sortFrames;
bool checkPeer;
/*
* This setting does not map 1:1 to how MTU works with UDP
* as SCTP will do a path MTU discovery on its own and chunk /
* reassemble data
*/
uint16_t linkMtuSize;
SCTPThreadRole role;
public:
UDPThreadParams toUDPThreadParams() const {
return UDPThreadParams{
.remoteAddr = remoteAddr,
.localAddr = localAddr,
.addressFamily = addressFamily,
.sortFrames = sortFrames,
.checkPeer = checkPeer,
.linkMtuSize = linkMtuSize,
};
}
};
class SCTPThread : public UDPThread {
public:
SCTPThread(const struct debugOptions_t &debugOptions,
const struct SCTPThreadParams ¶ms);
virtual int start();
virtual void run();
virtual void transmitFrame(canfd_frame *frame);
protected:
virtual ssize_t sendBuffer(uint8_t *buffer, uint16_t len);
private:
bool isConnected();
private:
sctp_assoc_t m_assoc_id;
SCTPThreadRole m_role;
bool m_checkPeerConnect;
bool m_connected;
int m_serverSocket;
};
}