svn cleanup
[anytun.git] / Sockets / SctpSocket.h
blob12e72a0624b8da855e85b42f43e9709bc009b6c8
1 /**
2 ** \file SctpSocket.h
3 ** \date 2006-09-04
4 ** \author grymse@alhem.net
5 **/
6 /*
7 Copyright (C) 2007 Anders Hedstrom
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.
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.
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.
23 #ifndef _SOCKETS_SctpSocket_H
24 #define _SOCKETS_SctpSocket_H
25 #include "sockets-config.h"
27 #include <map>
28 #include "StreamSocket.h"
29 #ifdef USE_SCTP
30 #include <netinet/sctp.h>
32 #ifdef SOCKETS_NAMESPACE
33 namespace SOCKETS_NAMESPACE {
34 #endif
36 #define SCTP_BUFSIZE_READ 16400
38 class SocketAddress;
41 class SctpSocket : public StreamSocket
43 public:
44 /** SctpSocket constructor.
45 \param h Owner
46 \param type SCTP_STREAM or SCTP_SEQPACKET */
47 SctpSocket(ISocketHandler& h,int type);
48 ~SctpSocket();
50 /** bind() */
51 int Bind(const std::string&,port_t);
52 int Bind(SocketAddress&);
53 /** sctp_bindx() */
54 int AddAddress(const std::string&,port_t);
55 int AddAddress(SocketAddress&);
56 /** sctp_bindx() */
57 int RemoveAddress(const std::string&,port_t);
58 int RemoveAddress(SocketAddress&);
60 /** connect() */
61 int Open(const std::string&,port_t);
62 int Open(SocketAddress&);
64 /** Connect timeout callback. */
65 void OnConnectTimeout();
66 #ifdef _WIN32
67 /** Connection failed reported as exception on win32 */
68 void OnException();
69 #endif
71 #ifndef SOLARIS
72 /** sctp_connectx() */
73 int AddConnection(const std::string&,port_t);
74 int AddConnection(SocketAddress&);
75 #endif
77 /** Get peer addresses of an association. */
78 int getpaddrs(sctp_assoc_t id,std::list<std::string>&);
79 /** Get all bound addresses of an association. */
80 int getladdrs(sctp_assoc_t id,std::list<std::string>&);
82 /** sctp_peeloff */
83 int PeelOff(sctp_assoc_t id);
85 /** recvmsg callback */
86 virtual void OnReceiveMessage(const char *buf,size_t sz,struct sockaddr *sa,socklen_t sa_len,struct sctp_sndrcvinfo *sinfo,int msg_flags) = 0;
88 void OnOptions(int,int,int,SOCKET) {}
90 virtual int Protocol();
92 protected:
93 SctpSocket(const SctpSocket& s) : StreamSocket(s) {}
94 void OnRead();
95 void OnWrite();
97 private:
98 SctpSocket& operator=(const SctpSocket& s) { return *this; }
99 int m_type; ///< SCTP_STREAM or SCTP_SEQPACKET
100 char *m_buf; ///< Temporary receive buffer
104 #ifdef SOCKETS_NAMESPACE
105 } // namespace SOCKETS_NAMESPACE
106 #endif
108 #endif // USE_SCTP
109 #endif // _SOCKETS_SctpSocket_H