1 | // |
2 | // DatagramSocket.cpp |
3 | // |
4 | // Library: Net |
5 | // Package: Sockets |
6 | // Module: DatagramSocket |
7 | // |
8 | // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. |
9 | // and Contributors. |
10 | // |
11 | // SPDX-License-Identifier: BSL-1.0 |
12 | // |
13 | |
14 | |
15 | #include "Poco/Net/DatagramSocket.h" |
16 | #include "Poco/Net/DatagramSocketImpl.h" |
17 | #include "Poco/Exception.h" |
18 | |
19 | |
20 | using Poco::InvalidArgumentException; |
21 | |
22 | |
23 | namespace Poco { |
24 | namespace Net { |
25 | |
26 | |
27 | DatagramSocket::DatagramSocket(): Socket(new DatagramSocketImpl) |
28 | { |
29 | } |
30 | |
31 | |
32 | DatagramSocket::DatagramSocket(SocketAddress::Family family): Socket(new DatagramSocketImpl(family)) |
33 | { |
34 | } |
35 | |
36 | |
37 | DatagramSocket::DatagramSocket(const SocketAddress& address, bool reuseAddress): Socket(new DatagramSocketImpl(address.family())) |
38 | { |
39 | bind(address, reuseAddress); |
40 | } |
41 | |
42 | |
43 | DatagramSocket::DatagramSocket(const Socket& socket): Socket(socket) |
44 | { |
45 | if (!dynamic_cast<DatagramSocketImpl*>(impl())) |
46 | throw InvalidArgumentException("Cannot assign incompatible socket" ); |
47 | } |
48 | |
49 | |
50 | DatagramSocket::DatagramSocket(SocketImpl* pImpl): Socket(pImpl) |
51 | { |
52 | if (!dynamic_cast<DatagramSocketImpl*>(impl())) |
53 | throw InvalidArgumentException("Cannot assign incompatible socket" ); |
54 | } |
55 | |
56 | |
57 | DatagramSocket::~DatagramSocket() |
58 | { |
59 | } |
60 | |
61 | |
62 | DatagramSocket& DatagramSocket::operator = (const Socket& socket) |
63 | { |
64 | if (dynamic_cast<DatagramSocketImpl*>(socket.impl())) |
65 | Socket::operator = (socket); |
66 | else |
67 | throw InvalidArgumentException("Cannot assign incompatible socket" ); |
68 | return *this; |
69 | } |
70 | |
71 | |
72 | void DatagramSocket::connect(const SocketAddress& address) |
73 | { |
74 | impl()->connect(address); |
75 | } |
76 | |
77 | |
78 | void DatagramSocket::bind(const SocketAddress& address, bool reuseAddress) |
79 | { |
80 | impl()->bind(address, reuseAddress); |
81 | } |
82 | |
83 | |
84 | void DatagramSocket::bind(const SocketAddress& address, bool reuseAddress, bool reusePort) |
85 | { |
86 | impl()->bind(address, reuseAddress, reusePort); |
87 | } |
88 | |
89 | |
90 | int DatagramSocket::sendBytes(const void* buffer, int length, int flags) |
91 | { |
92 | return impl()->sendBytes(buffer, length, flags); |
93 | } |
94 | |
95 | |
96 | int DatagramSocket::receiveBytes(void* buffer, int length, int flags) |
97 | { |
98 | return impl()->receiveBytes(buffer, length, flags); |
99 | } |
100 | |
101 | |
102 | int DatagramSocket::sendTo(const void* buffer, int length, const SocketAddress& address, int flags) |
103 | { |
104 | return impl()->sendTo(buffer, length, address, flags); |
105 | } |
106 | |
107 | |
108 | int DatagramSocket::receiveFrom(void* buffer, int length, SocketAddress& address, int flags) |
109 | { |
110 | return impl()->receiveFrom(buffer, length, address, flags); |
111 | } |
112 | |
113 | |
114 | } } // namespace Poco::Net |
115 | |