1 // **********************************************************************
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
8 // **********************************************************************
10 #ifndef ICE_ENDPOINT_I_H
11 #define ICE_ENDPOINT_I_H
13 #include <IceUtil/Shared.h>
14 #include <IceUtil/Thread.h>
15 #include <IceUtil/Monitor.h>
16 #include <Ice/Endpoint.h>
17 #include <Ice/EndpointIF.h>
18 #include <Ice/InstanceF.h>
19 #include <Ice/TransceiverF.h>
20 #include <Ice/ConnectorF.h>
21 #include <Ice/AcceptorF.h>
22 #include <Ice/Protocol.h>
25 # include <winsock2.h>
27 # include <sys/socket.h> // For struct sockaddr_storage
37 class ICE_API EndpointI_connectors
: public virtual IceUtil::Shared
41 virtual ~EndpointI_connectors() { }
43 virtual void connectors(const std::vector
<ConnectorPtr
>&) = 0;
44 virtual void exception(const Ice::LocalException
&) = 0;
46 typedef IceUtil::Handle
<EndpointI_connectors
> EndpointI_connectorsPtr
;
48 class ICE_API EndpointI
: public Ice::Endpoint
53 // Marshal the endpoint.
55 virtual void streamWrite(BasicStream
*) const = 0;
58 // Return the endpoint type.
60 virtual Ice::Short
type() const = 0;
63 // Return the timeout for the endpoint in milliseconds. 0 means
64 // non-blocking, -1 means no timeout.
66 virtual Ice::Int
timeout() const = 0;
69 // Return a new endpoint with a different timeout value, provided
70 // that timeouts are supported by the endpoint. Otherwise the same
71 // endpoint is returned.
73 virtual EndpointIPtr
timeout(Ice::Int
) const = 0;
76 // Return a new endpoint with a different connection id.
78 virtual EndpointIPtr
connectionId(const ::std::string
&) const = 0;
81 // Return true if the endpoints support bzip2 compress, or false
84 virtual bool compress() const = 0;
87 // Return a new endpoint with a different compression value,
88 // provided that compression is supported by the
89 // endpoint. Otherwise the same endpoint is returned.
91 virtual EndpointIPtr
compress(bool) const = 0;
94 // Return true if the endpoint is datagram-based.
96 virtual bool datagram() const = 0;
99 // Return true if the endpoint is secure.
101 virtual bool secure() const = 0;
104 // Return a server side transceiver for this endpoint, or null if a
105 // transceiver can only be created by an acceptor. In case a
106 // transceiver is created, this operation also returns a new
107 // "effective" endpoint, which might differ from this endpoint,
108 // for example, if a dynamic port number is assigned.
110 virtual TransceiverPtr
transceiver(EndpointIPtr
&) const = 0;
113 // Return connectors for this endpoint, or empty vector if no
114 // connector is available.
116 virtual std::vector
<ConnectorPtr
> connectors() const = 0;
117 virtual void connectors_async(const EndpointI_connectorsPtr
&) const = 0;
120 // Return an acceptor for this endpoint, or null if no acceptors
121 // is available. In case an acceptor is created, this operation
122 // also returns a new "effective" endpoint, which might differ
123 // from this endpoint, for example, if a dynamic port number is
126 virtual AcceptorPtr
acceptor(EndpointIPtr
&, const std::string
&) const = 0;
129 // Expand endpoint out in to separate endpoints for each local
130 // host if listening on INADDR_ANY on server side.
132 virtual std::vector
<EndpointIPtr
> expand() const = 0;
135 // Check whether the endpoint is equivalent to another one.
137 virtual bool equivalent(const EndpointIPtr
&) const = 0;
140 // Compare endpoints for sorting purposes.
142 virtual bool operator==(const Ice::LocalObject
&) const = 0;
143 virtual bool operator<(const Ice::LocalObject
&) const = 0;
144 virtual ::Ice::Int
ice_getHash() const;
148 virtual std::vector
<ConnectorPtr
> connectors(const std::vector
<struct sockaddr_storage
>&) const;
149 friend class EndpointHostResolver
;
152 virtual ::Ice::Int
hashInit() const = 0;
156 mutable bool _hashInitialized
;
157 mutable Ice::Int _hashValue
;
160 inline bool operator==(const EndpointI
& l
, const EndpointI
& r
)
162 return static_cast<const ::Ice::LocalObject
&>(l
) == static_cast<const ::Ice::LocalObject
&>(r
);
165 inline bool operator<(const EndpointI
& l
, const EndpointI
& r
)
167 return static_cast<const ::Ice::LocalObject
&>(l
) < static_cast<const ::Ice::LocalObject
&>(r
);
170 class ICE_API EndpointHostResolver
: public IceUtil::Thread
, public IceUtil::Monitor
<IceUtil::Mutex
>
174 EndpointHostResolver(const InstancePtr
&);
176 void resolve(const std::string
&, int, const EndpointIPtr
&, const EndpointI_connectorsPtr
&);
187 EndpointIPtr endpoint
;
188 EndpointI_connectorsPtr callback
;
191 const InstancePtr _instance
;
193 std::deque
<ResolveEntry
> _queue
;