diff options
author | Benoit Foucher <benoit@zeroc.com> | 2016-05-31 08:59:20 +0200 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2016-05-31 08:59:20 +0200 |
commit | 9f99bad130508d529814c778852621f6a1b814cc (patch) | |
tree | 4fa8328539c80f719cca38a0fb7f67b2995618fc /cpp/src/Ice/ios/StreamAcceptor.cpp | |
parent | PHP 7 fix for printing Exception info (diff) | |
download | ice-9f99bad130508d529814c778852621f6a1b814cc.tar.bz2 ice-9f99bad130508d529814c778852621f6a1b814cc.tar.xz ice-9f99bad130508d529814c778852621f6a1b814cc.zip |
Added support for building Xcode SDK, added iAP transport
Diffstat (limited to 'cpp/src/Ice/ios/StreamAcceptor.cpp')
-rw-r--r-- | cpp/src/Ice/ios/StreamAcceptor.cpp | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/cpp/src/Ice/ios/StreamAcceptor.cpp b/cpp/src/Ice/ios/StreamAcceptor.cpp new file mode 100644 index 00000000000..3d1a4a956b0 --- /dev/null +++ b/cpp/src/Ice/ios/StreamAcceptor.cpp @@ -0,0 +1,160 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved. +// +// This copy of Ice Touch is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include "StreamTransceiver.h" +#include "StreamEndpointI.h" +#include "StreamAcceptor.h" + +#include <IceUtil/StringUtil.h> + +#include <Ice/Instance.h> +#include <Ice/Network.h> +#include <Ice/Exception.h> +#include <Ice/Properties.h> + +#include <CoreFoundation/CoreFoundation.h> + +using namespace std; +using namespace Ice; +using namespace IceInternal; + +NativeInfoPtr +IceObjC::StreamAcceptor::getNativeInfo() +{ + return this; +} + +void +IceObjC::StreamAcceptor::close() +{ + if(_fd != INVALID_SOCKET) + { + closeSocketNoThrow(_fd); + _fd = INVALID_SOCKET; + } +} + +EndpointIPtr +IceObjC::StreamAcceptor::listen() +{ + try + { + const_cast<Address&>(_addr) = doBind(_fd, _addr); + doListen(_fd, _backlog); + } + catch(...) + { + _fd = INVALID_SOCKET; + throw; + } + + _endpoint = _endpoint->endpoint(this); + return _endpoint; +} + +TransceiverPtr +IceObjC::StreamAcceptor::accept() +{ + SOCKET fd = doAccept(_fd); + setBlock(fd, false); + setTcpBufSize(fd, _instance); + + // + // Create the read/write streams + // + CFReadStreamRef readStream = nil; + CFWriteStreamRef writeStream = nil; + try + { + CFStreamCreatePairWithSocket(NULL, fd, &readStream, &writeStream); + _instance->setupStreams(readStream, writeStream, true, ""); + return new StreamTransceiver(_instance, readStream, writeStream, fd); + } + catch(const Ice::LocalException& ex) + { + if(fd != INVALID_SOCKET) + { + closeSocketNoThrow(fd); + } + if(readStream) + { + CFRelease(readStream); + } + if(writeStream) + { + CFRelease(writeStream); + } + throw; + } +} + +string +IceObjC::StreamAcceptor::protocol() const +{ + return _instance->protocol(); +} + +string +IceObjC::StreamAcceptor::toString() const +{ + return addrToString(_addr); +} + +string +IceObjC::StreamAcceptor::toDetailedString() const +{ + ostringstream os; + os << "local address = " << toString(); + vector<string> intfs = getHostsForEndpointExpand(inetAddrToString(_addr), _instance->protocolSupport(), true); + if(!intfs.empty()) + { + os << "\nlocal interfaces = "; + os << IceUtilInternal::joinString(intfs, ", "); + } + return os.str(); +} + +int +IceObjC::StreamAcceptor::effectivePort() const +{ + return getPort(_addr); +} + +IceObjC::StreamAcceptor::StreamAcceptor(const StreamEndpointIPtr& endpoint, + const InstancePtr& instance, + const string& host, + int port) : + _endpoint(endpoint), + _instance(instance), + _addr(getAddressForServer(host, port, instance->protocolSupport(), instance->preferIPv6())) +{ +#ifdef SOMAXCONN + _backlog = instance->properties()->getPropertyAsIntWithDefault("Ice.TCP.Backlog", SOMAXCONN); +#else + _backlog = instance->properties()->getPropertyAsIntWithDefault("Ice.TCP.Backlog", 511); +#endif + + try + { + _fd = createSocket(false, _addr); + setBlock(_fd, false); + setTcpBufSize(_fd, _instance); + setReuseAddress(_fd, true); + } + catch(...) + { + _fd = INVALID_SOCKET; + throw; + } +} + +IceObjC::StreamAcceptor::~StreamAcceptor() +{ + assert(_fd == INVALID_SOCKET); +} |