ICE 3.4.2
[php5-ice-freebsdport.git] / cpp / src / Ice / TcpConnector.cpp
blobc0d34a6f85338cae5b87306a897e72e2d026b6ff
1 // **********************************************************************
2 //
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
4 //
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
7 //
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>
19 using namespace std;
20 using namespace Ice;
21 using namespace IceInternal;
23 TransceiverPtr
24 IceInternal::TcpConnector::connect()
26 if(_traceLevels->network >= 2)
28 Trace out(_logger, _traceLevels->networkCat);
29 out << "trying to establish tcp connection to " << toString();
32 try
34 TransceiverPtr transceiver = new TcpTransceiver(_instance, createSocket(false, _addr.ss_family), false);
35 dynamic_cast<TcpTransceiver*>(transceiver.get())->connect(_addr);
36 return transceiver;
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;
45 throw;
49 Short
50 IceInternal::TcpConnector::type() const
52 return TCPEndpointType;
55 string
56 IceInternal::TcpConnector::toString() const
58 return addrToString(_addr);
61 bool
62 IceInternal::TcpConnector::operator==(const Connector& r) const
64 const TcpConnector* p = dynamic_cast<const TcpConnector*>(&r);
65 if(!p)
67 return false;
70 if(compareAddress(_addr, p->_addr) != 0)
72 return false;
75 if(_timeout != p->_timeout)
77 return false;
80 if(_connectionId != p->_connectionId)
82 return false;
85 return true;
88 bool
89 IceInternal::TcpConnector::operator!=(const Connector& r) const
91 return !operator==(r);
94 bool
95 IceInternal::TcpConnector::operator<(const Connector& r) const
97 const TcpConnector* p = dynamic_cast<const TcpConnector*>(&r);
98 if(!p)
100 return type() < r.type();
103 if(_timeout < p->_timeout)
105 return true;
107 else if(p->_timeout < _timeout)
109 return false;
112 if(_connectionId < p->_connectionId)
114 return true;
116 else if(p->_connectionId < _connectionId)
118 return false;
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) :
125 _instance(instance),
126 _traceLevels(instance->traceLevels()),
127 _logger(instance->initializationData().logger),
128 _addr(addr),
129 _timeout(timeout),
130 _connectionId(connectionId)
134 IceInternal::TcpConnector::~TcpConnector()