summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/UdpTransceiver.cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2016-06-27 17:54:30 +0200
committerBenoit Foucher <benoit@zeroc.com>2016-06-27 17:54:30 +0200
commitc56f8ab6ca6ca0bdb9536fcce1ef24f1ef40ddc7 (patch)
tree5cb64dfe155e5d2349efb6c7dc4b0f5b5284d44a /cpp/src/Ice/UdpTransceiver.cpp
parentFix Windows php build to restore nuget packages (diff)
downloadice-c56f8ab6ca6ca0bdb9536fcce1ef24f1ef40ddc7.tar.bz2
ice-c56f8ab6ca6ca0bdb9536fcce1ef24f1ef40ddc7.tar.xz
ice-c56f8ab6ca6ca0bdb9536fcce1ef24f1ef40ddc7.zip
Refactored SSL and iAP transports, support for running SSL on top
of TCP/iAP/Bluetooth.
Diffstat (limited to 'cpp/src/Ice/UdpTransceiver.cpp')
-rwxr-xr-x[-rw-r--r--]cpp/src/Ice/UdpTransceiver.cpp134
1 files changed, 30 insertions, 104 deletions
diff --git a/cpp/src/Ice/UdpTransceiver.cpp b/cpp/src/Ice/UdpTransceiver.cpp
index 998ba5cf58f..4c1c277829f 100644..100755
--- a/cpp/src/Ice/UdpTransceiver.cpp
+++ b/cpp/src/Ice/UdpTransceiver.cpp
@@ -40,11 +40,11 @@ IceInternal::UdpTransceiver::getNativeInfo()
return this;
}
-
-#if defined(ICE_USE_IOCP)
+#if defined(ICE_USE_IOCP) || defined(ICE_OS_WINRT)
AsyncInfo*
IceInternal::UdpTransceiver::getAsyncInfo(SocketOperation status)
{
+#if defined(ICE_USE_IOCP)
switch(status)
{
case SocketOperationRead:
@@ -55,26 +55,9 @@ IceInternal::UdpTransceiver::getAsyncInfo(SocketOperation status)
assert(false);
return 0;
}
-}
#elif defined(ICE_OS_WINRT)
-void
-IceInternal::UdpTransceiver::setCompletedHandler(SocketOperationCompletedHandler^ handler)
-{
- _completedHandler = handler;
- _writeOperationCompletedHandler = ref new AsyncOperationCompletedHandler<unsigned int>(
- [=] (IAsyncOperation<unsigned int>^ operation, Windows::Foundation::AsyncStatus status)
- {
- if(status != Windows::Foundation::AsyncStatus::Completed)
- {
- _write.count = SOCKET_ERROR;
- _write.error = operation->ErrorCode.Value;
- }
- else
- {
- _write.count = static_cast<int>(operation->GetResults());
- }
- _completedHandler(SocketOperationWrite);
- });
+ return &_write;
+#endif
}
#endif
@@ -93,7 +76,15 @@ IceInternal::UdpTransceiver::initialize(Buffer& /*readBuffer*/, Buffer& /*writeB
#elif defined(ICE_OS_WINRT)
if(_write.count == SOCKET_ERROR)
{
- checkConnectErrorCode(__FILE__, __LINE__, _write.error, _addr.host);
+ try
+ {
+ checkConnectErrorCode(__FILE__, __LINE__, _write.error);
+ }
+ catch(Ice::DNSException& ex)
+ {
+ ex.host = IceUtil::wstringToString(_addr.host->RawName->Data(), IceUtil::getProcessStringConverter());
+ throw;
+ }
}
#else
doFinishConnect(_fd);
@@ -124,11 +115,10 @@ IceInternal::UdpTransceiver::close()
if(_readPending)
{
assert(_received.empty());
- _completedHandler(SocketOperationRead);
+ completed(SocketOperationRead);
_readPending = false;
}
_received.clear();
- _completedHandler = nullptr;
#endif
assert(_fd != INVALID_SOCKET);
@@ -394,7 +384,6 @@ IceInternal::UdpTransceiver::startWrite(Buffer& buf)
auto operation = safe_cast<DatagramSocket^>(_fd)->ConnectAsync(_addr.host, _addr.port);
if(!checkIfErrorOrCompleted(SocketOperationConnect, operation))
{
- SocketOperationCompletedHandler^ completed = _completedHandler;
operation->Completed = ref new AsyncActionCompletedHandler(
[=] (IAsyncAction^ info, Windows::Foundation::AsyncStatus status)
{
@@ -422,7 +411,6 @@ IceInternal::UdpTransceiver::startWrite(Buffer& buf)
auto operation = safe_cast<DatagramSocket^>(_fd)->GetOutputStreamAsync(_addr.host, _addr.port);
if(!checkIfErrorOrCompleted(SocketOperationConnect, operation))
{
- SocketOperationCompletedHandler^ completed = _completedHandler;
operation->Completed = ref new AsyncOperationCompletedHandler<IOutputStream^>(
[=] (IAsyncOperation<IOutputStream^>^ info, Windows::Foundation::AsyncStatus status)
{
@@ -456,7 +444,7 @@ IceInternal::UdpTransceiver::startWrite(Buffer& buf)
}
catch(Platform::Exception^ ex)
{
- checkConnectErrorCode(__FILE__, __LINE__, ex->HResult, _addr.host);
+ checkConnectErrorCode(__FILE__, __LINE__, ex->HResult);
}
return false;
}
@@ -464,7 +452,6 @@ IceInternal::UdpTransceiver::startWrite(Buffer& buf)
{
try
{
- SocketOperationCompletedHandler^ completed = _completedHandler;
DatagramSocket^ fd = safe_cast<DatagramSocket^>(_fd);
concurrency::create_task(fd->GetOutputStreamAsync(_peerAddr.host, _peerAddr.port)).then(
[=,&buf](concurrency::task<IOutputStream^> task)
@@ -474,35 +461,18 @@ IceInternal::UdpTransceiver::startWrite(Buffer& buf)
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();
-
- Windows::Foundation::AsyncStatus status = operation->Status;
- if(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();
- completed(SocketOperationWrite);
- }
- else if(status == Windows::Foundation::AsyncStatus::Started)
- {
- operation->Completed = _writeOperationCompletedHandler;
- }
- else
- {
- if(_state < StateConnected)
- {
- checkConnectErrorCode(__FILE__, __LINE__, operation->ErrorCode.Value, _addr.host);
- }
- else
- {
- checkErrorCode(__FILE__, __LINE__, operation->ErrorCode.Value);
- }
- }
+ 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)
{
@@ -523,15 +493,7 @@ IceInternal::UdpTransceiver::startWrite(Buffer& buf)
try
{
_writer->WriteBytes(ref new Array<unsigned char>(&*buf.i, static_cast<int>(buf.b.size())));
- DataWriterStoreOperation^ operation = _writer->StoreAsync();
- if(checkIfErrorOrCompleted(SocketOperationWrite, operation))
- {
- _write.count = operation->GetResults();
- }
- else
- {
- operation->Completed = _writeOperationCompletedHandler;
- }
+ queueOperation(SocketOperationWrite, _writer->StoreAsync());
}
catch(Platform::Exception^ ex)
{
@@ -675,7 +637,7 @@ IceInternal::UdpTransceiver::startRead(Buffer& buf)
assert(!_readPending);
if(!_received.empty())
{
- _completedHandler(SocketOperationRead);
+ completed(SocketOperationRead);
}
else
{
@@ -1147,42 +1109,6 @@ IceInternal::UdpTransceiver::setBufSize(int rcvSize, int sndSize)
}
#ifdef ICE_OS_WINRT
-bool
-IceInternal::UdpTransceiver::checkIfErrorOrCompleted(SocketOperation op, IAsyncInfo^ info)
-{
- //
- // NOTE: It's important to only check for info->Status once as it
- // might change during the checks below (the Status can be changed
- // by the Windows thread pool concurrently).
- //
- // We consider that a canceled async status is the same as an
- // error. A canceled async status can occur if there's a timeout
- // and the socket is closed.
- //
- Windows::Foundation::AsyncStatus status = info->Status;
- if(status == Windows::Foundation::AsyncStatus::Completed)
- {
- _completedHandler(op);
- return true;
- }
- else if(status == Windows::Foundation::AsyncStatus::Started)
- {
- return false;
- }
- else
- {
- if(_state < StateConnected)
- {
- checkConnectErrorCode(__FILE__, __LINE__, info->ErrorCode.Value, _addr.host);
- }
- else
- {
- checkErrorCode(__FILE__, __LINE__, info->ErrorCode.Value);
- }
- return true; // Prevent compiler warning.
- }
-}
-
void
IceInternal::UdpTransceiver::appendMessage(DatagramSocketMessageReceivedEventArgs^ args)
{
@@ -1202,7 +1128,7 @@ IceInternal::UdpTransceiver::appendMessage(DatagramSocketMessageReceivedEventArg
//
if(_readPending)
{
- _completedHandler(SocketOperationRead);
+ completed(SocketOperationRead);
_readPending = false;
}
}