1 | /** |
---|
2 | ** \file SctpSocket.h |
---|
3 | ** \date 2006-09-04 |
---|
4 | ** \author grymse@alhem.net |
---|
5 | **/ |
---|
6 | /* |
---|
7 | Copyright (C) 2007 Anders Hedstrom |
---|
8 | |
---|
9 | This program is free software; you can redistribute it and/or |
---|
10 | modify it under the terms of the GNU General Public License |
---|
11 | as published by the Free Software Foundation; either version 2 |
---|
12 | of the License, or (at your option) any later version. |
---|
13 | |
---|
14 | This program is distributed in the hope that it will be useful, |
---|
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | GNU General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU General Public License |
---|
20 | along with this program; if not, write to the Free Software |
---|
21 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
22 | */ |
---|
23 | #ifndef _SOCKETS_SctpSocket_H |
---|
24 | #define _SOCKETS_SctpSocket_H |
---|
25 | #include "sockets-config.h" |
---|
26 | |
---|
27 | #include "StreamSocket.h" |
---|
28 | #ifdef USE_SCTP |
---|
29 | #include <netinet/sctp.h> |
---|
30 | |
---|
31 | #ifdef SOCKETS_NAMESPACE |
---|
32 | namespace SOCKETS_NAMESPACE { |
---|
33 | #endif |
---|
34 | |
---|
35 | #define SCTP_BUFSIZE_READ 16400 |
---|
36 | |
---|
37 | class SocketAddress; |
---|
38 | |
---|
39 | |
---|
40 | class SctpSocket : public StreamSocket |
---|
41 | { |
---|
42 | public: |
---|
43 | /** SctpSocket constructor. |
---|
44 | \param h Owner |
---|
45 | \param type SCTP_STREAM or SCTP_SEQPACKET */ |
---|
46 | SctpSocket(ISocketHandler& h,int type); |
---|
47 | ~SctpSocket(); |
---|
48 | |
---|
49 | /** bind() */ |
---|
50 | int Bind(const std::string&,port_t); |
---|
51 | int Bind(SocketAddress&); |
---|
52 | /** sctp_bindx() */ |
---|
53 | int AddAddress(const std::string&,port_t); |
---|
54 | int AddAddress(SocketAddress&); |
---|
55 | /** sctp_bindx() */ |
---|
56 | int RemoveAddress(const std::string&,port_t); |
---|
57 | int RemoveAddress(SocketAddress&); |
---|
58 | |
---|
59 | /** connect() */ |
---|
60 | int Open(const std::string&,port_t); |
---|
61 | int Open(SocketAddress&); |
---|
62 | |
---|
63 | /** Connect timeout callback. */ |
---|
64 | void OnConnectTimeout(); |
---|
65 | #ifdef _WIN32 |
---|
66 | /** Connection failed reported as exception on win32 */ |
---|
67 | void OnException(); |
---|
68 | #endif |
---|
69 | |
---|
70 | #ifndef SOLARIS |
---|
71 | /** sctp_connectx() */ |
---|
72 | int AddConnection(const std::string&,port_t); |
---|
73 | int AddConnection(SocketAddress&); |
---|
74 | #endif |
---|
75 | |
---|
76 | /** Get peer addresses of an association. */ |
---|
77 | int getpaddrs(sctp_assoc_t id,std::list<std::string>&); |
---|
78 | /** Get all bound addresses of an association. */ |
---|
79 | int getladdrs(sctp_assoc_t id,std::list<std::string>&); |
---|
80 | |
---|
81 | /** sctp_peeloff */ |
---|
82 | int PeelOff(sctp_assoc_t id); |
---|
83 | |
---|
84 | /** recvmsg callback */ |
---|
85 | virtual void OnReceiveMessage(const char *buf,size_t sz,struct sockaddr *sa,socklen_t sa_len,struct sctp_sndrcvinfo *sinfo,int msg_flags) = 0; |
---|
86 | |
---|
87 | void OnOptions(int,int,int,SOCKET) {} |
---|
88 | |
---|
89 | virtual int Protocol(); |
---|
90 | |
---|
91 | protected: |
---|
92 | SctpSocket(const SctpSocket& s) : StreamSocket(s) {} |
---|
93 | void OnRead(); |
---|
94 | void OnWrite(); |
---|
95 | |
---|
96 | private: |
---|
97 | SctpSocket& operator=(const SctpSocket& s) { return *this; } |
---|
98 | int m_type; ///< SCTP_STREAM or SCTP_SEQPACKET |
---|
99 | char *m_buf; ///< Temporary receive buffer |
---|
100 | }; |
---|
101 | |
---|
102 | |
---|
103 | #ifdef SOCKETS_NAMESPACE |
---|
104 | } // namespace SOCKETS_NAMESPACE |
---|
105 | #endif |
---|
106 | |
---|
107 | #endif // USE_SCTP |
---|
108 | #endif // _SOCKETS_SctpSocket_H |
---|
109 | |
---|