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
20using Poco::InvalidArgumentException;
21
22
23namespace Poco {
24namespace Net {
25
26
27DatagramSocket::DatagramSocket(): Socket(new DatagramSocketImpl)
28{
29}
30
31
32DatagramSocket::DatagramSocket(SocketAddress::Family family): Socket(new DatagramSocketImpl(family))
33{
34}
35
36
37DatagramSocket::DatagramSocket(const SocketAddress& address, bool reuseAddress): Socket(new DatagramSocketImpl(address.family()))
38{
39 bind(address, reuseAddress);
40}
41
42
43DatagramSocket::DatagramSocket(const Socket& socket): Socket(socket)
44{
45 if (!dynamic_cast<DatagramSocketImpl*>(impl()))
46 throw InvalidArgumentException("Cannot assign incompatible socket");
47}
48
49
50DatagramSocket::DatagramSocket(SocketImpl* pImpl): Socket(pImpl)
51{
52 if (!dynamic_cast<DatagramSocketImpl*>(impl()))
53 throw InvalidArgumentException("Cannot assign incompatible socket");
54}
55
56
57DatagramSocket::~DatagramSocket()
58{
59}
60
61
62DatagramSocket& 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
72void DatagramSocket::connect(const SocketAddress& address)
73{
74 impl()->connect(address);
75}
76
77
78void DatagramSocket::bind(const SocketAddress& address, bool reuseAddress)
79{
80 impl()->bind(address, reuseAddress);
81}
82
83
84void DatagramSocket::bind(const SocketAddress& address, bool reuseAddress, bool reusePort)
85{
86 impl()->bind(address, reuseAddress, reusePort);
87}
88
89
90int DatagramSocket::sendBytes(const void* buffer, int length, int flags)
91{
92 return impl()->sendBytes(buffer, length, flags);
93}
94
95
96int DatagramSocket::sendBytes(const SocketBufVec& buffers, int flags)
97{
98 return impl()->sendBytes(buffers, flags);
99}
100
101
102int DatagramSocket::receiveBytes(void* buffer, int length, int flags)
103{
104 return impl()->receiveBytes(buffer, length, flags);
105}
106
107
108int DatagramSocket::receiveBytes(SocketBufVec& buffers, int flags)
109{
110 return impl()->receiveBytes(buffers, flags);
111}
112
113
114int DatagramSocket::receiveBytes(Poco::Buffer<char>& buffer, int flags, const Poco::Timespan& timeout)
115{
116 return impl()->receiveBytes(buffer, flags, timeout);
117}
118
119
120int DatagramSocket::sendTo(const void* buffer, int length, const SocketAddress& address, int flags)
121{
122 return impl()->sendTo(buffer, length, address, flags);
123}
124
125
126int DatagramSocket::sendTo(const SocketBufVec& buffers, const SocketAddress& address, int flags)
127{
128 return impl()->sendTo(buffers, address, flags);
129}
130
131
132int DatagramSocket::receiveFrom(void* buffer, int length, SocketAddress& address, int flags)
133{
134 return impl()->receiveFrom(buffer, length, address, flags);
135}
136
137
138int DatagramSocket::receiveFrom(void* buffer, int length, struct sockaddr** ppSA, poco_socklen_t** saLen, int flags)
139{
140 return impl()->receiveFrom(buffer, length, ppSA, saLen, flags);
141}
142
143
144int DatagramSocket::receiveFrom(SocketBufVec& buffers, SocketAddress& address, int flags)
145{
146 return impl()->receiveFrom(buffers, address, flags);
147}
148
149
150int DatagramSocket::receiveFrom(SocketBufVec& buffers, struct sockaddr** ppSA, poco_socklen_t** ppSALen, int flags)
151{
152 return impl()->receiveFrom(buffers, ppSA, ppSALen, flags);
153}
154
155
156} } // namespace Poco::Net
157