mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-27 19:10:20 +01:00
merge Unix Domain Sockets support and other changes from develop
This commit is contained in:
@@ -32,9 +32,16 @@ class Net_API DatagramSocket: public Socket
|
||||
{
|
||||
public:
|
||||
DatagramSocket();
|
||||
/// Creates an unconnected IPv4 datagram socket.
|
||||
/// Creates an unconnected, unbound datagram socket.
|
||||
///
|
||||
/// Before the datagram socket can be used, bind(),
|
||||
/// bind6() or connect() must be called.
|
||||
///
|
||||
/// Notice: The behavior of this constructor has changed
|
||||
/// in release 2.0. Previously, the constructor created
|
||||
/// an unbound IPv4 datagram socket.
|
||||
|
||||
explicit DatagramSocket(IPAddress::Family family);
|
||||
explicit DatagramSocket(SocketAddress::Family family);
|
||||
/// Creates an unconnected datagram socket.
|
||||
///
|
||||
/// The socket will be created for the
|
||||
@@ -80,6 +87,20 @@ public:
|
||||
///
|
||||
/// Calls to connect cannot() come before calls to bind().
|
||||
|
||||
void bind(const SocketAddress& address, bool reuseAddress, bool reusePort);
|
||||
/// Bind a local address to the socket.
|
||||
///
|
||||
/// This is usually only done when establishing a server
|
||||
/// socket.
|
||||
///
|
||||
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||
/// socket option.
|
||||
///
|
||||
/// If reusePort is true, sets the SO_REUSEPORT
|
||||
/// socket option.
|
||||
///
|
||||
/// Calls to connect cannot() come before calls to bind().
|
||||
|
||||
int sendBytes(const void* buffer, int length, int flags = 0);
|
||||
/// Sends the contents of the given buffer through
|
||||
/// the socket.
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
DatagramSocketImpl();
|
||||
/// Creates an unconnected, unbound datagram socket.
|
||||
|
||||
explicit DatagramSocketImpl(IPAddress::Family family);
|
||||
explicit DatagramSocketImpl(SocketAddress::Family family);
|
||||
/// Creates an unconnected datagram socket.
|
||||
///
|
||||
/// The socket will be created for the
|
||||
|
||||
@@ -225,6 +225,24 @@ public:
|
||||
/// to ensure a new connection will be set up
|
||||
/// for the next request.
|
||||
|
||||
virtual bool peekResponse(HTTPResponse& response);
|
||||
/// If the request contains a "Expect: 100-continue" header,
|
||||
/// (see HTTPRequest::setExpectContinue()) this method can be
|
||||
/// used to check whether the server has sent a 100 Continue response
|
||||
/// before continuing with the request, i.e. sending the request body,
|
||||
/// after calling sendRequest().
|
||||
///
|
||||
/// Returns true if the server has responded with 100 Continue,
|
||||
/// otherwise false. The HTTPResponse object contains the
|
||||
/// response sent by the server.
|
||||
///
|
||||
/// In any case, receiveResponse() must be called afterwards as well in
|
||||
/// order to complete the request. The same HTTPResponse object
|
||||
/// passed to peekResponse() must also be passed to receiveResponse().
|
||||
///
|
||||
/// This method should only be called if the request contains
|
||||
/// a "Expect: 100-continue" header.
|
||||
|
||||
void reset();
|
||||
/// Resets the session and closes the socket.
|
||||
///
|
||||
@@ -289,6 +307,7 @@ private:
|
||||
bool _reconnect;
|
||||
bool _mustReconnect;
|
||||
bool _expectResponseBody;
|
||||
bool _responseReceived;
|
||||
Poco::SharedPtr<std::ostream> _pRequestStream;
|
||||
Poco::SharedPtr<std::istream> _pResponseStream;
|
||||
|
||||
|
||||
@@ -103,6 +103,14 @@ public:
|
||||
/// Sets the authentication scheme and information for
|
||||
/// this request.
|
||||
|
||||
bool getExpectContinue() const;
|
||||
/// Returns true if the request contains an
|
||||
/// "Expect: 100-continue" header.
|
||||
|
||||
void setExpectContinue(bool expectContinue);
|
||||
/// Adds a "Expect: 100-continue" header to the request if
|
||||
/// expectContinue is true, otherwise removes the Expect header.
|
||||
|
||||
bool hasProxyCredentials() const;
|
||||
/// Returns true iff the request contains proxy authentication
|
||||
/// information in the form of an Proxy-Authorization header.
|
||||
@@ -141,6 +149,7 @@ public:
|
||||
static const std::string AUTHORIZATION;
|
||||
static const std::string PROXY_AUTHORIZATION;
|
||||
static const std::string UPGRADE;
|
||||
static const std::string EXPECT;
|
||||
|
||||
protected:
|
||||
void getCredentials(const std::string& header, std::string& scheme, std::string& authInfo) const;
|
||||
|
||||
@@ -54,6 +54,11 @@ public:
|
||||
/// The method should inspect the given HTTPServerRequest object (e.g., method
|
||||
/// and URI) and create an appropriate HTTPRequestHandler object to handle the
|
||||
/// request.
|
||||
///
|
||||
/// If the request contains a "Expect: 100-continue" header, it's possible
|
||||
/// to prevent the server from sending the default 100 Continue response
|
||||
/// by setting the status of the response object that can be obtained through
|
||||
/// the request object (request.response()) to something other than 200 OK.
|
||||
|
||||
protected:
|
||||
Poco::BasicEvent<const bool> serverStopped;
|
||||
|
||||
@@ -45,6 +45,7 @@ public:
|
||||
{
|
||||
HTTP_CONTINUE = 100,
|
||||
HTTP_SWITCHING_PROTOCOLS = 101,
|
||||
HTTP_PROCESSING = 102,
|
||||
HTTP_OK = 200,
|
||||
HTTP_CREATED = 201,
|
||||
HTTP_ACCEPTED = 202,
|
||||
@@ -52,14 +53,19 @@ public:
|
||||
HTTP_NO_CONTENT = 204,
|
||||
HTTP_RESET_CONTENT = 205,
|
||||
HTTP_PARTIAL_CONTENT = 206,
|
||||
HTTP_MULTI_STATUS = 207,
|
||||
HTTP_ALREADY_REPORTED = 208,
|
||||
HTTP_IM_USED = 226,
|
||||
HTTP_MULTIPLE_CHOICES = 300,
|
||||
HTTP_MOVED_PERMANENTLY = 301,
|
||||
HTTP_FOUND = 302,
|
||||
HTTP_SEE_OTHER = 303,
|
||||
HTTP_NOT_MODIFIED = 304,
|
||||
HTTP_USEPROXY = 305,
|
||||
HTTP_USE_PROXY = 305,
|
||||
HTTP_USEPROXY = 305, /// @deprecated
|
||||
// UNUSED: 306
|
||||
HTTP_TEMPORARY_REDIRECT = 307,
|
||||
HTTP_PERMANENT_REDIRECT = 308,
|
||||
HTTP_BAD_REQUEST = 400,
|
||||
HTTP_UNAUTHORIZED = 401,
|
||||
HTTP_PAYMENT_REQUIRED = 402,
|
||||
@@ -73,17 +79,36 @@ public:
|
||||
HTTP_GONE = 410,
|
||||
HTTP_LENGTH_REQUIRED = 411,
|
||||
HTTP_PRECONDITION_FAILED = 412,
|
||||
HTTP_REQUESTENTITYTOOLARGE = 413,
|
||||
HTTP_REQUESTURITOOLONG = 414,
|
||||
HTTP_UNSUPPORTEDMEDIATYPE = 415,
|
||||
HTTP_REQUEST_ENTITY_TOO_LARGE = 413,
|
||||
HTTP_REQUESTENTITYTOOLARGE = 413, /// @deprecated
|
||||
HTTP_REQUEST_URI_TOO_LONG = 414,
|
||||
HTTP_REQUESTURITOOLONG = 414, /// @deprecated
|
||||
HTTP_UNSUPPORTED_MEDIA_TYPE = 415,
|
||||
HTTP_UNSUPPORTEDMEDIATYPE = 415, /// @deprecated
|
||||
HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416,
|
||||
HTTP_EXPECTATION_FAILED = 417,
|
||||
HTTP_IM_A_TEAPOT = 418,
|
||||
HTTP_ENCHANCE_YOUR_CALM = 420,
|
||||
HTTP_MISDIRECTED_REQUEST = 421,
|
||||
HTTP_UNPROCESSABLE_ENTITY = 422,
|
||||
HTTP_LOCKED = 423,
|
||||
HTTP_FAILED_DEPENDENCY = 424,
|
||||
HTTP_UPGRADE_REQUIRED = 426,
|
||||
HTTP_PRECONDITION_REQUIRED = 428,
|
||||
HTTP_TOO_MANY_REQUESTS = 429,
|
||||
HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
|
||||
HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451,
|
||||
HTTP_INTERNAL_SERVER_ERROR = 500,
|
||||
HTTP_NOT_IMPLEMENTED = 501,
|
||||
HTTP_BAD_GATEWAY = 502,
|
||||
HTTP_SERVICE_UNAVAILABLE = 503,
|
||||
HTTP_GATEWAY_TIMEOUT = 504,
|
||||
HTTP_VERSION_NOT_SUPPORTED = 505
|
||||
HTTP_VERSION_NOT_SUPPORTED = 505,
|
||||
HTTP_VARIANT_ALSO_NEGOTIATES = 506,
|
||||
HTTP_INSUFFICIENT_STORAGE = 507,
|
||||
HTTP_LOOP_DETECTED = 508,
|
||||
HTTP_NOT_EXTENDED = 510,
|
||||
HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511
|
||||
};
|
||||
|
||||
HTTPResponse();
|
||||
@@ -169,6 +194,7 @@ public:
|
||||
|
||||
static const std::string HTTP_REASON_CONTINUE;
|
||||
static const std::string HTTP_REASON_SWITCHING_PROTOCOLS;
|
||||
static const std::string HTTP_REASON_PROCESSING;
|
||||
static const std::string HTTP_REASON_OK;
|
||||
static const std::string HTTP_REASON_CREATED;
|
||||
static const std::string HTTP_REASON_ACCEPTED;
|
||||
@@ -176,13 +202,17 @@ public:
|
||||
static const std::string HTTP_REASON_NO_CONTENT;
|
||||
static const std::string HTTP_REASON_RESET_CONTENT;
|
||||
static const std::string HTTP_REASON_PARTIAL_CONTENT;
|
||||
static const std::string HTTP_REASON_MULTI_STATUS;
|
||||
static const std::string HTTP_REASON_ALREADY_REPORTED;
|
||||
static const std::string HTTP_REASON_IM_USED;
|
||||
static const std::string HTTP_REASON_MULTIPLE_CHOICES;
|
||||
static const std::string HTTP_REASON_MOVED_PERMANENTLY;
|
||||
static const std::string HTTP_REASON_FOUND;
|
||||
static const std::string HTTP_REASON_SEE_OTHER;
|
||||
static const std::string HTTP_REASON_NOT_MODIFIED;
|
||||
static const std::string HTTP_REASON_USEPROXY;
|
||||
static const std::string HTTP_REASON_USE_PROXY;
|
||||
static const std::string HTTP_REASON_TEMPORARY_REDIRECT;
|
||||
static const std::string HTTP_REASON_PERMANENT_REDIRECT;
|
||||
static const std::string HTTP_REASON_BAD_REQUEST;
|
||||
static const std::string HTTP_REASON_UNAUTHORIZED;
|
||||
static const std::string HTTP_REASON_PAYMENT_REQUIRED;
|
||||
@@ -196,17 +226,33 @@ public:
|
||||
static const std::string HTTP_REASON_GONE;
|
||||
static const std::string HTTP_REASON_LENGTH_REQUIRED;
|
||||
static const std::string HTTP_REASON_PRECONDITION_FAILED;
|
||||
static const std::string HTTP_REASON_REQUESTENTITYTOOLARGE;
|
||||
static const std::string HTTP_REASON_REQUESTURITOOLONG;
|
||||
static const std::string HTTP_REASON_UNSUPPORTEDMEDIATYPE;
|
||||
static const std::string HTTP_REASON_REQUEST_ENTITY_TOO_LARGE;
|
||||
static const std::string HTTP_REASON_REQUEST_URI_TOO_LONG;
|
||||
static const std::string HTTP_REASON_UNSUPPORTED_MEDIA_TYPE;
|
||||
static const std::string HTTP_REASON_REQUESTED_RANGE_NOT_SATISFIABLE;
|
||||
static const std::string HTTP_REASON_EXPECTATION_FAILED;
|
||||
static const std::string HTTP_REASON_IM_A_TEAPOT;
|
||||
static const std::string HTTP_REASON_ENCHANCE_YOUR_CALM;
|
||||
static const std::string HTTP_REASON_MISDIRECTED_REQUEST;
|
||||
static const std::string HTTP_REASON_UNPROCESSABLE_ENTITY;
|
||||
static const std::string HTTP_REASON_LOCKED;
|
||||
static const std::string HTTP_REASON_FAILED_DEPENDENCY;
|
||||
static const std::string HTTP_REASON_UPGRADE_REQUIRED;
|
||||
static const std::string HTTP_REASON_PRECONDITION_REQUIRED;
|
||||
static const std::string HTTP_REASON_TOO_MANY_REQUESTS;
|
||||
static const std::string HTTP_REASON_REQUEST_HEADER_FIELDS_TOO_LARGE;
|
||||
static const std::string HTTP_REASON_UNAVAILABLE_FOR_LEGAL_REASONS;
|
||||
static const std::string HTTP_REASON_INTERNAL_SERVER_ERROR;
|
||||
static const std::string HTTP_REASON_NOT_IMPLEMENTED;
|
||||
static const std::string HTTP_REASON_BAD_GATEWAY;
|
||||
static const std::string HTTP_REASON_SERVICE_UNAVAILABLE;
|
||||
static const std::string HTTP_REASON_GATEWAY_TIMEOUT;
|
||||
static const std::string HTTP_REASON_VERSION_NOT_SUPPORTED;
|
||||
static const std::string HTTP_REASON_VARIANT_ALSO_NEGOTIATES;
|
||||
static const std::string HTTP_REASON_INSUFFICIENT_STORAGE;
|
||||
static const std::string HTTP_REASON_LOOP_DETECTED;
|
||||
static const std::string HTTP_REASON_NOT_EXTENDED;
|
||||
static const std::string HTTP_REASON_NETWORK_AUTHENTICATION_REQUIRED;
|
||||
static const std::string HTTP_REASON_UNKNOWN;
|
||||
|
||||
static const std::string DATE;
|
||||
|
||||
@@ -54,10 +54,6 @@ public:
|
||||
/// The stream must be valid until the HTTPServerRequest
|
||||
/// object is destroyed.
|
||||
|
||||
virtual bool expectContinue() const = 0;
|
||||
/// Returns true if the client expects a
|
||||
/// 100 Continue response.
|
||||
|
||||
virtual const SocketAddress& clientAddress() const = 0;
|
||||
/// Returns the client's address.
|
||||
|
||||
@@ -69,6 +65,12 @@ public:
|
||||
|
||||
virtual HTTPServerResponse& response() const = 0;
|
||||
/// Returns a reference to the associated response.
|
||||
|
||||
virtual bool secure() const = 0;
|
||||
/// Returns true if the request is using a secure
|
||||
/// connection. Returns false if no secure connection
|
||||
/// is used, or if it is not known whether a secure
|
||||
/// connection is used.
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -57,10 +57,6 @@ public:
|
||||
/// The stream is valid until the HTTPServerRequestImpl
|
||||
/// object is destroyed.
|
||||
|
||||
bool expectContinue() const;
|
||||
/// Returns true if the client expects a
|
||||
/// 100 Continue response.
|
||||
|
||||
const SocketAddress& clientAddress() const;
|
||||
/// Returns the client's address.
|
||||
|
||||
@@ -73,6 +69,12 @@ public:
|
||||
HTTPServerResponse& response() const;
|
||||
/// Returns a reference to the associated response.
|
||||
|
||||
bool secure() const;
|
||||
/// Returns true if the request is using a secure
|
||||
/// connection. Returns false if no secure connection
|
||||
/// is used, or if it is not known whether a secure
|
||||
/// connection is used.
|
||||
|
||||
StreamSocket& socket();
|
||||
/// Returns a reference to the underlying socket.
|
||||
|
||||
@@ -83,9 +85,6 @@ public:
|
||||
HTTPServerSession& session();
|
||||
/// Returns the underlying HTTPServerSession.
|
||||
|
||||
protected:
|
||||
static const std::string EXPECT;
|
||||
|
||||
private:
|
||||
HTTPServerResponseImpl& _response;
|
||||
HTTPServerSession& _session;
|
||||
|
||||
@@ -55,6 +55,9 @@ public:
|
||||
void setTimeout(const Poco::Timespan& timeout);
|
||||
/// Sets the timeout for the HTTP session.
|
||||
|
||||
void setTimeout(const Poco::Timespan& connectionTimeout, const Poco::Timespan& sendTimeout, const Poco::Timespan& receiveTimeout);
|
||||
/// Sets different timeouts for the HTTP session.
|
||||
|
||||
Poco::Timespan getTimeout() const;
|
||||
/// Returns the timeout for the HTTP session.
|
||||
|
||||
@@ -178,7 +181,8 @@ protected:
|
||||
private:
|
||||
enum
|
||||
{
|
||||
HTTP_DEFAULT_TIMEOUT = 60000000
|
||||
HTTP_DEFAULT_TIMEOUT = 60000000,
|
||||
HTTP_DEFAULT_CONNECTION_TIMEOUT = 30000000
|
||||
};
|
||||
|
||||
HTTPSession(const HTTPSession&);
|
||||
@@ -189,7 +193,9 @@ private:
|
||||
char* _pCurrent;
|
||||
char* _pEnd;
|
||||
bool _keepAlive;
|
||||
Poco::Timespan _timeout;
|
||||
Poco::Timespan _connectionTimeout;
|
||||
Poco::Timespan _receiveTimeout;
|
||||
Poco::Timespan _sendTimeout;
|
||||
Poco::Exception* _pException;
|
||||
Poco::Any _data;
|
||||
|
||||
@@ -211,7 +217,7 @@ inline bool HTTPSession::getKeepAlive() const
|
||||
|
||||
inline Poco::Timespan HTTPSession::getTimeout() const
|
||||
{
|
||||
return _timeout;
|
||||
return _receiveTimeout;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
mutable Poco::BasicEvent<ICMPEventArgs> pingError;
|
||||
mutable Poco::BasicEvent<ICMPEventArgs> pingEnd;
|
||||
|
||||
explicit ICMPClient(IPAddress::Family family);
|
||||
explicit ICMPClient(SocketAddress::Family family);
|
||||
/// Creates an ICMP client.
|
||||
|
||||
~ICMPClient();
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
///
|
||||
/// Returns the number of valid replies.
|
||||
|
||||
static int ping(SocketAddress& address, IPAddress::Family family, int repeat = 1);
|
||||
static int ping(SocketAddress& address, SocketAddress::Family family, int repeat = 1);
|
||||
/// Pings the specified address [repeat] times.
|
||||
/// Notifications are not posted for events.
|
||||
///
|
||||
@@ -75,7 +75,7 @@ public:
|
||||
/// Returns the number of valid replies.
|
||||
|
||||
private:
|
||||
mutable IPAddress::Family _family;
|
||||
mutable SocketAddress::Family _family;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class Net_API ICMPPacket
|
||||
/// This class is the ICMP packet abstraction.
|
||||
{
|
||||
public:
|
||||
ICMPPacket(IPAddress::Family family, int dataSize = 48);
|
||||
ICMPPacket(SocketAddress::Family family, int dataSize = 48);
|
||||
/// Creates an ICMPPacket of specified family.
|
||||
|
||||
~ICMPPacket();
|
||||
|
||||
@@ -31,7 +31,7 @@ class Net_API ICMPSocket: public Socket
|
||||
/// ICMP client socket.
|
||||
{
|
||||
public:
|
||||
ICMPSocket(IPAddress::Family family, int dataSize = 48, int ttl = 128, int timeout = 5000000);
|
||||
ICMPSocket(SocketAddress::Family family, int dataSize = 48, int ttl = 128, int timeout = 5000000);
|
||||
/// Creates an unconnected ICMP socket.
|
||||
///
|
||||
/// The socket will be created for the
|
||||
|
||||
@@ -32,7 +32,7 @@ class Net_API ICMPSocketImpl: public RawSocketImpl
|
||||
/// This class implements an ICMP socket.
|
||||
{
|
||||
public:
|
||||
ICMPSocketImpl(IPAddress::Family family, int dataSize, int ttl, int timeout);
|
||||
ICMPSocketImpl(SocketAddress::Family family, int dataSize, int ttl, int timeout);
|
||||
/// Creates an unconnected ICMP socket.
|
||||
///
|
||||
/// The socket will be created for the given address family.
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <vector>
|
||||
#include <ostream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@@ -55,14 +56,14 @@ class Net_API IPAddress
|
||||
public:
|
||||
typedef std::vector<IPAddress> List;
|
||||
|
||||
enum Family
|
||||
/// Possible address families for IP addresses.
|
||||
{
|
||||
IPv4 = Poco::Net::Impl::IPAddressImpl::IPv4
|
||||
#ifdef POCO_HAVE_IPv6
|
||||
,IPv6 = Poco::Net::Impl::IPAddressImpl::IPv6
|
||||
// The following declarations keep the Family type
|
||||
// backwards compatible with the previously used
|
||||
// enum declaration.
|
||||
typedef AddressFamily::Family Family;
|
||||
static const Family IPv4 = AddressFamily::IPv4;
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
static const Family IPv6 = AddressFamily::IPv6;
|
||||
#endif
|
||||
};
|
||||
|
||||
IPAddress();
|
||||
/// Creates a wildcard (zero) IPv4 IPAddress.
|
||||
@@ -371,13 +372,15 @@ private:
|
||||
#endif
|
||||
|
||||
Ptr pImpl() const;
|
||||
void newIPv4();
|
||||
void newIPv4(const void* hostAddr);
|
||||
void newIPv4(unsigned prefix);
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
void newIPv6();
|
||||
void newIPv6(const void* hostAddr);
|
||||
void newIPv6(const void* hostAddr, Poco::UInt32 scope);
|
||||
void newIPv4(unsigned prefix);
|
||||
void newIPv6(unsigned prefix);
|
||||
void newIPv4();
|
||||
void newIPv6();
|
||||
#endif
|
||||
void destruct();
|
||||
|
||||
#ifdef POCO_HAVE_ALIGNMENT
|
||||
@@ -394,7 +397,11 @@ private:
|
||||
AlignerType aligner;
|
||||
}
|
||||
#else // !POCO_ENABLE_CPP11
|
||||
AlignedCharArrayUnion <Poco::Net::Impl::IPv6AddressImpl>
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
AlignedCharArrayUnion <Poco::Net::Impl::IPv6AddressImpl>
|
||||
#else
|
||||
AlignedCharArrayUnion <Poco::Net::Impl::IPv4AddressImpl>
|
||||
#endif
|
||||
#endif // POCO_ENABLE_CPP11
|
||||
_memory;
|
||||
#else // !POCO_HAVE_ALIGNMENT
|
||||
@@ -406,6 +413,8 @@ private:
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
|
||||
|
||||
inline void IPAddress::destruct()
|
||||
{
|
||||
#ifdef POCO_HAVE_ALIGNMENT
|
||||
@@ -425,6 +434,16 @@ inline IPAddress::Ptr IPAddress::pImpl() const
|
||||
}
|
||||
|
||||
|
||||
inline void IPAddress::newIPv4()
|
||||
{
|
||||
#ifdef POCO_HAVE_ALIGNMENT
|
||||
new (storage()) Poco::Net::Impl::IPv4AddressImpl;
|
||||
#else
|
||||
_pImpl = new Poco::Net::Impl::IPv4AddressImpl;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
inline void IPAddress::newIPv4(const void* hostAddr)
|
||||
{
|
||||
#ifdef POCO_HAVE_ALIGNMENT
|
||||
@@ -435,6 +454,29 @@ inline void IPAddress::newIPv4(const void* hostAddr)
|
||||
}
|
||||
|
||||
|
||||
inline void IPAddress::newIPv4(unsigned prefix)
|
||||
{
|
||||
#ifdef POCO_HAVE_ALIGNMENT
|
||||
new (storage()) Poco::Net::Impl::IPv4AddressImpl(prefix);
|
||||
#else
|
||||
_pImpl = new Poco::Net::Impl::IPv4AddressImpl(prefix);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
|
||||
|
||||
inline void IPAddress::newIPv6()
|
||||
{
|
||||
#ifdef POCO_HAVE_ALIGNMENT
|
||||
new (storage()) Poco::Net::Impl::IPv6AddressImpl;
|
||||
#else
|
||||
_pImpl = new Poco::Net::Impl::IPv6AddressImpl;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
inline void IPAddress::newIPv6(const void* hostAddr)
|
||||
{
|
||||
#ifdef POCO_HAVE_ALIGNMENT
|
||||
@@ -455,16 +497,6 @@ inline void IPAddress::newIPv6(const void* hostAddr, Poco::UInt32 scope)
|
||||
}
|
||||
|
||||
|
||||
inline void IPAddress::newIPv4(unsigned prefix)
|
||||
{
|
||||
#ifdef POCO_HAVE_ALIGNMENT
|
||||
new (storage()) Poco::Net::Impl::IPv4AddressImpl(prefix);
|
||||
#else
|
||||
_pImpl = new Poco::Net::Impl::IPv4AddressImpl(prefix);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
inline void IPAddress::newIPv6(unsigned prefix)
|
||||
{
|
||||
#ifdef POCO_HAVE_ALIGNMENT
|
||||
@@ -475,24 +507,7 @@ inline void IPAddress::newIPv6(unsigned prefix)
|
||||
}
|
||||
|
||||
|
||||
inline void IPAddress::newIPv4()
|
||||
{
|
||||
#ifdef POCO_HAVE_ALIGNMENT
|
||||
new (storage()) Poco::Net::Impl::IPv4AddressImpl;
|
||||
#else
|
||||
_pImpl = new Poco::Net::Impl::IPv4AddressImpl;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
inline void IPAddress::newIPv6()
|
||||
{
|
||||
#ifdef POCO_HAVE_ALIGNMENT
|
||||
new (storage()) Poco::Net::Impl::IPv6AddressImpl;
|
||||
#else
|
||||
_pImpl = new Poco::Net::Impl::IPv6AddressImpl;
|
||||
#endif
|
||||
}
|
||||
#endif // POCO_HAVE_IPv6
|
||||
|
||||
|
||||
#ifdef POCO_HAVE_ALIGNMENT
|
||||
@@ -503,11 +518,12 @@ inline char* IPAddress::storage()
|
||||
#endif
|
||||
|
||||
|
||||
BinaryWriter& operator << (BinaryWriter& writer, const IPAddress& value);
|
||||
BinaryReader& operator >> (BinaryReader& reader, IPAddress& value);
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
|
||||
Net_API Poco::BinaryWriter& operator << (Poco::BinaryWriter& writer, const Poco::Net::IPAddress& value);
|
||||
Net_API Poco::BinaryReader& operator >> (Poco::BinaryReader& reader, Poco::Net::IPAddress& value);
|
||||
Net_API std::ostream& operator << (std::ostream& ostr, const Poco::Net::IPAddress& addr);
|
||||
|
||||
|
||||
#endif // Net_IPAddress_INCLUDED
|
||||
|
||||
@@ -37,14 +37,7 @@ class IPAddressImpl
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
enum Family
|
||||
/// Possible address families for IP addresses.
|
||||
{
|
||||
IPv4
|
||||
#ifdef POCO_HAVE_IPv6
|
||||
,IPv6
|
||||
#endif
|
||||
};
|
||||
typedef AddressFamily::Family Family;
|
||||
|
||||
virtual ~IPAddressImpl();
|
||||
|
||||
@@ -129,6 +122,9 @@ private:
|
||||
};
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
|
||||
|
||||
//
|
||||
// IPv6AddressImpl
|
||||
//
|
||||
@@ -179,6 +175,9 @@ private:
|
||||
};
|
||||
|
||||
|
||||
#endif // POCO_HAVE_IPv6
|
||||
|
||||
|
||||
} } } // namespace Poco::Net::Impl
|
||||
|
||||
|
||||
|
||||
@@ -145,6 +145,11 @@ public:
|
||||
/// appended to result, enclosed in double-quotes.
|
||||
/// Otherwise, the value is appended to result as-is.
|
||||
|
||||
static void decodeRFC2047(const std::string& ins, std::string& outs, const std::string& charset = "UTF-8");
|
||||
static std::string decodeWord(const std::string& text, const std::string& charset = "UTF-8");
|
||||
/// Decode RFC2047 string.
|
||||
|
||||
|
||||
private:
|
||||
enum Limits
|
||||
/// Limits for basic sanity checks when reading a header
|
||||
|
||||
@@ -39,9 +39,16 @@ class Net_API MulticastSocket: public DatagramSocket
|
||||
{
|
||||
public:
|
||||
MulticastSocket();
|
||||
/// Creates the multicast socket.
|
||||
/// Creates an unconnected, unbound multicast socket.
|
||||
///
|
||||
/// Before the multicast socket can be used, bind(),
|
||||
/// bind6() or connect() must be called.
|
||||
///
|
||||
/// Notice: The behavior of this constructor has changed
|
||||
/// in release 2.0. Previously, the constructor created
|
||||
/// an unbound IPv4 multicast socket.
|
||||
|
||||
explicit MulticastSocket(IPAddress::Family family);
|
||||
explicit MulticastSocket(SocketAddress::Family family);
|
||||
/// Creates an unconnected datagram socket.
|
||||
///
|
||||
/// The socket will be created for the
|
||||
|
||||
@@ -34,7 +34,7 @@ class Net_API NTPClient
|
||||
public:
|
||||
mutable Poco::BasicEvent<NTPEventArgs> response;
|
||||
|
||||
explicit NTPClient(IPAddress::Family family, int timeout = 3000000);
|
||||
explicit NTPClient(SocketAddress::Family family, int timeout = 3000000);
|
||||
/// Creates an NTP client.
|
||||
|
||||
~NTPClient();
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
/// Returns the number of valid replies.
|
||||
|
||||
private:
|
||||
mutable IPAddress::Family _family;
|
||||
mutable SocketAddress::Family _family;
|
||||
int _timeout;
|
||||
};
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ POCO_DECLARE_EXCEPTION(Net_API, NTPException, NetException)
|
||||
POCO_DECLARE_EXCEPTION(Net_API, HTMLFormException, NetException)
|
||||
POCO_DECLARE_EXCEPTION(Net_API, WebSocketException, NetException)
|
||||
POCO_DECLARE_EXCEPTION(Net_API, UnsupportedFamilyException, NetException)
|
||||
POCO_DECLARE_EXCEPTION(Net_API, AddressFamilyMismatchException, NetException)
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
@@ -248,8 +248,7 @@ public:
|
||||
/// Returns the NetworkInterface for the given interface index.
|
||||
///
|
||||
/// Throws an InterfaceNotFoundException if an interface
|
||||
/// with the given index does not exist (or IPv6 is not
|
||||
/// available).
|
||||
/// with the given index does not exist.
|
||||
|
||||
static List list(bool ipOnly = true, bool upOnly = true);
|
||||
/// Returns a list with all network interfaces
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
RawSocket();
|
||||
/// Creates an unconnected IPv4 raw socket.
|
||||
|
||||
RawSocket(IPAddress::Family family, int proto = IPPROTO_RAW);
|
||||
RawSocket(SocketAddress::Family family, int proto = IPPROTO_RAW);
|
||||
/// Creates an unconnected raw socket.
|
||||
///
|
||||
/// The socket will be created for the
|
||||
@@ -80,6 +80,20 @@ public:
|
||||
///
|
||||
/// Calls to connect() cannot come before calls to bind().
|
||||
|
||||
void bind(const SocketAddress& address, bool reuseAddress, bool reusePort);
|
||||
/// Bind a local address to the socket.
|
||||
///
|
||||
/// This is usually only done when establishing a server
|
||||
/// socket.
|
||||
///
|
||||
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||
/// socket option.
|
||||
///
|
||||
/// If reusePort is true, sets the SO_REUSEPORT
|
||||
/// socket option.
|
||||
///
|
||||
/// Calls to connect() cannot come before calls to bind().
|
||||
|
||||
int sendBytes(const void* buffer, int length, int flags = 0);
|
||||
/// Sends the contents of the given buffer through
|
||||
/// the socket.
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
RawSocketImpl();
|
||||
/// Creates an unconnected IPv4 raw socket with IPPROTO_RAW.
|
||||
|
||||
RawSocketImpl(IPAddress::Family family, int proto = IPPROTO_RAW);
|
||||
RawSocketImpl(SocketAddress::Family family, int proto = IPPROTO_RAW);
|
||||
/// Creates an unconnected raw socket.
|
||||
///
|
||||
/// The socket will be created for the
|
||||
|
||||
@@ -80,6 +80,19 @@ public:
|
||||
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||
/// socket option.
|
||||
|
||||
virtual void bind(const SocketAddress& address, bool reuseAddress, bool reusePort);
|
||||
/// Binds a local address to the socket.
|
||||
///
|
||||
/// This is usually only done when establishing a server
|
||||
/// socket. TCP clients should not bind a socket to a
|
||||
/// specific address.
|
||||
///
|
||||
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||
/// socket option.
|
||||
///
|
||||
/// If reuseAddress is true, sets the SO_REUSEPORT
|
||||
/// socket option.
|
||||
|
||||
virtual void bind(Poco::UInt16 port, bool reuseAddress = false);
|
||||
/// Binds a local port to the socket.
|
||||
///
|
||||
@@ -89,6 +102,18 @@ public:
|
||||
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||
/// socket option.
|
||||
|
||||
virtual void bind(Poco::UInt16 port, bool reuseAddress, bool reusePort);
|
||||
/// Binds a local port to the socket.
|
||||
///
|
||||
/// This is usually only done when establishing a server
|
||||
/// socket.
|
||||
///
|
||||
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||
/// socket option.
|
||||
///
|
||||
/// If reusePort is true, sets the SO_REUSEPORT
|
||||
/// socket option.
|
||||
|
||||
virtual void bind6(const SocketAddress& address, bool reuseAddress = false, bool ipV6Only = false);
|
||||
/// Binds a local IPv6 address to the socket.
|
||||
///
|
||||
@@ -106,6 +131,26 @@ public:
|
||||
/// If the library has not been built with IPv6 support,
|
||||
/// a Poco::NotImplementedException will be thrown.
|
||||
|
||||
virtual void bind6(const SocketAddress& address, bool reuseAddress, bool reusePort, bool ipV6Only);
|
||||
/// Binds a local IPv6 address to the socket.
|
||||
///
|
||||
/// This is usually only done when establishing a server
|
||||
/// socket. TCP clients should not bind a socket to a
|
||||
/// specific address.
|
||||
///
|
||||
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||
/// socket option.
|
||||
///
|
||||
/// If reusePort is true, sets the SO_REUSEPORT
|
||||
/// socket option.
|
||||
///
|
||||
/// The given address must be an IPv6 address. The
|
||||
/// IPPROTO_IPV6/IPV6_V6ONLY option is set on the socket
|
||||
/// according to the ipV6Only parameter.
|
||||
///
|
||||
/// If the library has not been built with IPv6 support,
|
||||
/// a Poco::NotImplementedException will be thrown.
|
||||
|
||||
virtual void bind6(Poco::UInt16 port, bool reuseAddress = false, bool ipV6Only = false);
|
||||
/// Binds a local IPv6 port to the socket.
|
||||
///
|
||||
@@ -122,6 +167,24 @@ public:
|
||||
/// If the library has not been built with IPv6 support,
|
||||
/// a Poco::NotImplementedException will be thrown.
|
||||
|
||||
virtual void bind6(Poco::UInt16 port, bool reuseAddress, bool reusePort, bool ipV6Only);
|
||||
/// Binds a local IPv6 port to the socket.
|
||||
///
|
||||
/// This is usually only done when establishing a server
|
||||
/// socket.
|
||||
///
|
||||
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||
/// socket option.
|
||||
///
|
||||
/// If reusePort is true, sets the SO_REUSEPORT
|
||||
/// socket option.
|
||||
/// The given address must be an IPv6 address. The
|
||||
/// IPPROTO_IPV6/IPV6_V6ONLY option is set on the socket
|
||||
/// according to the ipV6Only parameter.
|
||||
///
|
||||
/// If the library has not been built with IPv6 support,
|
||||
/// a Poco::NotImplementedException will be thrown.
|
||||
|
||||
virtual void listen(int backlog = 64);
|
||||
/// Puts the socket into listening state.
|
||||
///
|
||||
|
||||
@@ -20,9 +20,14 @@
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "Poco/Net/SocketAddressImpl.h"
|
||||
#include <ostream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
class BinaryReader;
|
||||
class BinaryWriter;
|
||||
|
||||
namespace Net {
|
||||
|
||||
|
||||
@@ -36,9 +41,25 @@ class Net_API SocketAddress
|
||||
/// host address and a port number.
|
||||
{
|
||||
public:
|
||||
// The following declarations keep the Family type
|
||||
// backwards compatible with the previously used
|
||||
// enum declaration.
|
||||
typedef AddressFamily::Family Family;
|
||||
static const Family IPv4 = AddressFamily::IPv4;
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
static const Family IPv6 = AddressFamily::IPv6;
|
||||
#endif
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
static const Family UNIX_LOCAL = AddressFamily::UNIX_LOCAL;
|
||||
#endif
|
||||
|
||||
SocketAddress();
|
||||
/// Creates a wildcard (all zero) IPv4 SocketAddress.
|
||||
|
||||
explicit SocketAddress(Family family);
|
||||
/// Creates a SocketAddress with unspecified (wildcard) IP address
|
||||
/// of the given family.
|
||||
|
||||
SocketAddress(const IPAddress& hostAddress, Poco::UInt16 portNumber);
|
||||
/// Creates a SocketAddress from an IP address and given port number.
|
||||
|
||||
@@ -46,12 +67,27 @@ public:
|
||||
/// Creates a SocketAddress with unspecified (wildcard) IP address
|
||||
/// and given port number.
|
||||
|
||||
SocketAddress(Family family, Poco::UInt16 port);
|
||||
/// Creates a SocketAddress with unspecified (wildcard) IP address
|
||||
/// of the given family, and given port number.
|
||||
|
||||
SocketAddress(const std::string& hostAddress, Poco::UInt16 portNumber);
|
||||
/// Creates a SocketAddress from an IP address and given port number.
|
||||
///
|
||||
/// The IP address must either be a domain name, or it must
|
||||
/// be in dotted decimal (IPv4) or hex string (IPv6) format.
|
||||
|
||||
SocketAddress(Family family, const std::string& hostAddress, Poco::UInt16 portNumber);
|
||||
/// Creates a SocketAddress from an IP address and given port number.
|
||||
///
|
||||
/// The IP address must either be a domain name, or it must
|
||||
/// be in dotted decimal (IPv4) or hex string (IPv6) format.
|
||||
///
|
||||
/// If a domain name is given in hostAddress, it is resolved and the address
|
||||
/// matching the given family is used. If no address matching the given family
|
||||
/// is found, or the IP address given in hostAddress does not match the given
|
||||
/// family, an AddressFamilyMismatchException is thrown.
|
||||
|
||||
SocketAddress(const std::string& hostAddress, const std::string& portNumber);
|
||||
/// Creates a SocketAddress from an IP address and the
|
||||
/// service name or port number.
|
||||
@@ -62,6 +98,21 @@ public:
|
||||
/// The given port must either be a decimal port number, or
|
||||
/// a service name.
|
||||
|
||||
SocketAddress(Family family, const std::string& hostAddress, const std::string& portNumber);
|
||||
/// Creates a SocketAddress from an IP address and the
|
||||
/// service name or port number.
|
||||
///
|
||||
/// The IP address must either be a domain name, or it must
|
||||
/// be in dotted decimal (IPv4) or hex string (IPv6) format.
|
||||
///
|
||||
/// The given port must either be a decimal port number, or
|
||||
/// a service name.
|
||||
///
|
||||
/// If a domain name is given in hostAddress, it is resolved and the address
|
||||
/// matching the given family is used. If no address matching the given family
|
||||
/// is found, or the IP address given in hostAddress does not match the given
|
||||
/// family, an AddressFamilyMismatchException is thrown.
|
||||
|
||||
explicit SocketAddress(const std::string& hostAndPort);
|
||||
/// Creates a SocketAddress from an IP address or host name and the
|
||||
/// port number/service name. Host name/address and port number must
|
||||
@@ -72,6 +123,17 @@ public:
|
||||
/// 192.168.1.10:80
|
||||
/// [::ffff:192.168.1.120]:2040
|
||||
/// www.appinf.com:8080
|
||||
///
|
||||
/// On POSIX platforms supporting UNIX_LOCAL sockets, hostAndPort
|
||||
/// can also be the absolute path of a local socket, starting with a
|
||||
/// slash, e.g. "/tmp/local.socket".
|
||||
|
||||
SocketAddress(Family family, const std::string& addr);
|
||||
/// Creates a SocketAddress of the given family from a
|
||||
/// string representation of the address, which is
|
||||
/// either an IP address and port number, separated by
|
||||
/// a colon for IPv4 or IPv6 addresses, or a path for
|
||||
/// UNIX_LOCAL sockets.
|
||||
|
||||
SocketAddress(const SocketAddress& addr);
|
||||
/// Creates a SocketAddress by copying another one.
|
||||
@@ -103,7 +165,7 @@ public:
|
||||
std::string toString() const;
|
||||
/// Returns a string representation of the address.
|
||||
|
||||
IPAddress::Family family() const;
|
||||
Family family() const;
|
||||
/// Returns the address family of the host's address.
|
||||
|
||||
bool operator < (const SocketAddress& socketAddress) const;
|
||||
@@ -113,7 +175,9 @@ public:
|
||||
enum
|
||||
{
|
||||
MAX_ADDRESS_LENGTH =
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
sizeof(struct sockaddr_un)
|
||||
#elif defined(POCO_HAVE_IPv6)
|
||||
sizeof(struct sockaddr_in6)
|
||||
#else
|
||||
sizeof(struct sockaddr_in)
|
||||
@@ -124,6 +188,9 @@ public:
|
||||
protected:
|
||||
void init(const IPAddress& hostAddress, Poco::UInt16 portNumber);
|
||||
void init(const std::string& hostAddress, Poco::UInt16 portNumber);
|
||||
void init(Family family, const std::string& hostAddress, Poco::UInt16 portNumber);
|
||||
void init(Family family, const std::string& address);
|
||||
void init(const std::string& hostAndPort);
|
||||
Poco::UInt16 resolveService(const std::string& service);
|
||||
|
||||
private:
|
||||
@@ -137,14 +204,18 @@ private:
|
||||
Ptr pImpl() const;
|
||||
|
||||
void newIPv4();
|
||||
|
||||
void newIPv4(const sockaddr_in*);
|
||||
|
||||
void newIPv4(const IPAddress& hostAddress, Poco::UInt16 portNumber);
|
||||
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
void newIPv6(const sockaddr_in6*);
|
||||
|
||||
void newIPv6(const IPAddress& hostAddress, Poco::UInt16 portNumber);
|
||||
#endif
|
||||
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
void newLocal(const sockaddr_un* sockAddr);
|
||||
void newLocal(const std::string& path);
|
||||
#endif
|
||||
|
||||
void destruct();
|
||||
|
||||
@@ -161,7 +232,11 @@ private:
|
||||
AlignerType aligner;
|
||||
}
|
||||
#else // !POCO_ENABLE_CPP11
|
||||
AlignedCharArrayUnion <Poco::Net::Impl::IPv6SocketAddressImpl>
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
AlignedCharArrayUnion <Poco::Net::Impl::IPv6SocketAddressImpl>
|
||||
#else
|
||||
AlignedCharArrayUnion <Poco::Net::Impl::IPv4SocketAddressImpl>
|
||||
#endif
|
||||
#endif // POCO_ENABLE_CPP11
|
||||
_memory;
|
||||
#else // !POCO_HAVE_ALIGNMENT
|
||||
@@ -224,7 +299,7 @@ inline void SocketAddress::newIPv4(const IPAddress& hostAddress, Poco::UInt16 po
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
inline void SocketAddress::newIPv6(const sockaddr_in6* sockAddr)
|
||||
{
|
||||
#ifdef POCO_HAVE_ALIGNMENT
|
||||
@@ -243,14 +318,31 @@ inline void SocketAddress::newIPv6(const IPAddress& hostAddress, Poco::UInt16 po
|
||||
_pImpl = new Poco::Net::Impl::IPv6SocketAddressImpl(hostAddress.addr(), htons(portNumber), hostAddress.scope());
|
||||
#endif
|
||||
}
|
||||
#endif // POCO_HAVE_IPv6
|
||||
|
||||
|
||||
inline IPAddress::Family SocketAddress::family() const
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
inline void SocketAddress::newLocal(const sockaddr_un* sockAddr)
|
||||
{
|
||||
return host().family();
|
||||
#ifdef POCO_HAVE_ALIGNMENT
|
||||
new (storage()) Poco::Net::Impl::LocalSocketAddressImpl(sockAddr);
|
||||
#else
|
||||
_pImpl = new Poco::Net::Impl::LocalSocketAddressImpl(sockAddr);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
inline void SocketAddress::newLocal(const std::string& path)
|
||||
{
|
||||
#ifdef POCO_HAVE_ALIGNMENT
|
||||
new (storage()) Poco::Net::Impl::LocalSocketAddressImpl(path.c_str());
|
||||
#else
|
||||
_pImpl = new Poco::Net::Impl::LocalSocketAddressImpl(path.c_str());
|
||||
#endif
|
||||
}
|
||||
#endif // POCO_OS_FAMILY_UNIX
|
||||
|
||||
|
||||
#ifdef POCO_HAVE_ALIGNMENT
|
||||
inline char* SocketAddress::storage()
|
||||
{
|
||||
@@ -259,19 +351,29 @@ inline char* SocketAddress::storage()
|
||||
#endif
|
||||
|
||||
|
||||
inline bool SocketAddress::operator == (const SocketAddress& socketAddress) const
|
||||
inline bool SocketAddress::operator == (const SocketAddress& socketAddress) const
|
||||
{
|
||||
return host() == socketAddress.host() && port() == socketAddress.port();
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
if (family() == UNIX_LOCAL)
|
||||
return toString() == socketAddress.toString();
|
||||
else
|
||||
#endif
|
||||
return host() == socketAddress.host() && port() == socketAddress.port();
|
||||
}
|
||||
|
||||
|
||||
inline bool SocketAddress::operator != (const SocketAddress& socketAddress) const
|
||||
{
|
||||
return host() != socketAddress.host() || port() != socketAddress.port();
|
||||
return !(operator == (socketAddress));
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
|
||||
Net_API Poco::BinaryWriter& operator << (Poco::BinaryWriter& writer, const Poco::Net::SocketAddress& value);
|
||||
Net_API Poco::BinaryReader& operator >> (Poco::BinaryReader& reader, Poco::Net::SocketAddress& value);
|
||||
Net_API std::ostream& operator << (std::ostream& ostr, const Poco::Net::SocketAddress& address);
|
||||
|
||||
|
||||
#endif // Net_SocketAddress_INCLUDED
|
||||
|
||||
@@ -37,6 +37,8 @@ class Net_API SocketAddressImpl
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
typedef AddressFamily::Family Family;
|
||||
|
||||
virtual ~SocketAddressImpl();
|
||||
|
||||
virtual IPAddress host() const = 0;
|
||||
@@ -44,6 +46,8 @@ public:
|
||||
virtual poco_socklen_t length() const = 0;
|
||||
virtual const struct sockaddr* addr() const = 0;
|
||||
virtual int af() const = 0;
|
||||
virtual Family family() const = 0;
|
||||
virtual std::string toString() const = 0;
|
||||
|
||||
protected:
|
||||
SocketAddressImpl();
|
||||
@@ -65,7 +69,7 @@ public:
|
||||
poco_socklen_t length() const;
|
||||
const struct sockaddr* addr() const;
|
||||
int af() const;
|
||||
IPAddress::Family family() const;
|
||||
Family family() const;
|
||||
std::string toString() const;
|
||||
|
||||
private:
|
||||
@@ -107,6 +111,12 @@ inline int IPv4SocketAddressImpl::af() const
|
||||
}
|
||||
|
||||
|
||||
inline SocketAddressImpl::Family IPv4SocketAddressImpl::family() const
|
||||
{
|
||||
return AddressFamily::IPv4;
|
||||
}
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
|
||||
|
||||
@@ -121,6 +131,8 @@ public:
|
||||
poco_socklen_t length() const;
|
||||
const struct sockaddr* addr() const;
|
||||
int af() const;
|
||||
Family family() const;
|
||||
std::string toString() const;
|
||||
|
||||
private:
|
||||
struct sockaddr_in6 _addr;
|
||||
@@ -161,7 +173,87 @@ inline int IPv6SocketAddressImpl::af() const
|
||||
}
|
||||
|
||||
|
||||
#endif //POCO_HAVE_IPv6
|
||||
inline SocketAddressImpl::Family IPv6SocketAddressImpl::family() const
|
||||
{
|
||||
return AddressFamily::IPv6;
|
||||
}
|
||||
|
||||
|
||||
#endif // POCO_HAVE_IPv6
|
||||
|
||||
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
|
||||
|
||||
class Net_API LocalSocketAddressImpl: public SocketAddressImpl
|
||||
{
|
||||
public:
|
||||
LocalSocketAddressImpl(const struct sockaddr_un* addr);
|
||||
LocalSocketAddressImpl(const char* path);
|
||||
~LocalSocketAddressImpl();
|
||||
IPAddress host() const;
|
||||
UInt16 port() const;
|
||||
poco_socklen_t length() const;
|
||||
const struct sockaddr* addr() const;
|
||||
int af() const;
|
||||
Family family() const;
|
||||
const char* path() const;
|
||||
std::string toString() const;
|
||||
|
||||
private:
|
||||
struct sockaddr_un* _pAddr;
|
||||
// Note: We allocate struct sockaddr_un on the heap, otherwise we would
|
||||
// waste a lot of memory due to small object optimization in SocketAddress.
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
|
||||
inline IPAddress LocalSocketAddressImpl::host() const
|
||||
{
|
||||
throw Poco::InvalidAccessException("local socket address does not have host IP address");
|
||||
}
|
||||
|
||||
|
||||
inline UInt16 LocalSocketAddressImpl::port() const
|
||||
{
|
||||
throw Poco::InvalidAccessException("local socket address does not have port number");
|
||||
}
|
||||
|
||||
|
||||
inline poco_socklen_t LocalSocketAddressImpl::length() const
|
||||
{
|
||||
return sizeof(struct sockaddr_un);
|
||||
}
|
||||
|
||||
|
||||
inline const struct sockaddr* LocalSocketAddressImpl::addr() const
|
||||
{
|
||||
return reinterpret_cast<const struct sockaddr*>(_pAddr);
|
||||
}
|
||||
|
||||
|
||||
inline int LocalSocketAddressImpl::af() const
|
||||
{
|
||||
return _pAddr->sun_family;
|
||||
}
|
||||
|
||||
|
||||
inline SocketAddressImpl::Family LocalSocketAddressImpl::family() const
|
||||
{
|
||||
return AddressFamily::UNIX_LOCAL;
|
||||
}
|
||||
|
||||
|
||||
inline const char* LocalSocketAddressImpl::path() const
|
||||
{
|
||||
return _pAddr->sun_path;
|
||||
}
|
||||
|
||||
|
||||
#endif // POCO_OS_FAMILY_UNIX
|
||||
|
||||
|
||||
} } } // namespace Poco::Net::Impl
|
||||
|
||||
@@ -132,6 +132,7 @@
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <fcntl.h>
|
||||
#if POCO_OS != POCO_OS_HPUX
|
||||
#include <sys/select.h>
|
||||
@@ -269,15 +270,19 @@
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_SALEN)
|
||||
#define poco_set_sa_len(pSA, len) (pSA)->sa_len = (len)
|
||||
#define poco_set_sin_len(pSA) (pSA)->sin_len = sizeof(struct sockaddr_in)
|
||||
#define poco_set_sa_len(pSA, len) (pSA)->sa_len = (len)
|
||||
#define poco_set_sin_len(pSA) (pSA)->sin_len = sizeof(struct sockaddr_in)
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
#define poco_set_sin6_len(pSA) (pSA)->sin6_len = sizeof(struct sockaddr_in6)
|
||||
#endif
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
#define poco_set_sun_len(pSA, len) (pSA)->sun_len = (len)
|
||||
#endif
|
||||
#else
|
||||
#define poco_set_sa_len(pSA, len) (void) 0
|
||||
#define poco_set_sin_len(pSA) (void) 0
|
||||
#define poco_set_sin6_len(pSA) (void) 0
|
||||
#define poco_set_sa_len(pSA, len) (void) 0
|
||||
#define poco_set_sin_len(pSA) (void) 0
|
||||
#define poco_set_sin6_len(pSA) (void) 0
|
||||
#define poco_set_sun_len(pSA, len) (void) 0
|
||||
#endif
|
||||
|
||||
|
||||
@@ -346,4 +351,32 @@
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Net {
|
||||
|
||||
|
||||
struct AddressFamily
|
||||
/// AddressFamily::Family replaces the previously used IPAddress::Family
|
||||
/// enumeration and is now used for IPAddress::Family and SocketAddress::Family.
|
||||
{
|
||||
enum Family
|
||||
/// Possible address families for socket addresses.
|
||||
{
|
||||
IPv4,
|
||||
/// IPv4 address family.
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
IPv6,
|
||||
/// IPv6 address family.
|
||||
#endif
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
UNIX_LOCAL
|
||||
/// UNIX domain socket address family. Available on UNIX/POSIX platforms only.
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
|
||||
#endif // Net_SocketDefs_INCLUDED
|
||||
|
||||
@@ -84,6 +84,19 @@ public:
|
||||
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||
/// socket option.
|
||||
|
||||
virtual void bind(const SocketAddress& address, bool reuseAddress, bool reusePort );
|
||||
/// Bind a local address to the socket.
|
||||
///
|
||||
/// This is usually only done when establishing a server
|
||||
/// socket. TCP clients should not bind a socket to a
|
||||
/// specific address.
|
||||
///
|
||||
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||
/// socket option.
|
||||
///
|
||||
/// If reusePort is true, sets the SO_REUSEPORT
|
||||
/// socket option.
|
||||
|
||||
virtual void bind6(const SocketAddress& address, bool reuseAddress = false, bool ipV6Only = false);
|
||||
/// Bind a local IPv6 address to the socket.
|
||||
///
|
||||
@@ -101,6 +114,26 @@ public:
|
||||
/// If the library has not been built with IPv6 support,
|
||||
/// a Poco::NotImplementedException will be thrown.
|
||||
|
||||
virtual void bind6(const SocketAddress& address, bool reuseAddress, bool reusePort, bool ipV6Only);
|
||||
/// Bind a local IPv6 address to the socket.
|
||||
///
|
||||
/// This is usually only done when establishing a server
|
||||
/// socket. TCP clients should not bind a socket to a
|
||||
/// specific address.
|
||||
///
|
||||
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||
/// socket option.
|
||||
///
|
||||
/// If reusePort is true, sets the SO_REUSEPORT
|
||||
/// socket option.
|
||||
///
|
||||
/// The given address must be an IPv6 address. The
|
||||
/// IPPROTO_IPV6/IPV6_V6ONLY option is set on the socket
|
||||
/// according to the ipV6Only parameter.
|
||||
///
|
||||
/// If the library has not been built with IPv6 support,
|
||||
/// a Poco::NotImplementedException will be thrown.
|
||||
|
||||
virtual void listen(int backlog = 64);
|
||||
/// Puts the socket into listening state.
|
||||
///
|
||||
@@ -419,11 +452,10 @@ private:
|
||||
SocketImpl& operator = (const SocketImpl&);
|
||||
|
||||
poco_socket_t _sockfd;
|
||||
#if defined(POCO_BROKEN_TIMEOUTS)
|
||||
Poco::Timespan _recvTimeout;
|
||||
Poco::Timespan _sndTimeout;
|
||||
#endif
|
||||
bool _blocking;
|
||||
bool _isBrokenTimeout;
|
||||
|
||||
friend class Socket;
|
||||
friend class SecureSocketImpl;
|
||||
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
/// Creates a stream socket and connects it to
|
||||
/// the socket specified by address.
|
||||
|
||||
explicit StreamSocket(IPAddress::Family family);
|
||||
explicit StreamSocket(SocketAddress::Family family);
|
||||
/// Creates an unconnected stream socket
|
||||
/// for the given address family.
|
||||
///
|
||||
@@ -158,7 +158,7 @@ public:
|
||||
|
||||
StreamSocket(SocketImpl* pImpl);
|
||||
/// Creates the Socket and attaches the given SocketImpl.
|
||||
/// The socket takes owership of the SocketImpl.
|
||||
/// The socket takes ownership of the SocketImpl.
|
||||
///
|
||||
/// The SocketImpl must be a StreamSocketImpl, otherwise
|
||||
/// an InvalidArgumentException will be thrown.
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
StreamSocketImpl();
|
||||
/// Creates a StreamSocketImpl.
|
||||
|
||||
explicit StreamSocketImpl(IPAddress::Family addressFamily);
|
||||
explicit StreamSocketImpl(SocketAddress::Family addressFamily);
|
||||
/// Creates a SocketImpl, with the underlying
|
||||
/// socket initialized for the given address family.
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include "Poco/Net/ServerSocket.h"
|
||||
#include "Poco/Net/TCPServerConnectionFactory.h"
|
||||
#include "Poco/Net/TCPServerParams.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include "Poco/Runnable.h"
|
||||
#include "Poco/Thread.h"
|
||||
#include "Poco/ThreadPool.h"
|
||||
@@ -32,6 +34,35 @@ namespace Net {
|
||||
|
||||
|
||||
class TCPServerDispatcher;
|
||||
class StreamSocket;
|
||||
|
||||
|
||||
class Net_API TCPServerConnectionFilter: public Poco::RefCountedObject
|
||||
/// A TCPServerConnectionFilter can be used to reject incoming connections
|
||||
/// before passing them on to the TCPServerDispatcher and
|
||||
/// starting a thread to handle them.
|
||||
///
|
||||
/// An example use case is white-list or black-list IP address filtering.
|
||||
///
|
||||
/// Subclasses must override the accept() method.
|
||||
{
|
||||
public:
|
||||
typedef Poco::AutoPtr<TCPServerConnectionFilter> Ptr;
|
||||
|
||||
virtual bool accept(const StreamSocket& socket) = 0;
|
||||
/// Returns true if the given StreamSocket connection should
|
||||
/// be handled, and passed on to the TCPServerDispatcher.
|
||||
///
|
||||
/// Returns false if the socket should be closed immediately.
|
||||
///
|
||||
/// The socket can be prevented from being closed immediately
|
||||
/// if false is returned by creating a copy of the socket.
|
||||
/// This can be used to handle certain socket connections in
|
||||
/// a special way, outside the TCPServer framework.
|
||||
|
||||
protected:
|
||||
virtual ~TCPServerConnectionFilter();
|
||||
};
|
||||
|
||||
|
||||
class Net_API TCPServer: public Poco::Runnable
|
||||
@@ -164,6 +195,19 @@ public:
|
||||
Poco::UInt16 port() const;
|
||||
/// Returns the port the server socket listens on.
|
||||
|
||||
void setConnectionFilter(const TCPServerConnectionFilter::Ptr& pFilter);
|
||||
/// Sets a TCPServerConnectionFilter. Can also be used to remove
|
||||
/// a filter by passing a null pointer.
|
||||
///
|
||||
/// To avoid a potential race condition, the filter must
|
||||
/// be set before the TCPServer is started. Trying to set
|
||||
/// the filter after start() has been called will trigger
|
||||
/// an assertion.
|
||||
|
||||
TCPServerConnectionFilter::Ptr getConnectionFilter() const;
|
||||
/// Returns the TCPServerConnectionFilter set with setConnectionFilter(),
|
||||
/// or null pointer if no filter has been set.
|
||||
|
||||
protected:
|
||||
void run();
|
||||
/// Runs the server. The server will run until
|
||||
@@ -179,10 +223,11 @@ private:
|
||||
TCPServer(const TCPServer&);
|
||||
TCPServer& operator = (const TCPServer&);
|
||||
|
||||
ServerSocket _socket;
|
||||
ServerSocket _socket;
|
||||
TCPServerDispatcher* _pDispatcher;
|
||||
Poco::Thread _thread;
|
||||
bool _stopped;
|
||||
TCPServerConnectionFilter::Ptr _pConnectionFilter;
|
||||
Poco::Thread _thread;
|
||||
bool _stopped;
|
||||
};
|
||||
|
||||
|
||||
@@ -201,6 +246,12 @@ inline Poco::UInt16 TCPServer::port() const
|
||||
}
|
||||
|
||||
|
||||
inline TCPServerConnectionFilter::Ptr TCPServer::getConnectionFilter() const
|
||||
{
|
||||
return _pConnectionFilter;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "Poco/Net/StreamSocket.h"
|
||||
#include "Poco/Net/HTTPCredentials.h"
|
||||
#include "Poco/Buffer.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@@ -219,6 +220,21 @@ public:
|
||||
/// The frame flags and opcode (FrameFlags and FrameOpcodes)
|
||||
/// is stored in flags.
|
||||
|
||||
int receiveFrame(Poco::Buffer<char>& buffer, int& flags);
|
||||
/// Receives a frame from the socket and stores it
|
||||
/// after any previous content in buffer.
|
||||
///
|
||||
/// Returns the number of bytes received.
|
||||
/// A return value of 0 means that the peer has
|
||||
/// shut down or closed the connection.
|
||||
///
|
||||
/// Throws a TimeoutException if a receive timeout has
|
||||
/// been set and nothing is received within that interval.
|
||||
/// Throws a NetException (or a subclass) in case of other errors.
|
||||
///
|
||||
/// The frame flags and opcode (FrameFlags and FrameOpcodes)
|
||||
/// is stored in flags.
|
||||
|
||||
Mode mode() const;
|
||||
/// Returns WS_SERVER if the WebSocket is a server-side
|
||||
/// WebSocket, or WS_CLIENT otherwise.
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
|
||||
#include "Poco/Net/StreamSocketImpl.h"
|
||||
#include "Poco/Buffer.h"
|
||||
#include "Poco/Random.h"
|
||||
#include "Poco/Buffer.h"
|
||||
|
||||
@@ -45,12 +46,17 @@ public:
|
||||
virtual int receiveBytes(void* buffer, int length, int flags);
|
||||
/// Receives a WebSocket protocol frame.
|
||||
|
||||
virtual int receiveBytes(Poco::Buffer<char>& buffer, int flags);
|
||||
/// Receives a WebSocket protocol frame.
|
||||
|
||||
virtual SocketImpl* acceptConnection(SocketAddress& clientAddr);
|
||||
virtual void connect(const SocketAddress& address);
|
||||
virtual void connect(const SocketAddress& address, const Poco::Timespan& timeout);
|
||||
virtual void connectNB(const SocketAddress& address);
|
||||
virtual void bind(const SocketAddress& address, bool reuseAddress = false);
|
||||
virtual void bind(const SocketAddress& address, bool reuseAddress, bool reusePort);
|
||||
virtual void bind6(const SocketAddress& address, bool reuseAddress = false, bool ipV6Only = false);
|
||||
virtual void bind6(const SocketAddress& address, bool reuseAddress, bool reusePort, bool ipV6Only);
|
||||
virtual void listen(int backlog = 64);
|
||||
virtual void close();
|
||||
virtual void shutdownReceive();
|
||||
@@ -80,6 +86,8 @@ protected:
|
||||
MAX_HEADER_LENGTH = 14
|
||||
};
|
||||
|
||||
int receiveHeader(char mask[4], bool& useMask);
|
||||
int receivePayload(char *buffer, int payloadLength, char mask[4], bool useMask);
|
||||
int receiveNBytes(void* buffer, int bytes);
|
||||
int receiveSomeBytes(char* buffer, int bytes);
|
||||
virtual ~WebSocketImpl();
|
||||
|
||||
Reference in New Issue
Block a user