4 ** \author grymse@alhem.net
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"
28 #include "StreamSocket.h"
30 #include <netinet/sctp.h>
32 #ifdef SOCKETS_NAMESPACE
33 namespace SOCKETS_NAMESPACE
{
36 #define SCTP_BUFSIZE_READ 16400
41 class SctpSocket
: public StreamSocket
44 /** SctpSocket constructor.
46 \param type SCTP_STREAM or SCTP_SEQPACKET */
47 SctpSocket(ISocketHandler
& h
,int type
);
51 int Bind(const std::string
&,port_t
);
52 int Bind(SocketAddress
&);
54 int AddAddress(const std::string
&,port_t
);
55 int AddAddress(SocketAddress
&);
57 int RemoveAddress(const std::string
&,port_t
);
58 int RemoveAddress(SocketAddress
&);
61 int Open(const std::string
&,port_t
);
62 int Open(SocketAddress
&);
64 /** Connect timeout callback. */
65 void OnConnectTimeout();
67 /** Connection failed reported as exception on win32 */
72 /** sctp_connectx() */
73 int AddConnection(const std::string
&,port_t
);
74 int AddConnection(SocketAddress
&);
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
>&);
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();
93 SctpSocket(const SctpSocket
& s
) : StreamSocket(s
) {}
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
109 #endif // _SOCKETS_SctpSocket_H