diff options
author | Jose <jose@zeroc.com> | 2017-04-11 01:00:31 +0200 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2017-04-11 01:00:31 +0200 |
commit | 9b3573c34f05d2d2d92a7e5acd3e970c67ecced0 (patch) | |
tree | dd15d242557e3492a0e112d956fed8166192eca1 /cpp/src/Ice/UdpTransceiver.cpp | |
parent | Fixed ICE-7755 - listen on all IPs associated with a DNS name (diff) | |
download | ice-9b3573c34f05d2d2d92a7e5acd3e970c67ecced0.tar.bz2 ice-9b3573c34f05d2d2d92a7e5acd3e970c67ecced0.tar.xz ice-9b3573c34f05d2d2d92a7e5acd3e970c67ecced0.zip |
Fix (ICE-7671) - VS 2017 crash when build UWP
Diffstat (limited to 'cpp/src/Ice/UdpTransceiver.cpp')
-rwxr-xr-x | cpp/src/Ice/UdpTransceiver.cpp | 144 |
1 files changed, 91 insertions, 53 deletions
diff --git a/cpp/src/Ice/UdpTransceiver.cpp b/cpp/src/Ice/UdpTransceiver.cpp index 2b36f64d754..ed21c0712b1 100755 --- a/cpp/src/Ice/UdpTransceiver.cpp +++ b/cpp/src/Ice/UdpTransceiver.cpp @@ -381,19 +381,14 @@ IceInternal::UdpTransceiver::startWrite(Buffer& buf) if(!checkIfErrorOrCompleted(SocketOperationConnect, operation)) { operation->Completed = ref new AsyncActionCompletedHandler( - [=] (IAsyncAction^ info, Windows::Foundation::AsyncStatus status) + [this] (IAsyncAction^ info, Windows::Foundation::AsyncStatus status) { - if(status != Windows::Foundation::AsyncStatus::Completed) - { - _write.count = SOCKET_ERROR; - _write.error = info->ErrorCode.Value; - } - else - { - _write.count = 0; - _writer = ref new DataWriter(safe_cast<DatagramSocket^>(_fd)->OutputStream); - } - completed(SocketOperationConnect); + // + // COMPILERFIX with VC141 using operator!= and operator== inside + // a lambda callback triggers a compiler bug, we move the code to + // a seperate private method to workaround the issue. + // + connectCompleted(info, status); }); } else @@ -408,23 +403,14 @@ IceInternal::UdpTransceiver::startWrite(Buffer& buf) if(!checkIfErrorOrCompleted(SocketOperationConnect, operation)) { operation->Completed = ref new AsyncOperationCompletedHandler<IOutputStream^>( - [=] (IAsyncOperation<IOutputStream^>^ info, Windows::Foundation::AsyncStatus status) + [=](IAsyncOperation<IOutputStream^>^ info, Windows::Foundation::AsyncStatus status) { - if(status != Windows::Foundation::AsyncStatus::Completed) - { - _write.count = SOCKET_ERROR; - _write.error = info->ErrorCode.Value; - } - else - { - _write.count = 0; - _writer = ref new DataWriter(info->GetResults()); - } - if(_mcastAddr.host != nullptr) - { - setMcastGroup(_fd, _mcastAddr, ""); - } - completed(SocketOperationConnect); + // + // COMPILERFIX with VC141 using operator!= and operator== inside + // a lambda callback triggers a compiler bug, we move the code to + // a seperate private method to workaround the issue. + // + getOutputStreamMcastCompleted(info, status); }); } else @@ -450,32 +436,14 @@ IceInternal::UdpTransceiver::startWrite(Buffer& buf) { DatagramSocket^ fd = safe_cast<DatagramSocket^>(_fd); concurrency::create_task(fd->GetOutputStreamAsync(_peerAddr.host, _peerAddr.port)).then( - [=,&buf](concurrency::task<IOutputStream^> task) + [=, &buf](concurrency::task<IOutputStream^> task) { - try - { - DataWriter^ writer = ref new DataWriter(task.get()); - writer->WriteBytes(ref new Array<unsigned char>(&*buf.i, static_cast<int>(buf.b.size()))); - DataWriterStoreOperation^ operation = writer->StoreAsync(); - if(operation->Status == Windows::Foundation::AsyncStatus::Completed) - { - // - // NOTE: unlike other methods, it's important to modify _write.count - // _before_ calling checkIfErrorOrCompleted since this isn't called - // with the connection mutex but from a Windows thread pool thread. - // So we can't modify the _write structure after calling the - // completed callback. - // - _write.count = operation->GetResults(); - } - queueOperation(SocketOperationWrite, operation); - } - catch(Platform::Exception^ pex) - { - _write.count = SOCKET_ERROR; - _write.error = pex->HResult; - completed(SocketOperationWrite); - } + // + // COMPILERFIX with VC141 using operator!= and operator== inside + // a lambda callback triggers a compiler bug, we move the code to + // a seperate private method to workaround the issue. + // + getOutputStreamCompleted(task, buf); }); } catch(Platform::Exception^ ex) @@ -549,6 +517,76 @@ IceInternal::UdpTransceiver::startWrite(Buffer& buf) return true; } +#ifdef ICE_OS_UWP +void +IceInternal::UdpTransceiver::connectCompleted(Windows::Foundation::IAsyncAction^ action, + Windows::Foundation::AsyncStatus status) +{ + if(status != Windows::Foundation::AsyncStatus::Completed) + { + _write.count = SOCKET_ERROR; + _write.error = action->ErrorCode.Value; + } + else + { + _write.count = 0; + _writer = ref new DataWriter(safe_cast<DatagramSocket^>(_fd)->OutputStream); + } + completed(SocketOperationConnect); +} + +void +IceInternal::UdpTransceiver::getOutputStreamMcastCompleted(IAsyncOperation<IOutputStream^>^ operation, + Windows::Foundation::AsyncStatus status) +{ + if(status != Windows::Foundation::AsyncStatus::Completed) + { + _write.count = SOCKET_ERROR; + _write.error = operation->ErrorCode.Value; + } + else + { + _write.count = 0; + _writer = ref new DataWriter(operation->GetResults()); + } + if(_mcastAddr.host != nullptr) + { + setMcastGroup(_fd, _mcastAddr, ""); + } + completed(SocketOperationConnect); +} + +void +IceInternal::UdpTransceiver::getOutputStreamCompleted(concurrency::task<IOutputStream^> task, Buffer& buf) +{ + try + { + DataWriter^ writer = ref new DataWriter(task.get()); + writer->WriteBytes(ref new Array<unsigned char>(&*buf.i, static_cast<int>(buf.b.size()))); + DataWriterStoreOperation^ operation = writer->StoreAsync(); + if(operation->Status == Windows::Foundation::AsyncStatus::Completed) + { + // + // NOTE: unlike other methods, it's important to modify _write.count + // _before_ calling checkIfErrorOrCompleted since this isn't called + // with the connection mutex but from a Windows thread pool thread. + // So we can't modify the _write structure after calling the + // completed callback. + // + _write.count = operation->GetResults(); + } + queueOperation(SocketOperationWrite, operation); + } + catch(Platform::Exception^ pex) + { + _write.count = SOCKET_ERROR; + _write.error = pex->HResult; + completed(SocketOperationWrite); + } +} + +#endif + void IceInternal::UdpTransceiver::finishWrite(Buffer& buf) { |