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