1//
2// SecureServerSocket.cpp
3//
4// Library: NetSSL_OpenSSL
5// Package: SSLSockets
6// Module: SecureServerSocket
7//
8// Copyright (c) 2006-2009, Applied Informatics Software Engineering GmbH.
9// and Contributors.
10//
11// SPDX-License-Identifier: BSL-1.0
12//
13
14
15#include "Poco/Net/SecureServerSocket.h"
16#include "Poco/Net/SecureServerSocketImpl.h"
17#include "Poco/Net/SecureStreamSocket.h"
18#include "Poco/Net/SSLManager.h"
19#include "Poco/Exception.h"
20
21
22using Poco::InvalidArgumentException;
23
24
25namespace Poco {
26namespace Net {
27
28
29SecureServerSocket::SecureServerSocket():
30 ServerSocket(new SecureServerSocketImpl(SSLManager::instance().defaultServerContext()), true)
31{
32}
33
34
35SecureServerSocket::SecureServerSocket(Context::Ptr pContext):
36 ServerSocket(new SecureServerSocketImpl(pContext), true)
37{
38}
39
40
41SecureServerSocket::SecureServerSocket(const Socket& socket):
42 ServerSocket(socket)
43{
44 if (!dynamic_cast<SecureServerSocketImpl*>(impl()))
45 throw InvalidArgumentException("Cannot assign incompatible socket");
46}
47
48
49SecureServerSocket::SecureServerSocket(const SocketAddress& address, int backlog):
50 ServerSocket(new SecureServerSocketImpl(SSLManager::instance().defaultServerContext()), true)
51{
52 impl()->bind(address, true);
53 impl()->listen(backlog);
54}
55
56
57SecureServerSocket::SecureServerSocket(const SocketAddress& address, int backlog, Context::Ptr pContext):
58 ServerSocket(new SecureServerSocketImpl(pContext), true)
59{
60 impl()->bind(address, true);
61 impl()->listen(backlog);
62}
63
64
65SecureServerSocket::SecureServerSocket(Poco::UInt16 port, int backlog):
66 ServerSocket(new SecureServerSocketImpl(SSLManager::instance().defaultServerContext()), true)
67{
68 IPAddress wildcardAddr;
69 SocketAddress address(wildcardAddr, port);
70 impl()->bind(address, true);
71 impl()->listen(backlog);
72}
73
74SecureServerSocket::SecureServerSocket(Poco::UInt16 port, int backlog, Context::Ptr pContext):
75 ServerSocket(new SecureServerSocketImpl(pContext), true)
76{
77 IPAddress wildcardAddr;
78 SocketAddress address(wildcardAddr, port);
79 impl()->bind(address, true);
80 impl()->listen(backlog);
81}
82
83
84SecureServerSocket::~SecureServerSocket()
85{
86}
87
88
89SecureServerSocket& SecureServerSocket::operator = (const Socket& socket)
90{
91 if (&socket != this)
92 {
93 if (dynamic_cast<SecureServerSocketImpl*>(socket.impl()))
94 ServerSocket::operator = (socket);
95 else
96 throw InvalidArgumentException("Cannot assign incompatible socket");
97 }
98 return *this;
99}
100
101
102StreamSocket SecureServerSocket::acceptConnection(SocketAddress& clientAddr)
103{
104 return SecureStreamSocket(impl()->acceptConnection(clientAddr));
105}
106
107
108StreamSocket SecureServerSocket::acceptConnection()
109{
110 SocketAddress clientAddr;
111 return SecureStreamSocket(impl()->acceptConnection(clientAddr));
112}
113
114
115Context::Ptr SecureServerSocket::context() const
116{
117 return static_cast<SecureServerSocketImpl*>(impl())->context();
118}
119
120
121} } // namespace Poco::Net
122