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 #include <Ice/TcpConnector.h>
11 #include <Ice/TcpTransceiver.h>
12 #include <Ice/TcpEndpointI.h>
13 #include <Ice/Instance.h>
14 #include <Ice/TraceLevels.h>
15 #include <Ice/LoggerUtil.h>
16 #include <Ice/Network.h>
17 #include <Ice/Exception.h>
21 using namespace IceInternal
;
24 IceInternal::TcpConnector::connect()
26 if(_traceLevels
->network
>= 2)
28 Trace
out(_logger
, _traceLevels
->networkCat
);
29 out
<< "trying to establish tcp connection to " << toString();
34 TransceiverPtr transceiver
= new TcpTransceiver(_instance
, createSocket(false, _addr
.ss_family
), false);
35 dynamic_cast<TcpTransceiver
*>(transceiver
.get())->connect(_addr
);
38 catch(const Ice::LocalException
& ex
)
40 if(_traceLevels
->network
>= 2)
42 Trace
out(_logger
, _traceLevels
->networkCat
);
43 out
<< "failed to establish tcp connection to " << toString() << "\n" << ex
;
50 IceInternal::TcpConnector::type() const
52 return TCPEndpointType
;
56 IceInternal::TcpConnector::toString() const
58 return addrToString(_addr
);
62 IceInternal::TcpConnector::operator==(const Connector
& r
) const
64 const TcpConnector
* p
= dynamic_cast<const TcpConnector
*>(&r
);
70 if(compareAddress(_addr
, p
->_addr
) != 0)
75 if(_timeout
!= p
->_timeout
)
80 if(_connectionId
!= p
->_connectionId
)
89 IceInternal::TcpConnector::operator!=(const Connector
& r
) const
91 return !operator==(r
);
95 IceInternal::TcpConnector::operator<(const Connector
& r
) const
97 const TcpConnector
* p
= dynamic_cast<const TcpConnector
*>(&r
);
100 return type() < r
.type();
103 if(_timeout
< p
->_timeout
)
107 else if(p
->_timeout
< _timeout
)
112 if(_connectionId
< p
->_connectionId
)
116 else if(p
->_connectionId
< _connectionId
)
120 return compareAddress(_addr
, p
->_addr
) == -1;
123 IceInternal::TcpConnector::TcpConnector(const InstancePtr
& instance
, const struct sockaddr_storage
& addr
,
124 Ice::Int timeout
, const string
& connectionId
) :
126 _traceLevels(instance
->traceLevels()),
127 _logger(instance
->initializationData().logger
),
130 _connectionId(connectionId
)
134 IceInternal::TcpConnector::~TcpConnector()