simple-socket library 1.5.0
Loading...
Searching...
No Matches
SCTPSocket.h
1#ifndef NET_SCTPSocket_h__
2#define NET_SCTPSocket_h__
3
4#include "SocketHandle.h"
5#include "InternetSocket.h"
6
7#include <netinet/in.h>
8#include <netinet/sctp.h>
9#include <vector>
10
11namespace NET
12{
14 class SCTPSocket : public InternetSocket
15 {
16 public:
19
20 enum abortFlag
21 {
22 ABORT = SCTP_ABORT,
23 SHUTDOWN = SCTP_EOF,
24 KEEPALIVE = 0
25 };
26
27 enum switchAddressFlag
28 {
29 KEEP_PRIMARY = 0,
30 OVERRIDE_PRIMARY = SCTP_ADDR_OVER
31 };
32
33 enum receiveFlag
34 {
35 };
36
37 SCTPSocket( uint16_t numOutStreams = 10, uint16_t maxInStreams = 65535, uint16_t maxAttempts = 4,
38 uint16_t maxInitTimeout = 0 /* TODO */);
39
44 explicit SCTPSocket( Handle&& handle);
45
47 int bind( const std::vector<std::string>& localAddresses, unsigned short localPort = 0);
48
50 int connect( const std::vector<std::string>& foreignAddresses, unsigned short foreignPort = 0);
51
52 int state() const;
53 int notAckedData() const;
54 int pendingData() const;
55 unsigned inStreams() const;
56 unsigned outStreams() const;
57 unsigned fragmentationPoint() const;
58 std::string primaryAddress() const;
59
61 int send( const void* data, size_t length, uint16_t stream, unsigned ttl = 0, unsigned context = 0, unsigned ppid = 0,
62 abortFlag abort = KEEPALIVE, switchAddressFlag switchAddr = KEEP_PRIMARY);
63
64 int sendUnordered( const void* data, size_t length, uint16_t stream, unsigned ttl = 0, unsigned context = 0,
65 unsigned ppid = 0, abortFlag abort = KEEPALIVE, switchAddressFlag switchAddr = KEEP_PRIMARY);
66
68 int receive( void* data, size_t maxLen, uint16_t& stream);
69 int receive( void* data, size_t maxLen, uint16_t& stream, receiveFlag& flag);
70
72 int timedReceive( void* data, size_t maxLen, uint16_t& stream, int timeout);
73 int timedReceive( void* data, size_t maxLen, uint16_t& stream, receiveFlag& flag, int timeout);
74
77
78 Handle accept() const;
79 Handle timedAccept( int timeout) const;
80
81 protected:
82 void setInitValues( uint16_t ostr, uint16_t istr, uint16_t att, uint16_t time);
83
84 // IPv4 only for now!
85 AddressFamily m_family;
86 };
87
88} // namespace NET
89
90#endif // NET_SCTPSocket_h__
void bind(unsigned short localPort=0)
InternetSocket(int sockfd)
create socket from a SocketHandle returned by an accept() call
void connect(std::string_view foreignAddress, unsigned short foreignPort)
establish a connection with the given foreign address and port
SocketHandle< SCTPSocket > Handle
Handle for a new socket returned by accept().
Definition SCTPSocket.h:18
int timedReceive(void *buffer, size_t len, int timeout)
receive data from a bound socket, return after the given timespan
int accept() const
allows stream sockets to accept connections into Handles
void listen(int backlog=5)
listen for incoming connections
int send(const void *buffer, size_t len)
send data through a connected socket
int receive(void *buffer, size_t len)
receive data from a bound socket
A simple class to provide strict ownership of socket handles.