summaryrefslogtreecommitdiff
path: root/cs/src
diff options
context:
space:
mode:
Diffstat (limited to 'cs/src')
-rw-r--r--cs/src/Glacier2/Application.cs3
-rw-r--r--cs/src/Glacier2/SessionHelper.cs6
-rw-r--r--cs/src/Ice/Application.cs3
-rw-r--r--cs/src/Ice/Arrays.cs58
-rw-r--r--cs/src/Ice/AssemblyUtil.cs29
-rw-r--r--cs/src/Ice/AsyncIOThread.cs11
-rw-r--r--cs/src/Ice/BasicStream.cs136
-rw-r--r--cs/src/Ice/ByteBuffer.cs42
-rw-r--r--cs/src/Ice/ConnectionFactory.cs8
-rw-r--r--cs/src/Ice/ConnectionI.cs2
-rw-r--r--cs/src/Ice/EndpointFactoryManager.cs6
-rw-r--r--cs/src/Ice/EndpointHostResolver.cs4
-rw-r--r--cs/src/Ice/EndpointI.cs2
-rw-r--r--cs/src/Ice/EventHandler.cs1
-rw-r--r--cs/src/Ice/ImplicitContextI.cs72
-rw-r--r--cs/src/Ice/Instance.cs63
-rw-r--r--cs/src/Ice/LinkedList.cs304
-rw-r--r--cs/src/Ice/LocatorInfo.cs53
-rw-r--r--cs/src/Ice/LoggerI.cs23
-rw-r--r--cs/src/Ice/Makefile1
-rw-r--r--cs/src/Ice/Makefile.mak1
-rw-r--r--cs/src/Ice/Monitor.cs150
-rw-r--r--cs/src/Ice/Network.cs496
-rw-r--r--cs/src/Ice/Object.cs2
-rw-r--r--cs/src/Ice/ObjectFactoryManager.cs20
-rw-r--r--cs/src/Ice/Options.cs6
-rw-r--r--cs/src/Ice/OutgoingAsync.cs4
-rw-r--r--cs/src/Ice/OutputBase.cs10
-rw-r--r--cs/src/Ice/PluginManagerI.cs2
-rw-r--r--cs/src/Ice/PropertiesI.cs111
-rw-r--r--cs/src/Ice/ProtocolPluginFacade.cs5
-rw-r--r--cs/src/Ice/Reference.cs77
-rw-r--r--cs/src/Ice/ReferenceFactory.cs24
-rw-r--r--cs/src/Ice/SliceChecksums.cs2
-rw-r--r--cs/src/Ice/SysLoggerI.cs6
-rw-r--r--cs/src/Ice/TcpAcceptor.cs22
-rw-r--r--cs/src/Ice/TcpConnector.cs19
-rw-r--r--cs/src/Ice/TcpEndpointI.cs14
-rw-r--r--cs/src/Ice/TcpTransceiver.cs211
-rw-r--r--cs/src/Ice/ThreadPool.cs37
-rw-r--r--cs/src/Ice/Time.cs17
-rw-r--r--cs/src/Ice/Timer.cs53
-rw-r--r--cs/src/Ice/UdpConnector.cs14
-rw-r--r--cs/src/Ice/UdpEndpointI.cs11
-rw-r--r--cs/src/Ice/UdpTransceiver.cs261
-rw-r--r--cs/src/Ice/Util.cs12
-rw-r--r--cs/src/Ice/ValueWriter.cs15
-rw-r--r--cs/src/IceSSL/AcceptorI.cs12
-rw-r--r--cs/src/IceSSL/ConnectorI.cs2
-rw-r--r--cs/src/IceSSL/EndpointI.cs6
-rw-r--r--cs/src/IceSSL/TransceiverI.cs52
-rw-r--r--cs/src/Makefile.mak8
-rw-r--r--cs/src/PolicyServer/AssemblyInfo.cs45
-rw-r--r--cs/src/PolicyServer/Makefile.mak39
-rw-r--r--cs/src/PolicyServer/PolicyServer.cs127
55 files changed, 1660 insertions, 1060 deletions
diff --git a/cs/src/Glacier2/Application.cs b/cs/src/Glacier2/Application.cs
index 7f85daace27..54fd27c658d 100644
--- a/cs/src/Glacier2/Application.cs
+++ b/cs/src/Glacier2/Application.cs
@@ -12,6 +12,8 @@ using System.Diagnostics;
using System.Collections.Generic;
using System.Threading;
+#if !SILVERLIGHT
+
namespace Glacier2
{
@@ -572,3 +574,4 @@ public abstract class Application : Ice.Application
}
}
+#endif
diff --git a/cs/src/Glacier2/SessionHelper.cs b/cs/src/Glacier2/SessionHelper.cs
index 7d2a98bca02..0df336aab71 100644
--- a/cs/src/Glacier2/SessionHelper.cs
+++ b/cs/src/Glacier2/SessionHelper.cs
@@ -75,7 +75,7 @@ public class SessionHelper
if(!_done)
{
-#if COMPACT
+#if COMPACT || SILVERLIGHT
_m.TimedWait(_period);
#else
try
@@ -445,7 +445,7 @@ public class SessionHelper
sessionRefresh.done();
while(true)
{
-#if COMPACT
+#if COMPACT || SILVERLIGHT
_refreshThread.Join();
break;
#else
@@ -563,7 +563,7 @@ public class SessionHelper
{
if(_initData.dispatcher != null)
{
- EventWaitHandle h = new EventWaitHandle(false, EventResetMode.ManualReset);
+ EventWaitHandle h = new ManualResetEvent(false);
_initData.dispatcher(delegate()
{
callback();
diff --git a/cs/src/Ice/Application.cs b/cs/src/Ice/Application.cs
index 89002e5b0d5..8a4e4248ef0 100644
--- a/cs/src/Ice/Application.cs
+++ b/cs/src/Ice/Application.cs
@@ -7,6 +7,8 @@
//
// **********************************************************************
+#if !SILVERLIGHT
+
namespace Ice
{
using System;
@@ -1008,3 +1010,4 @@ namespace Ice
delegate bool CtrlCEventHandler(int sig);
}
+#endif
diff --git a/cs/src/Ice/Arrays.cs b/cs/src/Ice/Arrays.cs
index ff25aa479a6..f737531878e 100644
--- a/cs/src/Ice/Arrays.cs
+++ b/cs/src/Ice/Arrays.cs
@@ -111,63 +111,5 @@ namespace IceUtilInternal
return h;
}
-
- public static void Sort(ref ArrayList array, IComparer comparator)
- {
- //
- // This Sort method implements the merge sort algorithm
- // which is a stable sort (unlike the Sort method of the
- // System.Collections.ArrayList which is unstable).
- //
- Sort1(ref array, 0, array.Count, comparator);
- }
-
- private static void Sort1(ref ArrayList array, int begin, int end, IComparer comparator)
- {
- int mid;
- if(end - begin <= 1)
- {
- return;
- }
-
- mid = (begin + end) / 2;
- Sort1(ref array, begin, mid, comparator);
- Sort1(ref array, mid, end, comparator);
- Merge(ref array, begin, mid, end, comparator);
- }
-
- private static void Merge(ref ArrayList array, int begin, int mid, int end, IComparer comparator)
- {
- int i = begin;
- int j = mid;
- int k = 0;
-
- object[] tmp = new object[end - begin];
- while(i < mid && j < end)
- {
- if(comparator.Compare(array[i], array[j]) <= 0)
- {
- tmp[k++] = array[i++];
- }
- else
- {
- tmp[k++] = array[j++];
- }
- }
-
- while(i < mid)
- {
- tmp[k++] = array[i++];
- }
- while(j < end)
- {
- tmp[k++] = array[j++];
- }
- for(i = 0; i < (end - begin); ++i)
- {
- array[begin + i] = tmp[i];
- }
- }
}
-
}
diff --git a/cs/src/Ice/AssemblyUtil.cs b/cs/src/Ice/AssemblyUtil.cs
index f6e3fd39be6..e0ba2b094ac 100644
--- a/cs/src/Ice/AssemblyUtil.cs
+++ b/cs/src/Ice/AssemblyUtil.cs
@@ -56,8 +56,7 @@ namespace IceInternal
xp_ = v.Major == 5 && v.Minor == 1; // Are we running on XP?
osx_ = false;
-
-#if COMPACT
+#if COMPACT || SILVERLIGHT
//
// Populate the _iceAssemblies list with the fully-qualified names
// of the standard Ice assemblies. The fully-qualified name looks
@@ -82,7 +81,7 @@ namespace IceInternal
_iceAssemblies.Add("IceStorm," + suffix);
}
#else
- if(platform_ == Platform.NonWindows)
+ if (platform_ == Platform.NonWindows)
{
try
{
@@ -113,18 +112,18 @@ namespace IceInternal
public static Type findType(Instance instance, string csharpId)
{
-#if !COMPACT
+#if !COMPACT && !SILVERLIGHT
loadAssemblies(); // Lazy initialization
#endif
lock(_mutex)
{
- Type t = (Type)_typeTable[csharpId];
- if(t != null)
+ Type t;
+ if (_typeTable.TryGetValue(csharpId, out t))
{
return t;
}
-#if COMPACT
+#if COMPACT || SILVERLIGHT
string[] assemblies = instance.factoryAssemblies();
for(int i = 0; i < assemblies.Length; ++i)
{
@@ -151,7 +150,7 @@ namespace IceInternal
}
}
#else
- foreach(Assembly a in _loadedAssemblies.Values)
+ foreach (Assembly a in _loadedAssemblies.Values)
{
if((t = a.GetType(csharpId)) != null)
{
@@ -164,10 +163,10 @@ namespace IceInternal
return null;
}
-#if !COMPACT
+#if !COMPACT && !SILVERLIGHT
public static Type[] findTypesWithPrefix(string prefix)
{
- IceUtilInternal.LinkedList l = new IceUtilInternal.LinkedList();
+ LinkedList<Type> l = new LinkedList<Type>();
loadAssemblies(); // Lazy initialization
@@ -180,7 +179,7 @@ namespace IceInternal
{
if(t.AssemblyQualifiedName.IndexOf(prefix, StringComparison.Ordinal) == 0)
{
- l.Add(t);
+ l.AddLast(t);
}
}
}
@@ -207,7 +206,7 @@ namespace IceInternal
}
}
-#if !COMPACT
+#if !COMPACT && !SILVERLIGHT
//
// Make sure that all assemblies that are referenced by this process
// are actually loaded. This is necessary so we can use reflection
@@ -242,7 +241,7 @@ namespace IceInternal
AssemblyName[] names = a.GetReferencedAssemblies();
foreach(AssemblyName name in names)
{
- if(!_loadedAssemblies.Contains(name.FullName))
+ if(!_loadedAssemblies.ContainsKey(name.FullName))
{
try
{
@@ -263,8 +262,8 @@ namespace IceInternal
#else
private static List<string> _iceAssemblies = new List<string>();
#endif
- private static Hashtable _typeTable = new Hashtable(); // <type name, Type> pairs.
- private static Mutex _mutex = new Mutex();
+ private static Dictionary<string, Type> _typeTable = new Dictionary<string, Type>(); // <type name, Type> pairs.
+ private static Object _mutex = new Object();
public readonly static Runtime runtime_; // Either DotNET or Mono
//
diff --git a/cs/src/Ice/AsyncIOThread.cs b/cs/src/Ice/AsyncIOThread.cs
index 56def39ff3d..fe003a90ef9 100644
--- a/cs/src/Ice/AsyncIOThread.cs
+++ b/cs/src/Ice/AsyncIOThread.cs
@@ -22,6 +22,7 @@ namespace IceInternal
_instance = instance;
_thread = new HelperThread(this);
+#if !SILVERLIGHT
if(instance.initializationData().properties.getProperty("Ice.ThreadPriority").Length > 0)
{
ThreadPriority priority = IceInternal.Util.stringToThreadPriority(
@@ -32,7 +33,9 @@ namespace IceInternal
{
_thread.Start(ThreadPriority.Normal);
}
-
+#else
+ _thread.Start();
+#endif
}
public void queue(ThreadPoolWorkItem callback)
@@ -143,12 +146,18 @@ namespace IceInternal
_thread.Join();
}
+#if !SILVERLIGHT
public void Start(ThreadPriority priority)
+#else
+ public void Start()
+#endif
{
_thread = new Thread(new ThreadStart(Run));
_thread.IsBackground = true;
_thread.Name = _name;
+#if !SILVERLIGHT
_thread.Priority = priority;
+#endif
_thread.Start();
}
diff --git a/cs/src/Ice/BasicStream.cs b/cs/src/Ice/BasicStream.cs
index 78c7ba2aecb..802ae64c8f2 100644
--- a/cs/src/Ice/BasicStream.cs
+++ b/cs/src/Ice/BasicStream.cs
@@ -15,14 +15,14 @@ namespace IceInternal
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
-#if !COMPACT
+#if !COMPACT && !SILVERLIGHT
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
#endif
using System.Threading;
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
internal static class NativeMethods
{
[DllImport("bzip2.dll")]
@@ -52,7 +52,7 @@ namespace IceInternal
static BasicStream()
{
-#if MANAGED || COMPACT
+#if MANAGED || COMPACT || SILVERLIGHT
//
// Protocol compression is not supported when using managed code.
//
@@ -234,7 +234,7 @@ namespace IceInternal
other._minSeqSize = _minSeqSize;
_minSeqSize = tmpMinSeqSize;
- ArrayList tmpObjectList = other._objectList;
+ List<Ice.Object> tmpObjectList = other._objectList;
other._objectList = _objectList;
_objectList = tmpObjectList;
@@ -597,15 +597,15 @@ namespace IceInternal
throw new Ice.MarshalException("type ids require an encapsulation");
}
- object o = _writeEncapsStack.typeIdMap[id];
- if(o != null)
+ int index;
+ if(_writeEncapsStack.typeIdMap.TryGetValue(id, out index))
{
writeBool(true);
- writeSize((int)o);
+ writeSize(index);
}
else
{
- int index = ++_writeEncapsStack.typeIdIndex;
+ index = ++_writeEncapsStack.typeIdIndex;
_writeEncapsStack.typeIdMap[id] = index;
writeBool(false);
writeString(id);
@@ -625,8 +625,7 @@ namespace IceInternal
if(isIndex)
{
index = readSize();
- id = (string)_readEncapsStack.typeIdMap[index];
- if(id == null)
+ if(!_readEncapsStack.typeIdMap.TryGetValue(index, out id))
{
throw new Ice.UnmarshalOutOfBoundsException("Missing type ID");
}
@@ -769,7 +768,7 @@ namespace IceInternal
public void writeSerializable(object o)
{
-#if !COMPACT
+#if !COMPACT && !SILVERLIGHT
if(o == null)
{
writeSize(0);
@@ -874,7 +873,7 @@ namespace IceInternal
public object readSerializable()
{
-#if !COMPACT
+#if !COMPACT && !SILVERLIGHT
int sz = readAndCheckSeqSize(1);
if(sz == 0)
{
@@ -2049,35 +2048,33 @@ namespace IceInternal
if(_writeEncapsStack.toBeMarshaledMap == null) // Lazy initialization
{
- _writeEncapsStack.toBeMarshaledMap = new Hashtable();
- _writeEncapsStack.marshaledMap = new Hashtable();
- _writeEncapsStack.typeIdMap = new Hashtable();
+ _writeEncapsStack.toBeMarshaledMap = new Dictionary<Ice.Object, int>();
+ _writeEncapsStack.marshaledMap = new Dictionary<Ice.Object, int>();
+ _writeEncapsStack.typeIdMap = new Dictionary<string, int>();
}
if(v != null)
{
//
- // Look for this instance in the to-be-marshaled map.
- //
- object p = _writeEncapsStack.toBeMarshaledMap[v];
- if(p == null)
- {
- //
- // Didn't find it, try the marshaled map next.
- //
- object q = _writeEncapsStack.marshaledMap[v];
- if(q == null)
+ // Look for this instance in the to-be-marshaled map.
+ //
+ int p;
+ if(!_writeEncapsStack.toBeMarshaledMap.TryGetValue(v, out p))
+ {
+ //
+ // Didn't find it, try the marshaled map next.
+ //
+ if(!_writeEncapsStack.marshaledMap.TryGetValue(v, out p))
{
- //
- // We haven't seen this instance previously,
- // create a new index, and insert it into the
- // to-be-marshaled map.
- //
- q = ++_writeEncapsStack.writeIndex;
- _writeEncapsStack.toBeMarshaledMap[v] = q;
- }
- p = q;
- }
- writeInt(-((int)p));
+ //
+ // We haven't seen this instance previously,
+ // create a new index, and insert it into the
+ // to-be-marshaled map.
+ //
+ p = ++_writeEncapsStack.writeIndex;
+ _writeEncapsStack.toBeMarshaledMap[v] = p;
+ }
+ }
+ writeInt(-p);
}
else
{
@@ -2104,9 +2101,9 @@ namespace IceInternal
if(_readEncapsStack.patchMap == null) // Lazy initialization
{
- _readEncapsStack.patchMap = new Hashtable();
- _readEncapsStack.unmarshaledMap = new Hashtable();
- _readEncapsStack.typeIdMap = new Hashtable();
+ _readEncapsStack.patchMap = new Dictionary<int, List<IceInternal.IPatcher> >();
+ _readEncapsStack.unmarshaledMap = new Dictionary<int, Ice.Object>();
+ _readEncapsStack.typeIdMap = new Dictionary<int, string>();
}
int index = readInt();
@@ -2122,15 +2119,15 @@ namespace IceInternal
if(index < 0)
{
int i = -index;
- IceUtilInternal.LinkedList patchlist = (IceUtilInternal.LinkedList)_readEncapsStack.patchMap[i];
- if(patchlist == null)
+ List<IceInternal.IPatcher> patchlist;
+ if(!_readEncapsStack.patchMap.TryGetValue(i, out patchlist))
{
//
// We have no outstanding instances to be patched
// for this index, so make a new entry in the
// patch map.
//
- patchlist = new IceUtilInternal.LinkedList();
+ patchlist = new List<IceInternal.IPatcher>();
_readEncapsStack.patchMap[i] = patchlist;
}
//
@@ -2241,7 +2238,7 @@ namespace IceInternal
//
if(_objectList == null)
{
- _objectList = new ArrayList();
+ _objectList = new List<Ice.Object>();
}
_objectList.Add(v);
@@ -2346,9 +2343,10 @@ namespace IceInternal
{
while(_writeEncapsStack.toBeMarshaledMap.Count > 0)
{
- Hashtable savedMap = new Hashtable(_writeEncapsStack.toBeMarshaledMap);
+ Dictionary<Ice.Object, int> savedMap =
+ new Dictionary<Ice.Object, int>(_writeEncapsStack.toBeMarshaledMap);
writeSize(savedMap.Count);
- foreach(DictionaryEntry e in savedMap)
+ foreach(KeyValuePair<Ice.Object, int> e in savedMap)
{
//
// Add an instance from the old
@@ -2367,7 +2365,7 @@ namespace IceInternal
// pass, substract what we have marshaled from the
// toBeMarshaledMap.
//
- foreach(DictionaryEntry e in savedMap)
+ foreach(KeyValuePair<Ice.Object, int> e in savedMap)
{
_writeEncapsStack.toBeMarshaledMap.Remove(e.Key);
}
@@ -2452,10 +2450,10 @@ namespace IceInternal
// must be null.) Patch any pointers in the patch map with
// the new address.
//
- Debug.Assert( ((object)instanceIndex != null && (object)patchIndex == null)
- || ((object)instanceIndex == null && (object)patchIndex != null));
-
- IceUtilInternal.LinkedList patchlist;
+ Debug.Assert(((object)instanceIndex != null && (object)patchIndex == null) ||
+ ((object)instanceIndex == null && (object)patchIndex != null));
+
+ List<IceInternal.IPatcher> patchlist;
Ice.Object v;
if((object)instanceIndex != null)
{
@@ -2463,12 +2461,11 @@ namespace IceInternal
// We have just unmarshaled an instance -- check if
// something needs patching for that instance.
//
- patchlist = (IceUtilInternal.LinkedList)_readEncapsStack.patchMap[instanceIndex];
- if(patchlist == null)
+ if(!_readEncapsStack.patchMap.TryGetValue((int)instanceIndex, out patchlist))
{
return; // We don't have anything to patch for the instance just unmarshaled.
}
- v = (Ice.Object)_readEncapsStack.unmarshaledMap[instanceIndex];
+ v = _readEncapsStack.unmarshaledMap[(int)instanceIndex];
patchIndex = instanceIndex;
}
else
@@ -2477,12 +2474,11 @@ namespace IceInternal
// We have just unmarshaled an index -- check if we
// have unmarshaled the instance for that index yet.
//
- v = (Ice.Object)_readEncapsStack.unmarshaledMap[patchIndex];
- if(v == null)
+ if(!_readEncapsStack.unmarshaledMap.TryGetValue((int)patchIndex, out v))
{
return; // We haven't unmarshaled the instance for this index yet.
}
- patchlist = (IceUtilInternal.LinkedList)_readEncapsStack.patchMap[patchIndex];
+ patchlist = _readEncapsStack.patchMap[(int)patchIndex];
}
Debug.Assert(patchlist != null && patchlist.Count > 0);
Debug.Assert(v != null);
@@ -2516,10 +2512,10 @@ namespace IceInternal
// nothing left to patch for that index for the time
// being.
//
- _readEncapsStack.patchMap.Remove(patchIndex);
+ _readEncapsStack.patchMap.Remove((int)patchIndex);
}
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
static string getBZ2Error(int error)
{
string rc;
@@ -2588,7 +2584,7 @@ namespace IceInternal
public bool compress(ref BasicStream cstream, int headerSize, int compressionLevel)
{
-#if MANAGED || COMPACT
+#if MANAGED || COMPACT || SILVERLIGHT
cstream = this;
return false;
#else
@@ -2656,7 +2652,7 @@ namespace IceInternal
public BasicStream uncompress(int headerSize)
{
-#if MANAGED || COMPACT
+#if MANAGED || COMPACT || SILVERLIGHT
return this;
#else
if(!_bzlibInstalled)
@@ -2837,8 +2833,7 @@ namespace IceInternal
lock(_exceptionFactories)
{
- factory = (UserExceptionFactory)_exceptionFactories[id];
- if(factory == null)
+ if(!_exceptionFactories.TryGetValue(id, out factory))
{
try
{
@@ -2885,10 +2880,10 @@ namespace IceInternal
// internal byte encodingMajor; // Currently unused
// internal byte encodingMinor; // Currently unused
- internal Hashtable patchMap;
- internal Hashtable unmarshaledMap;
+ internal Dictionary<int, List<IceInternal.IPatcher> > patchMap;
+ internal Dictionary<int, Ice.Object> unmarshaledMap;
internal int typeIdIndex;
- internal Hashtable typeIdMap;
+ internal Dictionary<int, string> typeIdMap;
internal ReadEncaps next;
internal void reset()
@@ -2908,10 +2903,10 @@ namespace IceInternal
internal int start;
internal int writeIndex;
- internal Hashtable toBeMarshaledMap;
- internal Hashtable marshaledMap;
+ internal Dictionary<Ice.Object, int> toBeMarshaledMap;
+ internal Dictionary<Ice.Object, int> marshaledMap;
internal int typeIdIndex;
- internal Hashtable typeIdMap;
+ internal Dictionary<string, int> typeIdMap;
internal WriteEncaps next;
internal void reset()
@@ -2946,9 +2941,10 @@ namespace IceInternal
int _startSeq;
int _minSeqSize;
- private ArrayList _objectList;
+ private List<Ice.Object> _objectList;
- private static Hashtable _exceptionFactories = new Hashtable(); // <type name, factory> pairs.
+ private static Dictionary<string, UserExceptionFactory> _exceptionFactories =
+ new Dictionary<string, UserExceptionFactory>(); // <type name, factory> pairs.
private static bool _bzlibInstalled;
diff --git a/cs/src/Ice/ByteBuffer.cs b/cs/src/Ice/ByteBuffer.cs
index 5143860a371..38dfef99b6e 100644
--- a/cs/src/Ice/ByteBuffer.cs
+++ b/cs/src/Ice/ByteBuffer.cs
@@ -273,7 +273,7 @@ namespace IceInternal
public byte b7;
}
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
unsafe
#endif
public short getShort()
@@ -281,7 +281,7 @@ namespace IceInternal
checkUnderflow(2);
if(NO._o == _order)
{
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
fixed(byte* p = &_bytes[_position])
{
_valBytes.shortVal = *((short*)p);
@@ -321,7 +321,7 @@ namespace IceInternal
_position += len;
}
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
unsafe
#endif
public ByteBuffer putShort(short val)
@@ -330,7 +330,7 @@ namespace IceInternal
_valBytes.shortVal = val;
if(NO._o == _order)
{
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
fixed(byte* p = &_bytes[_position])
{
*((short*)p) = _valBytes.shortVal;
@@ -371,7 +371,7 @@ namespace IceInternal
return this;
}
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
unsafe
#endif
public int getInt()
@@ -379,7 +379,7 @@ namespace IceInternal
checkUnderflow(4);
if(NO._o == _order)
{
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
fixed(byte* p = &_bytes[_position])
{
_valBytes.intVal = *((int*)p);
@@ -432,7 +432,7 @@ namespace IceInternal
return this;
}
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
unsafe
#endif
public ByteBuffer putInt(int pos, int val)
@@ -448,7 +448,7 @@ namespace IceInternal
_valBytes.intVal = val;
if(NO._o == _order)
{
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
fixed(byte* p = &_bytes[pos])
{
*((int*)p) = _valBytes.intVal;
@@ -494,7 +494,7 @@ namespace IceInternal
return this;
}
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
unsafe
#endif
public long getLong()
@@ -502,7 +502,7 @@ namespace IceInternal
checkUnderflow(8);
if(NO._o == _order)
{
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
fixed(byte* p = &_bytes[_position])
{
_valBytes.longVal = *((long*)p);
@@ -560,7 +560,7 @@ namespace IceInternal
_position += len;
}
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
unsafe
#endif
public ByteBuffer putLong(long val)
@@ -569,7 +569,7 @@ namespace IceInternal
_valBytes.longVal = val;
if(NO._o == _order)
{
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
fixed(byte* p = &_bytes[_position])
{
*((long*)p) = _valBytes.longVal;
@@ -628,7 +628,7 @@ namespace IceInternal
return this;
}
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
unsafe
#endif
public float getFloat()
@@ -636,7 +636,7 @@ namespace IceInternal
checkUnderflow(4);
if(NO._o == _order)
{
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
fixed(byte* p = &_bytes[_position])
{
_valBytes.floatVal = *((float*)p);
@@ -682,7 +682,7 @@ namespace IceInternal
_position += len;
}
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
unsafe
#endif
public ByteBuffer putFloat(float val)
@@ -691,7 +691,7 @@ namespace IceInternal
_valBytes.floatVal = val;
if(NO._o == _order)
{
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
fixed(byte* p = &_bytes[_position])
{
*((float*)p) = _valBytes.floatVal;
@@ -738,7 +738,7 @@ namespace IceInternal
return this;
}
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
unsafe
#endif
public double getDouble()
@@ -746,7 +746,7 @@ namespace IceInternal
checkUnderflow(8);
if(NO._o == _order)
{
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
fixed(byte* p = &_bytes[_position])
{
_valBytes.doubleVal = *((double*)p);
@@ -804,7 +804,7 @@ namespace IceInternal
_position += len;
}
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
unsafe
#endif
public ByteBuffer putDouble(double val)
@@ -813,7 +813,7 @@ namespace IceInternal
_valBytes.doubleVal = val;
if(NO._o == _order)
{
-#if !MANAGED && !COMPACT
+#if !MANAGED && !COMPACT && !SILVERLIGHT
fixed(byte* p = &_bytes[_position])
{
*((double*)p) = _valBytes.doubleVal;
@@ -926,7 +926,7 @@ namespace IceInternal
private static void throwOutOfRange(string param, object value, string message)
{
-#if COMPACT
+#if COMPACT || SILVERLIGHT
throw new ArgumentOutOfRangeException(param, message);
#else
throw new ArgumentOutOfRangeException(param, value, message);
diff --git a/cs/src/Ice/ConnectionFactory.cs b/cs/src/Ice/ConnectionFactory.cs
index 4f0b6cbf200..354f2207ea6 100644
--- a/cs/src/Ice/ConnectionFactory.cs
+++ b/cs/src/Ice/ConnectionFactory.cs
@@ -1462,7 +1462,7 @@ namespace IceInternal
//
// Operations from EventHandler.
//
- public override bool startAsync(int unused, AsyncCallback callback, ref bool completedSynchronously)
+ public override bool startAsync(int operation, AsyncCallback callback, ref bool completedSynchronously)
{
if(_state >= StateClosed)
{
@@ -1483,7 +1483,7 @@ namespace IceInternal
}
finally
{
-#if !COMPACT
+#if !COMPACT && !SILVERLIGHT
System.Environment.FailFast(s);
#endif
}
@@ -1510,7 +1510,7 @@ namespace IceInternal
}
finally
{
-#if !COMPACT
+#if !COMPACT && !SILVERLIGHT
System.Environment.FailFast(s);
#endif
}
@@ -1582,7 +1582,7 @@ namespace IceInternal
}
finally
{
-#if !COMPACT
+#if !COMPACT && !SILVERLIGHT
System.Environment.FailFast(s);
#endif
}
diff --git a/cs/src/Ice/ConnectionI.cs b/cs/src/Ice/ConnectionI.cs
index 1d84ebe13b7..10e14111078 100644
--- a/cs/src/Ice/ConnectionI.cs
+++ b/cs/src/Ice/ConnectionI.cs
@@ -1045,7 +1045,7 @@ namespace Ice
//
// Operations from EventHandler
//
- public override bool startAsync(int operation, System.AsyncCallback cb, ref bool completedSynchronously)
+ public override bool startAsync(int operation, IceInternal.AsyncCallback cb, ref bool completedSynchronously)
{
if(_state >= StateClosed)
{
diff --git a/cs/src/Ice/EndpointFactoryManager.cs b/cs/src/Ice/EndpointFactoryManager.cs
index 7c429d7410d..1e93c60956c 100644
--- a/cs/src/Ice/EndpointFactoryManager.cs
+++ b/cs/src/Ice/EndpointFactoryManager.cs
@@ -10,7 +10,7 @@
namespace IceInternal
{
- using System.Collections;
+ using System.Collections.Generic;
using System.Diagnostics;
using System.Text.RegularExpressions;
@@ -19,7 +19,7 @@ namespace IceInternal
internal EndpointFactoryManager(Instance instance)
{
instance_ = instance;
- _factories = new ArrayList();
+ _factories = new List<EndpointFactory>();
}
public void add(EndpointFactory factory)
@@ -162,7 +162,7 @@ namespace IceInternal
}
private readonly Instance instance_;
- private readonly ArrayList _factories;
+ private readonly List<EndpointFactory> _factories;
}
}
diff --git a/cs/src/Ice/EndpointHostResolver.cs b/cs/src/Ice/EndpointHostResolver.cs
index 436608b2f98..b9080113669 100644
--- a/cs/src/Ice/EndpointHostResolver.cs
+++ b/cs/src/Ice/EndpointHostResolver.cs
@@ -7,6 +7,7 @@
//
// **********************************************************************
+#if !SILVERLIGHT
namespace IceInternal
{
using System;
@@ -41,7 +42,7 @@ namespace IceInternal
//
try
{
- List<IPEndPoint> addrs = Network.getAddresses(host, port, _instance.protocolSupport(), false);
+ List<EndPoint> addrs = Network.getAddresses(host, port, _instance.protocolSupport(), false);
if(addrs.Count > 0)
{
callback.connectors(endpoint.connectors(addrs));
@@ -203,3 +204,4 @@ namespace IceInternal
private readonly IceUtilInternal.Monitor _m = new IceUtilInternal.Monitor();
}
}
+#endif
diff --git a/cs/src/Ice/EndpointI.cs b/cs/src/Ice/EndpointI.cs
index 0b1d1930715..24a6b0a062d 100644
--- a/cs/src/Ice/EndpointI.cs
+++ b/cs/src/Ice/EndpointI.cs
@@ -119,7 +119,7 @@ namespace IceInternal
//
public abstract bool equivalent(EndpointI endpoint);
- public virtual List<Connector> connectors(List<IPEndPoint> addresses)
+ public virtual List<Connector> connectors(List<EndPoint> addresses)
{
Debug.Assert(false);
return null;
diff --git a/cs/src/Ice/EventHandler.cs b/cs/src/Ice/EventHandler.cs
index d49f03169ed..b266960ac9f 100644
--- a/cs/src/Ice/EventHandler.cs
+++ b/cs/src/Ice/EventHandler.cs
@@ -18,6 +18,7 @@ public abstract class EventHandler
// Called to start a new asynchronous read or write operation.
//
abstract public bool startAsync(int op, AsyncCallback cb, ref bool completedSynchronously);
+
abstract public bool finishAsync(int op);
//
diff --git a/cs/src/Ice/ImplicitContextI.cs b/cs/src/Ice/ImplicitContextI.cs
index 76255a29a97..8dfdfcbf9c0 100644
--- a/cs/src/Ice/ImplicitContextI.cs
+++ b/cs/src/Ice/ImplicitContextI.cs
@@ -172,7 +172,7 @@ namespace Ice
Dictionary<string, string> ctx = null;
lock(this)
{
- ctx = _context.Count == 0 ? prxContext :combine(prxContext);
+ ctx = _context.Count == 0 ? prxContext : combine(prxContext);
}
ContextHelper.write(os, ctx);
}
@@ -206,9 +206,13 @@ namespace Ice
public override Dictionary<string, string> getContext()
{
Dictionary<string, string> threadContext = null;
+ Thread currentThread = Thread.CurrentThread;
lock(this)
{
- threadContext = (Dictionary<string, string>)_map[Thread.CurrentThread];
+ if(_map.ContainsKey(currentThread))
+ {
+ threadContext = (Dictionary<string, string>)_map[currentThread];
+ }
}
if(threadContext == null)
@@ -248,12 +252,10 @@ namespace Ice
Dictionary<string, string> threadContext = null;
lock(this)
{
- threadContext = (Dictionary<string, string>)_map[Thread.CurrentThread];
- }
-
- if(threadContext == null)
- {
- return false;
+ if(!_map.TryGetValue(Thread.CurrentThread, out threadContext))
+ {
+ return false;
+ }
}
return threadContext.ContainsKey(key);
@@ -269,13 +271,12 @@ namespace Ice
Dictionary<string, string> threadContext = null;
lock(this)
{
- threadContext = (Dictionary<string, string>)_map[Thread.CurrentThread];
+ if(!_map.TryGetValue(Thread.CurrentThread, out threadContext))
+ {
+ return "";
+ }
}
- if(threadContext == null)
- {
- return "";
- }
string val = threadContext[key];
if(val == null)
{
@@ -295,26 +296,18 @@ namespace Ice
value = "";
}
- Thread currentThread = Thread.CurrentThread;
-
Dictionary<string, string> threadContext = null;
lock(this)
{
- threadContext = (Dictionary<string, string>)_map[currentThread];
- }
-
- if(threadContext == null)
- {
- threadContext = new Dictionary<string, string>();
- lock(this)
+ if(!_map.TryGetValue(Thread.CurrentThread, out threadContext))
{
- _map.Add(currentThread, threadContext);
+ threadContext = new Dictionary<string, string>();
+ _map.Add(Thread.CurrentThread, threadContext);
}
}
-
+
string oldVal;
- threadContext.TryGetValue(key, out oldVal);
- if(oldVal == null)
+ if(!threadContext.TryGetValue(key, out oldVal))
{
oldVal = "";
}
@@ -333,17 +326,15 @@ namespace Ice
Dictionary<string, string> threadContext = null;
lock(this)
{
- threadContext = (Dictionary<string, string>)_map[Thread.CurrentThread];
- }
-
- if(threadContext == null)
- {
- return "";
+ if(!_map.TryGetValue(Thread.CurrentThread, out threadContext))
+ {
+ return "";
+ }
}
- string val = threadContext[key];
- if(val == null)
+ string val = null;
+ if(!threadContext.TryGetValue(key, out val))
{
val = "";
}
@@ -354,13 +345,12 @@ namespace Ice
return val;
}
- public override void write(Dictionary<string, string> prxContext,
- IceInternal.BasicStream os)
+ public override void write(Dictionary<string, string> prxContext, IceInternal.BasicStream os)
{
Dictionary<string, string> threadContext = null;
lock(this)
{
- threadContext = (Dictionary<string, string>)_map[Thread.CurrentThread];
+ _map.TryGetValue(Thread.CurrentThread, out threadContext);
}
if(threadContext == null || threadContext.Count == 0)
@@ -394,7 +384,10 @@ namespace Ice
Dictionary<string, string> threadContext = null;
lock(this)
{
- threadContext = (Dictionary<string, string>)_map[Thread.CurrentThread];
+ if(!_map.TryGetValue(Thread.CurrentThread, out threadContext))
+ {
+ return new Dictionary<string, string>(prxContext);
+ }
}
Dictionary<string, string> combined = new Dictionary<string, string>(prxContext);
@@ -408,7 +401,8 @@ namespace Ice
//
// map Thread -> Context
//
- private Hashtable _map = new Hashtable();
+ private Dictionary<Thread, Dictionary<string, string> > _map =
+ new Dictionary<Thread, Dictionary<string, string> >();
}
}
diff --git a/cs/src/Ice/Instance.cs b/cs/src/Ice/Instance.cs
index ad04c61b2c3..b9c77cb14d1 100644
--- a/cs/src/Ice/Instance.cs
+++ b/cs/src/Ice/Instance.cs
@@ -49,7 +49,7 @@ namespace IceInternal
return _defaultsAndOverrides;
}
-#if COMPACT
+#if COMPACT || SILVERLIGHT
public string[] factoryAssemblies()
{
return _factoryAssemblies;
@@ -233,6 +233,7 @@ namespace IceInternal
}
}
+#if !SILVERLIGHT
public EndpointHostResolver endpointHostResolver()
{
lock(this)
@@ -246,7 +247,7 @@ namespace IceInternal
return _endpointHostResolver;
}
}
-
+#endif
public RetryQueue
retryQueue()
{
@@ -601,7 +602,7 @@ namespace IceInternal
{
_initData.properties = Ice.Util.createProperties();
}
-
+#if !SILVERLIGHT
lock(_staticLock)
{
if(!_oneOffDone)
@@ -655,9 +656,11 @@ namespace IceInternal
_oneOffDone = true;
}
}
-
+#endif
+
if(_initData.logger == null)
{
+#if !SILVERLIGHT
string logfile = _initData.properties.getProperty("Ice.LogFile");
if(_initData.properties.getPropertyAsInt("Ice.UseSyslog") > 0)
{
@@ -676,9 +679,16 @@ namespace IceInternal
bool console =
_initData.properties.getPropertyAsIntWithDefault("Ice.ConsoleListener",
logfile.Length == 0 ? 1 : 0) > 0;
- _initData.logger =
+ _initData.logger =
new Ice.TraceLoggerI(_initData.properties.getProperty("Ice.ProgramName"), logfile, console);
}
+#else
+ if(Ice.Util.getProcessLogger() is Ice.LoggerI)
+ {
+ _initData.logger =
+ new Ice.TraceLoggerI(_initData.properties.getProperty("Ice.ProgramName"), true);
+ }
+#endif
else
{
_initData.logger = Ice.Util.getProcessLogger();
@@ -689,11 +699,10 @@ namespace IceInternal
_defaultsAndOverrides = new DefaultsAndOverrides(_initData.properties);
-#if COMPACT
+#if COMPACT || SILVERLIGHT
char[] separators = { ' ', '\t', '\n', '\r' };
_factoryAssemblies = _initData.properties.getProperty("Ice.FactoryAssemblies").Split(separators);
#endif
-
{
const int defaultMessageSizeMax = 1024;
int num =
@@ -750,8 +759,10 @@ namespace IceInternal
_endpointFactoryManager.add(tcpEndpointFactory);
EndpointFactory udpEndpointFactory = new UdpEndpointFactory(this);
_endpointFactoryManager.add(udpEndpointFactory);
-
+
+#if !SILVERLIGHT
_pluginManager = new Ice.PluginManagerI(communicator);
+#endif
_outgoingConnectionFactory = new OutgoingConnectionFactory(communicator, this);
@@ -785,14 +796,17 @@ namespace IceInternal
// Load plug-ins.
//
Debug.Assert(_serverThreadPool == null);
+#if !SILVERLIGHT
Ice.PluginManagerI pluginManagerImpl = (Ice.PluginManagerI)_pluginManager;
pluginManagerImpl.loadPlugins(ref args);
+#endif
//
// Create threads.
//
try
{
+#if !SILVERLIGHT
if(initializationData().properties.getProperty("Ice.ThreadPriority").Length > 0)
{
ThreadPriority priority = IceInternal.Util.stringToThreadPriority(
@@ -803,6 +817,9 @@ namespace IceInternal
{
_timer = new Timer(this);
}
+#else
+ _timer = new Timer(this);
+#endif
}
catch(System.Exception ex)
{
@@ -811,6 +828,7 @@ namespace IceInternal
throw;
}
+#if !SILVERLIGHT
try
{
_endpointHostResolver = new EndpointHostResolver(this);
@@ -821,7 +839,7 @@ namespace IceInternal
_initData.logger.error(s);
throw;
}
-
+#endif
_clientThreadPool = new ThreadPool(this, "Ice.ThreadPool.Client", 0);
//
@@ -844,6 +862,7 @@ namespace IceInternal
//
// Show process id if requested (but only once).
//
+#if !SILVERLIGHT
lock(this)
{
if(!_printProcessIdDone && _initData.properties.getPropertyAsInt("Ice.PrintProcessId") > 0)
@@ -855,7 +874,7 @@ namespace IceInternal
_printProcessIdDone = true;
}
}
-
+#endif
//
// Create the connection monitor and ensure the interval for
// monitoring connections is appropriate for client & server
@@ -875,11 +894,12 @@ namespace IceInternal
// initialization until after it has interacted directly with the
// plug-ins.
//
+#if !SILVERLIGHT
if(_initData.properties.getPropertyAsIntWithDefault("Ice.InitPlugins", 1) > 0)
{
pluginManagerImpl.initializePlugins();
}
-
+#endif
//
// This must be done last as this call creates the Ice.Admin object adapter
// and eventually registers a process proxy with the Ice locator (allowing
@@ -944,8 +964,10 @@ namespace IceInternal
ThreadPool serverThreadPool = null;
ThreadPool clientThreadPool = null;
AsyncIOThread asyncIOThread = null;
- EndpointHostResolver endpointHostResolver = null;
+#if !SILVERLIGHT
+ EndpointHostResolver endpointHostResolver = null;
+#endif
lock(this)
{
_objectAdapterFactory = null;
@@ -979,12 +1001,14 @@ namespace IceInternal
_asyncIOThread = null;
}
+#if !SILVERLIGHT
if(_endpointHostResolver != null)
{
_endpointHostResolver.destroy();
endpointHostResolver = _endpointHostResolver;
_endpointHostResolver = null;
}
+#endif
if(_timer != null)
{
@@ -1053,18 +1077,19 @@ namespace IceInternal
{
asyncIOThread.joinWithThread();
}
+#if !SILVERLIGHT
if(endpointHostResolver != null)
{
endpointHostResolver.joinWithThread();
}
-
+#endif
if(_initData.properties.getPropertyAsInt("Ice.Warn.UnusedProperties") > 0)
{
- ArrayList unusedProperties = ((Ice.PropertiesI)_initData.properties).getUnusedProperties();
- if(unusedProperties.Count != 0)
+ List<string> unusedProperties = ((Ice.PropertiesI)_initData.properties).getUnusedProperties();
+ if (unusedProperties.Count != 0)
{
StringBuilder message = new StringBuilder("The following properties were set but never read:");
- foreach(string s in unusedProperties)
+ foreach (string s in unusedProperties)
{
message.Append("\n ");
message.Append(s);
@@ -1083,7 +1108,7 @@ namespace IceInternal
private Ice.InitializationData _initData; // Immutable, not reset by destroy().
private TraceLevels _traceLevels; // Immutable, not reset by destroy().
private DefaultsAndOverrides _defaultsAndOverrides; // Immutable, not reset by destroy().
-#if COMPACT
+#if COMPACT || SILVERLIGHT
private string[] _factoryAssemblies; // Immutable, not reset by destroy().
#endif
private int _messageSizeMax; // Immutable, not reset by destroy().
@@ -1102,7 +1127,9 @@ namespace IceInternal
private ThreadPool _clientThreadPool;
private ThreadPool _serverThreadPool;
private AsyncIOThread _asyncIOThread;
+#if !SILVERLIGHT
private EndpointHostResolver _endpointHostResolver;
+#endif
private Timer _timer;
private RetryQueue _retryQueue;
private EndpointFactoryManager _endpointFactoryManager;
@@ -1112,9 +1139,11 @@ namespace IceInternal
private HashSet<string> _adminFacetFilter = new HashSet<string>();
private Ice.Identity _adminIdentity;
+#if !SILVERLIGHT
private static bool _printProcessIdDone = false;
private static bool _oneOffDone = false;
+#endif
private static System.Object _staticLock = new System.Object();
}
}
diff --git a/cs/src/Ice/LinkedList.cs b/cs/src/Ice/LinkedList.cs
deleted file mode 100644
index e8543cf7324..00000000000
--- a/cs/src/Ice/LinkedList.cs
+++ /dev/null
@@ -1,304 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2012 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-
-namespace IceUtilInternal
-{
- using System;
- using System.Collections;
- using System.Diagnostics;
-
- public class LinkedList : ICollection, ICloneable
- {
- public LinkedList()
- {
- _head = null;
- _tail = null;
- _count = 0;
- }
-
- public LinkedList(LinkedList l)
- {
- _head = null;
- _tail = null;
- _count = 0;
-
- Node cursor = l._head;
- while(cursor != null)
- {
- Add(cursor.val);
- cursor = cursor.next;
- }
- }
-
- public int Count
- {
- get
- {
- return _count;
- }
- }
-
- public bool IsSynchronized
- {
- get
- {
- return false;
- }
- }
-
- public object SyncRoot
- {
- get
- {
- return this;
- }
- }
-
- public void CopyTo(Array array, int index)
- {
- //
- // Check preconditions.
- //
- if(array == null)
- {
- throw new ArgumentNullException("array", "array parameter must not be null");
- }
- if(index < 0)
- {
-#if COMPACT
- throw new ArgumentOutOfRangeException("index", "index must not be less than zero");
-#else
- throw new ArgumentOutOfRangeException("index", _count, "index must not be less than zero");
-#endif
- }
- if(index >= array.Length)
- {
- throw new ArgumentException("index out of bounds for array", "index");
- }
- if(array.Length - index > _count)
- {
- throw new ArgumentException("insufficient room in array", "array");
- }
- if(array.Rank != 1)
- {
- throw new ArgumentException("array must be one-dimensional", "array");
- }
-
- //
- // Copy the elements.
- //
- Node n = _head;
- while(n != null)
- {
- array.SetValue(n.val, index++);
- n = (Node)n.next;
- }
- }
-
- public IEnumerator GetEnumerator()
- {
- return new Enumerator(this);
- }
-
- public object Clone()
- {
- LinkedList l = new LinkedList();
- Node cursor = _head;
- while(cursor != null)
- {
- l.Add(cursor.val);
- cursor = cursor.next;
- }
- return l;
- }
-
- public void Add(object value)
- {
- Node n = new Node();
- n.val = value;
- if(_tail == null)
- {
- n.prev = null;
- n.next = null;
- _head = n;
- _tail = n;
- }
- else
- {
- n.prev = _tail;
- n.next = null;
- _tail.next = n;
- _tail = n;
- }
- _count++;
- }
-
- public void AddFirst(object value)
- {
- Node n = new Node();
- n.val = value;
- if(_head == null)
- {
- n.prev = null;
- n.next = null;
- _head = n;
- _tail = n;
- }
- else
- {
- n.prev = null;
- n.next = _head;
- _head.prev = n;
- _head = n;
- }
- _count++;
- }
-
- public bool Remove(object value)
- {
- Node n = _head;
- while(n != null)
- {
- if(n.val == value)
- {
- RemoveNode(n);
- return true;
- }
- n = n.next;
- }
- return false;
- }
-
- private void RemoveNode(Node n)
- {
- Debug.Assert(n != null);
- Debug.Assert(_count != 0);
-
- if(n.prev != null)
- {
- n.prev.next = n.next;
- }
- else
- {
- _head = n.next;
- }
- if(n.next != null)
- {
- n.next.prev = n.prev;
- }
- else
- {
- _tail = n.prev;
- }
- _count--;
- }
-
- internal class Node
- {
- internal Node next;
- internal Node prev;
- internal object val;
- }
-
- private Node _head;
- private Node _tail;
- private int _count;
-
- public class Enumerator : IEnumerator
- {
- internal Enumerator(LinkedList list)
- {
- _list = list;
- _current = null;
- _movePrev = null;
- _moveNext = null;
- _removed = false;
- }
-
- public void Reset()
- {
- _current = null;
- _movePrev = null;
- _moveNext = null;
- _removed = false;
- }
-
- public object Current
- {
- get
- {
- if(_current == null)
- {
- throw new InvalidOperationException("iterator not positioned on an element");
- }
- return _current.val;
- }
- }
-
- public bool MoveNext()
- {
- if(_removed)
- {
- _current = _moveNext;
- _moveNext = null;
- _movePrev = null;
- _removed = false;
- }
- else
- {
- if(_current == _list._tail) // Make sure the iterator "sticks" if on last element.
- {
- return false;
- }
- _current = _current == null ? _list._head : _current.next;
- }
- return _current != null;
- }
-
- public bool MovePrev()
- {
- if(_removed)
- {
- _current = _movePrev;
- _movePrev = null;
- _moveNext = null;
- _removed = false;
- }
- else
- {
- if(_current == _list._head) // Make sure the iterator "sticks" if on first element.
- {
- return false;
- }
- _current = _current == null ? _list._tail : _current.prev;
- }
- return _current != null;
- }
-
- public void Remove()
- {
- if(_current == null)
- {
- throw new InvalidOperationException("iterator is not positioned on an element");
- }
- _removed = true;
- _moveNext = _current.next; // Remember where to move next for call to MoveNext().
- _movePrev = _current.prev; // Remember where to move next for call to MovePrev().
- _list.RemoveNode(_current);
- _current = null;
- }
-
- private LinkedList _list; // The list we are iterating over.
- private Node _current; // Current iterator position.
- private Node _moveNext; // Remembers node that preceded a removed element.
- private Node _movePrev; // Remembers node that followed a removed element.
- private bool _removed; // True after a call to Remove(), false otherwise.
- }
- }
-}
diff --git a/cs/src/Ice/LocatorInfo.cs b/cs/src/Ice/LocatorInfo.cs
index 95b899b5365..326eef71291 100644
--- a/cs/src/Ice/LocatorInfo.cs
+++ b/cs/src/Ice/LocatorInfo.cs
@@ -825,8 +825,8 @@ namespace IceInternal
{
internal LocatorManager(Ice.Properties properties)
{
- _table = new Hashtable();
- _locatorTables = new Hashtable();
+ _table = new Dictionary<Ice.LocatorPrx, LocatorInfo>();
+ _locatorTables = new Dictionary<Ice.Identity, LocatorTable>();
_background = properties.getPropertyAsInt("Ice.BackgroundLocatorCacheUpdates") > 0;
}
@@ -865,16 +865,16 @@ namespace IceInternal
lock(this)
{
- LocatorInfo info = (LocatorInfo)_table[locator];
- if(info == null)
+ LocatorInfo info = null;
+ if(!_table.TryGetValue(locator, out info))
{
//
// Rely on locator identity for the adapter table. We want to
// have only one table per locator (not one per locator
// proxy).
//
- LocatorTable table = (LocatorTable)_locatorTables[locator.ice_getIdentity()];
- if(table == null)
+ LocatorTable table = null;
+ if(!_locatorTables.TryGetValue(locator.ice_getIdentity(), out table))
{
table = new LocatorTable();
_locatorTables[locator.ice_getIdentity()] = table;
@@ -888,8 +888,8 @@ namespace IceInternal
}
}
- private Hashtable _table;
- private Hashtable _locatorTables;
+ private Dictionary<Ice.LocatorPrx, LocatorInfo> _table;
+ private Dictionary<Ice.Identity, LocatorTable> _locatorTables;
private readonly bool _background;
}
@@ -897,8 +897,8 @@ namespace IceInternal
{
internal LocatorTable()
{
- _adapterEndpointsTable = new Hashtable();
- _objectTable = new Hashtable();
+ _adapterEndpointsTable = new Dictionary<string, EndpointTableEntry>();
+ _objectTable = new Dictionary<Ice.Identity, ReferenceTableEntry>();
}
internal void clear()
@@ -920,11 +920,12 @@ namespace IceInternal
lock(this)
{
- EndpointTableEntry entry = (EndpointTableEntry)_adapterEndpointsTable[adapter];
- if(entry != null)
+ EndpointTableEntry entry = null;
+ if(_adapterEndpointsTable.TryGetValue(adapter, out entry))
{
cached = checkTTL(entry.time, ttl);
return entry.endpoints;
+
}
cached = false;
return null;
@@ -944,9 +945,13 @@ namespace IceInternal
{
lock(this)
{
- EndpointTableEntry entry = (EndpointTableEntry)_adapterEndpointsTable[adapter];
- _adapterEndpointsTable.Remove(adapter);
- return entry != null ? entry.endpoints : null;
+ EndpointTableEntry entry = null;
+ if(_adapterEndpointsTable.TryGetValue(adapter, out entry))
+ {
+ _adapterEndpointsTable.Remove(adapter);
+ return entry.endpoints;
+ }
+ return null;
}
}
@@ -960,8 +965,8 @@ namespace IceInternal
lock(this)
{
- ReferenceTableEntry entry = (ReferenceTableEntry)_objectTable[id];
- if(entry != null)
+ ReferenceTableEntry entry = null;
+ if(_objectTable.TryGetValue(id, out entry))
{
cached = checkTTL(entry.time, ttl);
return entry.reference;
@@ -983,9 +988,13 @@ namespace IceInternal
{
lock(this)
{
- ReferenceTableEntry entry = (ReferenceTableEntry)_objectTable[id];
- _objectTable.Remove(id);
- return entry != null ? entry.reference : null;
+ ReferenceTableEntry entry = null;
+ if(_objectTable.TryGetValue(id, out entry))
+ {
+ _objectTable.Remove(id);
+ return entry.reference;
+ }
+ return null;
}
}
@@ -1026,8 +1035,8 @@ namespace IceInternal
public Reference reference;
}
- private Hashtable _adapterEndpointsTable;
- private Hashtable _objectTable;
+ private Dictionary<string, EndpointTableEntry> _adapterEndpointsTable;
+ private Dictionary<Ice.Identity, ReferenceTableEntry> _objectTable;
}
}
diff --git a/cs/src/Ice/LoggerI.cs b/cs/src/Ice/LoggerI.cs
index 914230948c1..e232847286c 100644
--- a/cs/src/Ice/LoggerI.cs
+++ b/cs/src/Ice/LoggerI.cs
@@ -16,7 +16,7 @@ namespace Ice
#if COMPACT
using System.IO;
#endif
-
+
public abstract class LoggerI : Logger
{
public LoggerI(string prefix)
@@ -156,6 +156,27 @@ namespace Ice
private bool _console = false;
private TextWriter _writer;
}
+#elif SILVERLIGHT
+ public sealed class TraceLoggerI : LoggerI
+ {
+ public TraceLoggerI(string prefix, bool console)
+ : base(prefix)
+ {
+ _console = console;
+ }
+
+ public override Logger cloneWithPrefix(string prefix)
+ {
+ return new TraceLoggerI(prefix, _console);
+ }
+
+ protected override void write(string message)
+ {
+ System.Console.Error.WriteLine(message);
+ }
+
+ private bool _console = false;
+ }
#else
public sealed class TraceLoggerI : LoggerI
{
diff --git a/cs/src/Ice/Makefile b/cs/src/Ice/Makefile
index 77afe2b5817..a7fedaa6976 100644
--- a/cs/src/Ice/Makefile
+++ b/cs/src/Ice/Makefile
@@ -50,7 +50,6 @@ SRCS = Acceptor.cs \
IncomingAsync.cs \
Incoming.cs \
Instance.cs \
- LinkedList.cs \
LocalObject.cs \
LocatorInfo.cs \
LoggerI.cs \
diff --git a/cs/src/Ice/Makefile.mak b/cs/src/Ice/Makefile.mak
index 516b317ed30..81dcec2b656 100644
--- a/cs/src/Ice/Makefile.mak
+++ b/cs/src/Ice/Makefile.mak
@@ -51,7 +51,6 @@ SRCS = Acceptor.cs \
IncomingAsync.cs \
Incoming.cs \
Instance.cs \
- LinkedList.cs \
LocalObject.cs \
LocatorInfo.cs \
LoggerI.cs \
diff --git a/cs/src/Ice/Monitor.cs b/cs/src/Ice/Monitor.cs
index 8202c19008f..a445832d95c 100644
--- a/cs/src/Ice/Monitor.cs
+++ b/cs/src/Ice/Monitor.cs
@@ -75,39 +75,45 @@ namespace IceUtilInternal
}
LockerEvent e = acquireEvent();
- _waitQueue.Enqueue(e);
+ try
+ {
+ _waitQueue.Enqueue(e);
- //
- // Preserve the lock count until we reaquire the lock.
- //
- int lockCount = _lockCount;
- _lockCount = 0;
+ //
+ // Preserve the lock count until we reaquire the lock.
+ //
+ int lockCount = _lockCount;
+ _lockCount = 0;
- //
- // Fully release the lock.
- //
- for(int i = 0; i < lockCount; ++i)
- {
- _mutex.ReleaseMutex();
- }
+ //
+ // Fully release the lock.
+ //
+ for(int i = 0; i < lockCount; ++i)
+ {
+ _mutex.ReleaseMutex();
+ }
- //
- // Wait for the event to be set.
- //
- e.ev.WaitOne();
+ //
+ // Wait for the event to be set.
+ //
+ e.ev.WaitOne();
- //
- // Reacquire the lock the same number of times.
- //
- for(int i = 0; i < lockCount; ++i)
- {
- _mutex.WaitOne();
- }
+ //
+ // Reacquire the lock the same number of times.
+ //
+ for(int i = 0; i < lockCount; ++i)
+ {
+ _mutex.WaitOne();
+ }
- _lockCount = lockCount;
+ _lockCount = lockCount;
- Debug.Assert(e.notified);
- releaseEvent(e);
+ Debug.Assert(e.notified);
+ }
+ finally
+ {
+ releaseEvent(e);
+ }
}
public bool TimedWait(int timeout)
@@ -118,46 +124,43 @@ namespace IceUtilInternal
}
LockerEvent e = acquireEvent();
- _waitQueue.Enqueue(e);
-
- //
- // Preserve the lock count until we reaquire the lock.
- //
- int lockCount = _lockCount;
- _lockCount = 0;
-
- //
- // Fully release the lock.
- //
- for(int i = 0; i < lockCount; ++i)
+ try
{
- _mutex.ReleaseMutex();
- }
+ _waitQueue.Enqueue(e);
- //
- // Wait for the event to be set or the timeout to expire.
- //
- e.ev.WaitOne(timeout, false);
+ //
+ // Preserve the lock count until we reaquire the lock.
+ //
+ int lockCount = _lockCount;
+ _lockCount = 0;
- //
- // Reacquire the lock the same number of times.
- //
- for(int i = 0; i < lockCount; ++i)
- {
- _mutex.WaitOne();
- }
+ //
+ // Fully release the lock.
+ //
+ for(int i = 0; i < lockCount; ++i)
+ {
+ _mutex.ReleaseMutex();
+ }
- _lockCount = lockCount;
+ //
+ // Wait for the event to be set or the timeout to expire.
+ //
+ e.ev.WaitOne(timeout, false);
- if(e.notified)
- {
- releaseEvent(e);
- return true;
+ //
+ // Reacquire the lock the same number of times.
+ //
+ for(int i = 0; i < lockCount; ++i)
+ {
+ _mutex.WaitOne();
+ }
+
+ _lockCount = lockCount;
+ return e.notified;
}
- else
+ finally
{
- e.timedOut = true;
- return false;
+ releaseEvent(e);
}
}
@@ -171,16 +174,8 @@ namespace IceUtilInternal
// Set the first event in the wait queue.
//
LockerEvent h = _waitQueue.Dequeue();
- if(!h.timedOut)
- {
- h.notified = true;
- h.ev.Set();
- break;
- }
- else
- {
- releaseEvent(h);
- }
+ h.notified = true;
+ h.ev.Set();
}
}
}
@@ -194,21 +189,14 @@ namespace IceUtilInternal
//
foreach(LockerEvent h in _waitQueue)
{
- if(!h.timedOut)
- {
- h.notified = true;
- h.ev.Set();
- }
- else
- {
- releaseEvent(h);
- }
+ h.notified = true;
+ h.ev.Set();
}
_waitQueue.Clear();
}
}
- private LockerEvent acquireEvent()
+ private LockerEvent acquireEvent()
{
if(_eventPool == null)
{
@@ -233,7 +221,6 @@ namespace IceUtilInternal
internal class LockerEvent
{
internal System.Threading.EventWaitHandle ev;
- internal bool timedOut;
internal bool notified;
internal LockerEvent next;
@@ -246,7 +233,6 @@ namespace IceUtilInternal
internal void Reset()
{
ev.Reset();
- timedOut = false;
notified = false;
}
}
diff --git a/cs/src/Ice/Network.cs b/cs/src/Ice/Network.cs
index 30994abb5ef..3609ac8c6e6 100644
--- a/cs/src/Ice/Network.cs
+++ b/cs/src/Ice/Network.cs
@@ -29,34 +29,101 @@ namespace IceInternal
public const int EnableIPv4 = 0;
public const int EnableIPv6 = 1;
public const int EnableBoth = 2;
-
+
+#if COMPACT
+ public static SocketError socketErrorCode(SocketException ex)
+ {
+ return (SocketError)ex.ErrorCode;
+ }
+#else
+ public static SocketError socketErrorCode(SocketException ex)
+ {
+ return ex.SocketErrorCode;
+ }
+#endif
+
+#if COMPACT
//
- // Magic numbers taken from winsock2.h
+ // SocketError enumeration isn't available with Silverlight
//
- const int WSAEINTR = 10004;
- const int WSAEFAULT = 10014;
- const int WSAEINVAL = 10022;
- const int WSAEMFILE = 10024;
- const int WSAEWOULDBLOCK = 10035;
- const int WSAEINPROGRESS = 10036; // Deprecated in winsock2, but still used by Mono Beta 1
- const int WSAEMSGSIZE = 10040;
- const int WSAENETDOWN = 10050;
- const int WSAENETUNREACH = 10051;
- const int WSAENETRESET = 10052;
- const int WSAECONNABORTED = 10053;
- const int WSAECONNRESET = 10054;
- const int WSAENOBUFS = 10055;
- const int WSAENOTCONN = 10057;
- const int WSAESHUTDOWN = 10058;
- const int WSAETIMEDOUT = 10060;
- const int WSAECONNREFUSED = 10061;
- const int WSAEHOSTUNREACH = 10065;
- const int WSATRY_AGAIN = 11002;
-
- private static IPEndPoint getAddressImpl(string host, int port, int protocol, bool server)
+ public enum SocketError
+ {
+ Interrupted = 10004, // A blocking Socket call was canceled.
+ //AccessDenied =10013, // An attempt was made to access a Socket in a way that is forbidden by its access permissions.
+ Fault = 10014, // An invalid pointer address was detected by the underlying socket provider.
+ InvalidArgument = 10022, // An invalid argument was supplied to a Socket member.
+ TooManyOpenSockets = 10024, // There are too many open sockets in the underlying socket provider.
+ WouldBlock = 10035, // An operation on a nonblocking socket cannot be completed immediately.
+ InProgress = 10036, // A blocking operation is in progress.
+ //AlreadyInProgress = 10037, // The nonblocking Socket already has an operation in progress.
+ //NotSocket = 10038, // A Socket operation was attempted on a non-socket.
+ //DestinationAddressRequired = 10039, // A required address was omitted from an operation on a Socket.
+ MessageSize = 10040, // The datagram is too long.
+ //ProtocolType = 10041, // The protocol type is incorrect for this Socket.
+ //ProtocolOption = 10042, // An unknown, invalid, or unsupported option or level was used with a Socket.
+ //ProtocolNotSupported = 10043, // The protocol is not implemented or has not been configured.
+ //SocketNotSupported = 10044, // The support for the specified socket type does not exist in this address family.
+ //OperationNotSupported = 10045, // The address family is not supported by the protocol family.
+ //ProtocolFamilyNotSupported = 10046, // The protocol family is not implemented or has not been configured.
+ //AddressFamilyNotSupported = 10047, // The address family specified is not supported.
+ //AddressAlreadyInUse = 10048, // Only one use of an address is normally permitted.
+ //AddressNotAvailable = 10049, // The selected IP address is not valid in this context.
+ NetworkDown = 10050, // The network is not available.
+ NetworkUnreachable = 10051, // No route to the remote host exists.
+ NetworkReset = 10052, // The application tried to set KeepAlive on a connection that has already timed out.
+ ConnectionAborted = 10053, // The connection was aborted by the .NET Framework or the underlying socket provider.
+ ConnectionReset = 10054, // The connection was reset by the remote peer.
+ NoBufferSpaceAvailable = 10055, // No free buffer space is available for a Socket operation.
+ //IsConnected = 10056, // The Socket is already connected.
+ NotConnected = 10057, // The application tried to send or receive data, and the Socket is not connected.
+ Shutdown = 10058, // A request to send or receive data was disallowed because the Socket has already been closed.
+ TimedOut = 10060, // The connection attempt timed out, or the connected host has failed to respond.
+ ConnectionRefused = 10061, // The remote host is actively refusing a connection.
+ //HostDown = 10064, // The operation failed because the remote host is down.
+ HostUnreachable = 10065, // There is no network route to the specified host.
+ //ProcessLimit = 10067, // Too many processes are using the underlying socket provider.
+ //SystemNotReady = 10091, // The network subsystem is unavailable.
+ //VersionNotSupported = 10092, // The version of the underlying socket provider is out of range.
+ //NotInitialized = 10093, // The underlying socket provider has not been initialized.
+ //Disconnecting = 10101, // A graceful shutdown is in progress.
+ //TypeNotFound = 10109, // The specified class was not found.
+ //HostNotFound = 11001, // No such host is known. The name is not an official host name or alias.
+ TryAgain = 11002, // The name of the host could not be resolved. Try again later.
+ //NoRecovery = 11003, // The error is unrecoverable or the requested database cannot be located.
+ //NoData = 11004, // The requested name or IP address was not found on the name server.
+ //IOPending = 997, // The application has initiated an overlapped operation that cannot be completed immediately.
+ OperationAborted =995 // The overlapped operation was aborted due to the closure of the Socket.
+ }
+#endif
+
+ private static EndPoint getAddressImpl(string host, int port, int protocol, bool server)
{
if(host.Length == 0)
{
+#if SILVERLIGHT
+ if(server)
+ {
+ if(protocol != EnableIPv4)
+ {
+ return new DnsEndPoint(IPAddress.IPv6Any.ToString(), port);
+ }
+ else
+ {
+ return new DnsEndPoint(IPAddress.Any.ToString(), port);
+ }
+ }
+ else
+ {
+ if(protocol != EnableIPv4)
+ {
+ return new DnsEndPoint(IPAddress.IPv6Loopback.ToString(), port);
+ }
+ else
+ {
+ return new DnsEndPoint(IPAddress.Loopback.ToString(), port);
+ }
+ }
+#else
if(server)
{
if(protocol != EnableIPv4)
@@ -79,11 +146,15 @@ namespace IceInternal
return new IPEndPoint(IPAddress.Loopback, port);
}
}
+#endif
}
+#if SILVERLIGHT
+ return new DnsEndPoint(host, port);
+#else
int retry = 5;
- repeatGetHostByName:
+ repeatGetHostByName:
try
{
try
@@ -99,11 +170,11 @@ namespace IceInternal
{
}
-#if COMPACT
+# if COMPACT
foreach(IPAddress a in Dns.GetHostEntry(host).AddressList)
-#else
+# else
foreach(IPAddress a in Dns.GetHostAddresses(host))
-#endif
+# endif
{
if((a.AddressFamily == AddressFamily.InterNetwork && protocol != EnableIPv6) ||
(a.AddressFamily == AddressFamily.InterNetworkV6 && protocol != EnableIPv4))
@@ -112,9 +183,9 @@ namespace IceInternal
}
}
}
- catch(Win32Exception ex)
+ catch(SocketException ex)
{
- if(ex.NativeErrorCode == WSATRY_AGAIN && --retry >= 0)
+ if(socketErrorCode(ex) == SocketError.TryAgain && --retry >= 0)
{
goto repeatGetHostByName;
}
@@ -135,65 +206,66 @@ namespace IceInternal
Ice.DNSException dns = new Ice.DNSException();
dns.host = host;
throw dns;
+#endif
}
- public static bool interrupted(Win32Exception ex)
+ public static bool interrupted(SocketException ex)
{
- return ex.NativeErrorCode == WSAEINTR;
+ return socketErrorCode(ex) == SocketError.Interrupted;
}
- public static bool acceptInterrupted(Win32Exception ex)
+ public static bool acceptInterrupted(SocketException ex)
{
if(interrupted(ex))
{
return true;
}
- int error = ex.NativeErrorCode;
- return error == WSAECONNABORTED ||
- error == WSAECONNRESET ||
- error == WSAETIMEDOUT;
+ SocketError error = socketErrorCode(ex);
+ return error == SocketError.ConnectionAborted ||
+ error == SocketError.ConnectionReset ||
+ error == SocketError.TimedOut;
}
- public static bool noBuffers(Win32Exception ex)
+ public static bool noBuffers(SocketException ex)
{
- int error = ex.NativeErrorCode;
- return error == WSAENOBUFS ||
- error == WSAEFAULT;
+ SocketError error = socketErrorCode(ex);
+ return error == SocketError.NoBufferSpaceAvailable ||
+ error == SocketError.Fault;
}
- public static bool wouldBlock(Win32Exception ex)
+ public static bool wouldBlock(SocketException ex)
{
- return ex.NativeErrorCode == WSAEWOULDBLOCK;
+ return socketErrorCode(ex) == SocketError.WouldBlock;
}
- public static bool connectFailed(Win32Exception ex)
+ public static bool connectFailed(SocketException ex)
{
- int error = ex.NativeErrorCode;
- return error == WSAECONNREFUSED ||
- error == WSAETIMEDOUT ||
- error == WSAENETUNREACH ||
- error == WSAEHOSTUNREACH ||
- error == WSAECONNRESET ||
- error == WSAESHUTDOWN ||
- error == WSAECONNABORTED ||
- error == WSAENETDOWN;
+ SocketError error = socketErrorCode(ex);
+ return error == SocketError.ConnectionRefused ||
+ error == SocketError.TimedOut ||
+ error == SocketError.NetworkUnreachable ||
+ error == SocketError.HostUnreachable ||
+ error == SocketError.ConnectionReset ||
+ error == SocketError.Shutdown ||
+ error == SocketError.ConnectionAborted ||
+ error == SocketError.NetworkDown;
}
- public static bool connectInProgress(Win32Exception ex)
+ public static bool connectInProgress(SocketException ex)
{
- int error = ex.NativeErrorCode;
- return error == WSAEWOULDBLOCK ||
- error == WSAEINPROGRESS;
+ SocketError error = socketErrorCode(ex);
+ return error == SocketError.WouldBlock ||
+ error == SocketError.InProgress;
}
- public static bool connectionLost(Win32Exception ex)
+ public static bool connectionLost(SocketException ex)
{
- int error = ex.NativeErrorCode;
- return error == WSAECONNRESET ||
- error == WSAESHUTDOWN ||
- error == WSAECONNABORTED ||
- error == WSAENETDOWN ||
- error == WSAENETRESET;
+ SocketError error = socketErrorCode(ex);
+ return error == SocketError.ConnectionReset ||
+ error == SocketError.Shutdown ||
+ error == SocketError.ConnectionAborted ||
+ error == SocketError.NetworkDown ||
+ error == SocketError.NetworkReset;
}
public static bool connectionLost(System.IO.IOException ex)
@@ -202,9 +274,9 @@ namespace IceInternal
// In some cases the IOException has an inner exception that we can pass directly
// to the other overloading of connectionLost().
//
- if(ex.InnerException != null && ex.InnerException is Win32Exception)
+ if(ex.InnerException != null && ex.InnerException is SocketException)
{
- return connectionLost(ex.InnerException as Win32Exception);
+ return connectionLost(ex.InnerException as SocketException);
}
//
@@ -229,28 +301,30 @@ namespace IceInternal
return false;
}
- public static bool connectionRefused(Win32Exception ex)
+ public static bool connectionRefused(SocketException ex)
{
- return ex.NativeErrorCode == WSAECONNREFUSED;
+ return socketErrorCode(ex) == SocketError.ConnectionRefused;
}
- public static bool notConnected(Win32Exception ex)
+ public static bool notConnected(SocketException ex)
{
- // BUGFIX: WSAEINVAL because shutdown() under MacOS returns EINVAL if the server side is gone.
- // BUGFIX: shutdown() under Vista might return WSAECONNRESET
- return ex.NativeErrorCode == WSAENOTCONN ||
- ex.NativeErrorCode == WSAEINVAL ||
- ex.NativeErrorCode == WSAECONNRESET;
+ // BUGFIX: SocketError.InvalidArgument because shutdown() under MacOS returns EINVAL
+ // if the server side is gone.
+ // BUGFIX: shutdown() under Vista might return SocketError.ConnectionReset
+ SocketError error = socketErrorCode(ex);
+ return error == SocketError.NotConnected ||
+ error == SocketError.InvalidArgument ||
+ error == SocketError.ConnectionReset;
}
- public static bool recvTruncated(Win32Exception ex)
+ public static bool recvTruncated(SocketException ex)
{
- return ex.NativeErrorCode == WSAEMSGSIZE;
+ return socketErrorCode(ex) == SocketError.MessageSize;
}
- public static bool operationAborted(Win32Exception ex)
+ public static bool operationAborted(SocketException ex)
{
- return ex.NativeErrorCode == 995;
+ return socketErrorCode(ex) == SocketError.OperationAborted;
}
public static bool timeout(System.IO.IOException ex)
@@ -266,7 +340,7 @@ namespace IceInternal
{
try
{
- return ex != null && ((Win32Exception)ex).NativeErrorCode == WSAEMFILE;
+ return ex != null && socketErrorCode((SocketException)ex) == SocketError.TooManyOpenSockets;
}
catch(InvalidCastException)
{
@@ -327,13 +401,20 @@ namespace IceInternal
{
throw new Ice.SocketException(ex);
}
+ catch(ArgumentException ex)
+ {
+ throw new Ice.SocketException(ex);
+ }
+
if(!udp)
{
try
{
setTcpNoDelay(socket);
+#if !SILVERLIGHT
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, 1);
+#endif
}
catch(SocketException ex)
{
@@ -376,26 +457,31 @@ namespace IceInternal
}
}
- public static void setBlock(Socket socket, bool block)
+ public static void setTcpNoDelay(Socket socket)
{
try
{
- socket.Blocking = block;
+#if SILVERLIGHT
+ socket.NoDelay = true;
+#else
+ socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, 1);
+#endif
}
- catch(SocketException ex)
+ catch(System.Exception ex)
{
closeSocketNoThrow(socket);
throw new Ice.SocketException(ex);
}
}
- public static void setTcpNoDelay(Socket socket)
+#if !SILVERLIGHT
+ public static void setBlock(Socket socket, bool block)
{
try
{
- socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, 1);
+ socket.Blocking = block;
}
- catch(System.Exception ex)
+ catch(SocketException ex)
{
closeSocketNoThrow(socket);
throw new Ice.SocketException(ex);
@@ -414,12 +500,17 @@ namespace IceInternal
throw new Ice.SocketException(ex);
}
}
+#endif
public static void setSendBufferSize(Socket socket, int sz)
{
try
{
+#if SILVERLIGHT
+ socket.SendBufferSize = sz;
+#else
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, sz);
+#endif
}
catch(SocketException ex)
{
@@ -433,7 +524,11 @@ namespace IceInternal
int sz;
try
{
+#if SILVERLIGHT
+ sz = socket.SendBufferSize;
+#else
sz = (int)socket.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer);
+#endif
}
catch(SocketException ex)
{
@@ -447,7 +542,11 @@ namespace IceInternal
{
try
{
+#if SILVERLIGHT
+ socket.ReceiveBufferSize = sz;
+#else
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, sz);
+#endif
}
catch(SocketException ex)
{
@@ -461,7 +560,11 @@ namespace IceInternal
int sz = 0;
try
{
+#if SILVERLIGHT
+ sz = socket.ReceiveBufferSize;
+#else
sz = (int)socket.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer);
+#endif
}
catch(SocketException ex)
{
@@ -471,6 +574,7 @@ namespace IceInternal
return sz;
}
+#if !SILVERLIGHT
public static void setReuseAddress(Socket socket, bool reuse)
{
try
@@ -483,7 +587,7 @@ namespace IceInternal
throw new Ice.SocketException(ex);
}
}
-
+
public static void setMcastGroup(Socket socket, IPAddress group, string iface)
{
try
@@ -496,7 +600,7 @@ namespace IceInternal
ifaceAddr = getInterfaceAddress(iface);
if(ifaceAddr == IPAddress.Any)
{
- ifaceAddr = getAddress(iface, 0, EnableIPv4).Address;
+ ifaceAddr = ((IPEndPoint)getAddress(iface, 0, EnableIPv4)).Address;
}
}
socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership,
@@ -531,11 +635,15 @@ namespace IceInternal
throw new Ice.SocketException(ex);
}
}
-
+#endif
+
public static void setMcastTtl(Socket socket, int ttl, AddressFamily family)
{
try
{
+#if SILVERLIGHT
+ socket.Ttl = (short)ttl;
+#else
if(family == AddressFamily.InterNetwork)
{
socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, ttl);
@@ -544,6 +652,7 @@ namespace IceInternal
{
socket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.MulticastTimeToLive, ttl);
}
+#endif
}
catch(SocketException ex)
{
@@ -551,7 +660,8 @@ namespace IceInternal
throw new Ice.SocketException(ex);
}
}
-
+
+#if !SILVERLIGHT
public static IPEndPoint doBind(Socket socket, EndPoint addr)
{
try
@@ -585,7 +695,9 @@ namespace IceInternal
throw new Ice.SocketException(ex);
}
}
+#endif
+#if !SILVERLIGHT
public static bool doConnect(Socket fd, EndPoint addr)
{
repeatConnect:
@@ -643,7 +755,6 @@ namespace IceInternal
throw new Ice.ConnectionRefusedException();
}
}
-
return true;
}
@@ -665,7 +776,14 @@ namespace IceInternal
//
IPAddress any = fd.AddressFamily == AddressFamily.InterNetworkV6 ? IPAddress.IPv6Any : IPAddress.Any;
fd.Bind(new IPEndPoint(any, 0));
- return fd.BeginConnect(addr, callback, state);
+ return fd.BeginConnect(addr,
+ delegate(IAsyncResult result)
+ {
+ if(!result.CompletedSynchronously)
+ {
+ callback(result.AsyncState);
+ }
+ }, state);
}
catch(SocketException ex)
{
@@ -691,7 +809,6 @@ namespace IceInternal
// NOTE: It's the caller's responsability to close the socket upon
// failure to connect. The socket isn't closed by this method.
//
-
try
{
fd.EndConnect(result);
@@ -728,63 +845,43 @@ namespace IceInternal
}
}
}
+#endif
- public static IPEndPoint getAddress(string host, int port, int protocol)
+ public static EndPoint getAddress(string host, int port, int protocol)
{
return getAddressImpl(host, port, protocol, false);
}
-
- public static IPEndPoint getAddressForServer(string host, int port, int protocol)
+
+ public static EndPoint getAddressForServer(string host, int port, int protocol)
{
return getAddressImpl(host, port, protocol, true);
}
- public static int compareAddress(IPEndPoint addr1, IPEndPoint addr2)
+ public static List<EndPoint> getAddresses(string host, int port, int protocol)
{
- if(addr1.Port < addr2.Port)
- {
- return -1;
- }
- else if(addr2.Port < addr1.Port)
- {
- return 1;
- }
-
- byte[] larr = addr1.Address.GetAddressBytes();
- byte[] rarr = addr2.Address.GetAddressBytes();
-
- if(larr.Length < rarr.Length)
- {
- return -1;
- }
- else if(rarr.Length < larr.Length)
- {
- return 1;
- }
+ return getAddresses(host, port, protocol, true);
+ }
- for(int i = 0; i < larr.Length; i++)
+ public static List<EndPoint> getAddresses(string host, int port, int protocol, bool blocking)
+ {
+ List<EndPoint> addresses = new List<EndPoint>();
+#if SILVERLIGHT
+ if(host.Length == 0)
{
- if(larr[i] < rarr[i])
+ if(protocol != EnableIPv4)
{
- return -1;
+ addresses.Add(new DnsEndPoint(IPAddress.IPv6Loopback.ToString(), port));
}
- else if(rarr[i] < larr[i])
+ else
{
- return 1;
+ addresses.Add(new DnsEndPoint(IPAddress.Loopback.ToString(), port));
}
}
-
- return 0;
- }
-
- public static List<IPEndPoint> getAddresses(string host, int port, int protocol)
- {
- return getAddresses(host, port, protocol, true);
- }
-
- public static List<IPEndPoint> getAddresses(string host, int port, int protocol, bool blocking)
- {
- List<IPEndPoint> addresses = new List<IPEndPoint>();
+ else
+ {
+ addresses.Add(new DnsEndPoint(host, port));
+ }
+#else
if(host.Length == 0)
{
if(protocol != EnableIPv4)
@@ -796,7 +893,6 @@ namespace IceInternal
{
addresses.Add(new IPEndPoint(IPAddress.Loopback, port));
}
- return addresses;
}
else
{
@@ -826,11 +922,11 @@ namespace IceInternal
}
}
-#if COMPACT
+# if COMPACT
foreach(IPAddress a in Dns.GetHostEntry(host).AddressList)
-#else
+# else
foreach(IPAddress a in Dns.GetHostAddresses(host))
-#endif
+# endif
{
if((a.AddressFamily == AddressFamily.InterNetwork && protocol != EnableIPv6) ||
(a.AddressFamily == AddressFamily.InterNetworkV6 && protocol != EnableIPv4))
@@ -839,9 +935,9 @@ namespace IceInternal
}
}
}
- catch(Win32Exception ex)
+ catch(SocketException ex)
{
- if(ex.NativeErrorCode == WSATRY_AGAIN && --retry >= 0)
+ if(socketErrorCode(ex) == SocketError.TryAgain && --retry >= 0)
{
goto repeatGetHostByName;
}
@@ -866,21 +962,23 @@ namespace IceInternal
throw e;
}
}
-
+#endif
return addresses;
}
public static IPAddress[] getLocalAddresses(int protocol)
{
- ArrayList addresses;
-
+#if SILVERLIGHT
+ return new List<IPAddress>().ToArray();
+#else
+ List<IPAddress> addresses;
int retry = 5;
- repeatGetHostByName:
+ repeatGetHostByName:
try
{
- addresses = new ArrayList();
-#if !COMPACT
+ addresses = new List<IPAddress>();
+# if !COMPACT
if(AssemblyUtil.runtime_ != AssemblyUtil.Runtime.Mono)
{
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
@@ -902,13 +1000,13 @@ namespace IceInternal
}
}
else
-#endif
+# endif
{
-#if COMPACT
+# if COMPACT
foreach(IPAddress a in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
-#else
+# else
foreach(IPAddress a in Dns.GetHostAddresses(Dns.GetHostName()))
-#endif
+# endif
{
if((a.AddressFamily == AddressFamily.InterNetwork && protocol != EnableIPv6) ||
(a.AddressFamily == AddressFamily.InterNetworkV6 && protocol != EnableIPv4))
@@ -921,9 +1019,9 @@ namespace IceInternal
}
}
}
- catch(Win32Exception ex)
+ catch(SocketException ex)
{
- if(ex.NativeErrorCode == WSATRY_AGAIN && --retry >= 0)
+ if(socketErrorCode(ex) == SocketError.TryAgain && --retry >= 0)
{
goto repeatGetHostByName;
}
@@ -938,7 +1036,8 @@ namespace IceInternal
throw e;
}
- return (IPAddress[])addresses.ToArray(typeof(IPAddress));
+ return addresses.ToArray();
+#endif
}
public static void
@@ -1053,7 +1152,11 @@ namespace IceInternal
public static string fdLocalAddressToString(Socket socket)
{
System.Text.StringBuilder s = new System.Text.StringBuilder();
- IPEndPoint localEndpoint = getLocalAddress(socket);
+#if SILVERLIGHT
+ // Silverlight Socket doesn't expose the local endpoint
+ s.Append("local address = <not available>");
+#else
+ IPEndPoint localEndpoint = (IPEndPoint)getLocalAddress(socket);
if(localEndpoint == null)
{
// This might occur if connect was not called yet, see also comments in doBeginConnectAsync
@@ -1064,34 +1167,52 @@ namespace IceInternal
s.Append("local address = " + localEndpoint.Address);
s.Append(":" + localEndpoint.Port);
}
+#endif
return s.ToString();
}
public static string
- addressesToString(IPEndPoint localEndpoint, IPEndPoint remoteEndpoint)
+ addressesToString(EndPoint localEndpoint, EndPoint remoteEndpoint)
{
System.Text.StringBuilder s = new System.Text.StringBuilder();
- if(localEndpoint == null)
+#if SILVERLIGHT
+ DnsEndPoint remoteDnsEndPoint = (DnsEndPoint)remoteEndpoint;
+ // Silverlight Socket doesn't expose the local endpoint
+ s.Append("local address = <not available>");
+
+ if(remoteDnsEndPoint == null)
+ {
+ s.Append("\nremote address = <not connected>");
+ }
+ else
+ {
+ s.Append("\nremote address = " + remoteDnsEndPoint.Host);
+ s.Append(":" + remoteDnsEndPoint.Port);
+ }
+#else
+ IPEndPoint localPEndpoint = (IPEndPoint)localEndpoint;
+ IPEndPoint remoteIPEndPoint = (IPEndPoint)remoteEndpoint;
+ if(localPEndpoint == null)
{
// This might occur if connect was not called yet, see also comments in doBeginConnectAsync
s.Append("local address = <not bound>");
}
else
{
- s.Append("local address = " + localEndpoint.Address);
- s.Append(":" + localEndpoint.Port);
+ s.Append("local address = " + localPEndpoint.Address);
+ s.Append(":" + localPEndpoint.Port);
}
- if(remoteEndpoint == null)
+ if(remoteIPEndPoint == null)
{
s.Append("\nremote address = <not connected>");
}
else
{
- s.Append("\nremote address = " + remoteEndpoint.Address);
- s.Append(":" + remoteEndpoint.Port);
+ s.Append("\nremote address = " + remoteIPEndPoint.Address);
+ s.Append(":" + remoteIPEndPoint.Port);
}
-
+#endif
return s.ToString();
}
@@ -1101,28 +1222,31 @@ namespace IceInternal
return addr.ToString();
}
- public static IPEndPoint
+ public static EndPoint
getLocalAddress(Socket socket)
- {
- IPEndPoint localEndpoint;
+ {
+ EndPoint localEndpoint = null;
+ // Silverlight socket doesn't exposes a local endpoint
+#if !SILVERLIGHT
try
{
- localEndpoint = (IPEndPoint)socket.LocalEndPoint;
+ localEndpoint = (EndPoint)socket.LocalEndPoint;
}
catch(SocketException ex)
{
throw new Ice.SocketException(ex);
}
+#endif
return localEndpoint;
}
- public static IPEndPoint
+ public static EndPoint
getRemoteAddress(Socket socket)
{
- IPEndPoint remoteEndpoint = null;
+ EndPoint remoteEndpoint = null;
try
{
- remoteEndpoint = (IPEndPoint)socket.RemoteEndPoint;
+ remoteEndpoint = (EndPoint)socket.RemoteEndPoint;
}
catch(SocketException)
{
@@ -1133,7 +1257,7 @@ namespace IceInternal
private static int
getInterfaceIndex(string name)
{
-#if !COMPACT
+#if !COMPACT && !SILVERLIGHT
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
foreach(NetworkInterface ni in nics)
{
@@ -1154,7 +1278,7 @@ namespace IceInternal
private static IPAddress
getInterfaceAddress(string name)
{
-#if !COMPACT
+#if !COMPACT && !SILVERLIGHT
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
foreach(NetworkInterface ni in nics)
{
@@ -1174,5 +1298,39 @@ namespace IceInternal
#endif
return IPAddress.Any;
}
+
+ public static string
+ endpointAddressToString(EndPoint endpoint)
+ {
+ System.Text.StringBuilder s = new System.Text.StringBuilder();
+ if(endpoint != null)
+ {
+#if SILVERLIGHT
+ DnsEndPoint dnsEndpoint = (DnsEndPoint) endpoint;
+ s.Append(dnsEndpoint.Host);
+#else
+ IPEndPoint ipEndpoint = (IPEndPoint) endpoint;
+ s.Append(ipEndpoint.Address.ToString());
+#endif
+ }
+ return s.ToString();
+ }
+
+ public static int
+ endpointPort(EndPoint endpoint)
+ {
+ int port = -1;
+ if(endpoint != null)
+ {
+#if SILVERLIGHT
+ DnsEndPoint dnsEndpoint = (DnsEndPoint) endpoint;
+ port = dnsEndpoint.Port;
+#else
+ IPEndPoint ipEndpoint = (IPEndPoint) endpoint;
+ port = ipEndpoint.Port;
+#endif
+ }
+ return port;
+ }
}
}
diff --git a/cs/src/Ice/Object.cs b/cs/src/Ice/Object.cs
index 8159aeed3ef..e251b233cdb 100644
--- a/cs/src/Ice/Object.cs
+++ b/cs/src/Ice/Object.cs
@@ -62,7 +62,7 @@ namespace Ice
/// <summary>
/// the base interface for servants.
/// </summary>
- public interface Object : System.ICloneable
+ public interface Object : System.ICloneable
{
/// <summary>
/// This method is deprecated. Use GetHashCode instead.
diff --git a/cs/src/Ice/ObjectFactoryManager.cs b/cs/src/Ice/ObjectFactoryManager.cs
index d09ca4b1c3e..8c3970b87b0 100644
--- a/cs/src/Ice/ObjectFactoryManager.cs
+++ b/cs/src/Ice/ObjectFactoryManager.cs
@@ -10,7 +10,7 @@
namespace IceInternal
{
- using System.Collections;
+ using System.Collections.Generic;
public sealed class ObjectFactoryManager
{
@@ -18,8 +18,7 @@ namespace IceInternal
{
lock(this)
{
- object o = _factoryMap[id];
- if(o != null)
+ if(_factoryMap.ContainsKey(id))
{
Ice.AlreadyRegisteredException ex = new Ice.AlreadyRegisteredException();
ex.id = id;
@@ -35,8 +34,7 @@ namespace IceInternal
object o = null;
lock(this)
{
- o = _factoryMap[id];
- if(o == null)
+ if(!_factoryMap.ContainsKey(id))
{
Ice.NotRegisteredException ex = new Ice.NotRegisteredException();
ex.id = id;
@@ -52,7 +50,9 @@ namespace IceInternal
{
lock(this)
{
- return (Ice.ObjectFactory)_factoryMap[id];
+ Ice.ObjectFactory factory = null;
+ _factoryMap.TryGetValue(id, out factory);
+ return factory;
}
}
@@ -61,17 +61,17 @@ namespace IceInternal
//
internal ObjectFactoryManager()
{
- _factoryMap = new Hashtable();
+ _factoryMap = new Dictionary<string, Ice.ObjectFactory>();
}
internal void destroy()
{
- Hashtable oldMap = null;
+ Dictionary<string, Ice.ObjectFactory> oldMap = null;
lock(this)
{
oldMap = _factoryMap;
- _factoryMap = new Hashtable();
+ _factoryMap = new Dictionary<string, Ice.ObjectFactory>();
}
foreach(Ice.ObjectFactory factory in oldMap.Values)
@@ -80,7 +80,7 @@ namespace IceInternal
}
}
- private Hashtable _factoryMap;
+ private Dictionary<string, Ice.ObjectFactory> _factoryMap;
}
}
diff --git a/cs/src/Ice/Options.cs b/cs/src/Ice/Options.cs
index 46b9b2b15ad..8424e8651ac 100644
--- a/cs/src/Ice/Options.cs
+++ b/cs/src/Ice/Options.cs
@@ -7,7 +7,7 @@
//
// **********************************************************************
-using System.Collections;
+using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
@@ -38,7 +38,7 @@ namespace IceUtilInternal
State state = State.Normal;
string arg = "";
- ArrayList vec = new ArrayList();
+ List<string> vec = new List<string>();
for(int i = 0; i < l.Length; ++i)
{
@@ -400,7 +400,7 @@ namespace IceUtilInternal
}
}
- return (string[])vec.ToArray(typeof(string));
+ return (string[])vec.ToArray();
}
}
}
diff --git a/cs/src/Ice/OutgoingAsync.cs b/cs/src/Ice/OutgoingAsync.cs
index 978bcae8ac1..56532af2dee 100644
--- a/cs/src/Ice/OutgoingAsync.cs
+++ b/cs/src/Ice/OutgoingAsync.cs
@@ -257,7 +257,11 @@ namespace IceInternal
{
if(waitHandle_ == null)
{
+#if SILVERLIGHT
+ waitHandle_ = new ManualResetEvent(false);
+#else
waitHandle_ = new EventWaitHandle(false, EventResetMode.ManualReset);
+#endif
}
if((state_ & Done) != 0)
{
diff --git a/cs/src/Ice/OutputBase.cs b/cs/src/Ice/OutputBase.cs
index 038cbeffaa8..7e2f9e02ed4 100644
--- a/cs/src/Ice/OutputBase.cs
+++ b/cs/src/Ice/OutputBase.cs
@@ -10,7 +10,7 @@
namespace IceUtilInternal
{
-using System.Collections;
+using System.Collections.Generic;
using System.IO;
using System.Diagnostics;
@@ -24,7 +24,7 @@ public class OutputBase
indent_ = 0;
indentSize_ = 4;
useTab_ = true;
- indentSave_ = new Stack();
+ indentSave_ = new Stack<int>();
separator_ = true;
}
@@ -36,7 +36,7 @@ public class OutputBase
indent_ = 0;
indentSize_ = 4;
useTab_ = true;
- indentSave_ = new Stack();
+ indentSave_ = new Stack<int>();
separator_ = true;
}
@@ -48,7 +48,7 @@ public class OutputBase
indent_ = 0;
indentSize_ = 4;
useTab_ = true;
- indentSave_ = new Stack();
+ indentSave_ = new Stack<int>();
separator_ = true;
}
@@ -185,7 +185,7 @@ public class OutputBase
protected internal int pos_;
protected internal int indent_;
protected internal int indentSize_;
- protected internal Stack indentSave_;
+ protected internal Stack<int> indentSave_;
protected internal bool useTab_;
protected internal bool separator_;
}
diff --git a/cs/src/Ice/PluginManagerI.cs b/cs/src/Ice/PluginManagerI.cs
index 081d6d7083a..9e128ebf71d 100644
--- a/cs/src/Ice/PluginManagerI.cs
+++ b/cs/src/Ice/PluginManagerI.cs
@@ -7,6 +7,7 @@
//
// **********************************************************************
+#if !SILVERLIGHT
namespace Ice
{
using System;
@@ -518,3 +519,4 @@ namespace Ice
private static bool _sslWarnOnce = false;
}
}
+#endif
diff --git a/cs/src/Ice/PropertiesI.cs b/cs/src/Ice/PropertiesI.cs
index a514a048123..ac6736b59ba 100644
--- a/cs/src/Ice/PropertiesI.cs
+++ b/cs/src/Ice/PropertiesI.cs
@@ -42,8 +42,8 @@ namespace Ice
lock(this)
{
string result = "";
- PropertyValue pv = (PropertyValue)_properties[key];
- if(pv != null)
+ PropertyValue pv;
+ if(_properties.TryGetValue(key, out pv))
{
pv.used = true;
result = pv.val;
@@ -57,8 +57,8 @@ namespace Ice
lock(this)
{
string result = val;
- PropertyValue pv = (PropertyValue)_properties[key];
- if(pv != null)
+ PropertyValue pv;
+ if(_properties.TryGetValue(key, out pv))
{
pv.used = true;
result = pv.val;
@@ -76,24 +76,21 @@ namespace Ice
{
lock(this)
{
- PropertyValue pv = (PropertyValue)_properties[key];
- if(pv == null)
+ PropertyValue pv;
+ if(!_properties.TryGetValue(key, out pv))
{
- return val;
+ return val;
}
- else
+ pv.used = true;
+ try
{
- pv.used = true;
- try
- {
- return System.Int32.Parse(pv.val, CultureInfo.InvariantCulture);
- }
- catch(System.FormatException)
- {
- Ice.Util.getProcessLogger().warning("numeric property " + key +
- " set to non-numeric value, defaulting to " + val);
- return val;
- }
+ return System.Int32.Parse(pv.val, CultureInfo.InvariantCulture);
+ }
+ catch(System.FormatException)
+ {
+ Ice.Util.getProcessLogger().warning("numeric property " + key +
+ " set to non-numeric value, defaulting to " + val);
+ return val;
}
}
}
@@ -112,26 +109,24 @@ namespace Ice
lock(this)
{
- PropertyValue pv = (PropertyValue)_properties[key];
- if(pv == null)
+ PropertyValue pv;
+ if(!_properties.TryGetValue(key, out pv))
+ {
+ return val;
+ }
+
+ pv.used = true;
+
+ string[] result = IceUtilInternal.StringUtil.splitString(pv.val, ", \t\r\n");
+ if(result == null)
{
+ Ice.Util.getProcessLogger().warning("mismatched quotes in property " + key
+ + "'s value, returning default value");
return val;
}
else
{
- pv.used = true;
-
- string[] result = IceUtilInternal.StringUtil.splitString(pv.val, ", \t\r\n");
- if(result == null)
- {
- Ice.Util.getProcessLogger().warning("mismatched quotes in property " + key
- + "'s value, returning default value");
- return val;
- }
- else
- {
- return result;
- }
+ return result;
}
}
}
@@ -219,8 +214,8 @@ namespace Ice
//
if(val != null && val.Length > 0)
{
- PropertyValue pv = (PropertyValue)_properties[key];
- if(pv != null)
+ PropertyValue pv;
+ if(_properties.TryGetValue(key, out pv))
{
pv.val = val;
}
@@ -243,9 +238,9 @@ namespace Ice
{
string[] result = new string[_properties.Count];
int i = 0;
- foreach(DictionaryEntry entry in _properties)
+ foreach(KeyValuePair<string, PropertyValue> entry in _properties)
{
- result[i++] = "--" + entry.Key + "=" + ((PropertyValue)entry.Value).val;
+ result[i++] = "--" + entry.Key + "=" + entry.Value.val;
}
return result;
}
@@ -259,7 +254,7 @@ namespace Ice
}
pfx = "--" + pfx;
- ArrayList result = new ArrayList();
+ List<string> result = new List<string>();
for(int i = 0; i < options.Length; i++)
{
string opt = options[i];
@@ -297,6 +292,7 @@ namespace Ice
public void load(string file)
{
+#if !SILVERLIGHT
if(IceInternal.AssemblyUtil.platform_ == IceInternal.AssemblyUtil.Platform.Windows &&
(file.StartsWith("HKLM\\", StringComparison.Ordinal)))
{
@@ -319,6 +315,7 @@ namespace Ice
}
else
{
+#endif
try
{
using(System.IO.StreamReader sr = new System.IO.StreamReader(file))
@@ -332,7 +329,9 @@ namespace Ice
fe.path = file;
throw fe;
}
+#if !SILVERLIGHT
}
+#endif
}
public Properties ice_clone_()
@@ -342,15 +341,15 @@ namespace Ice
return new PropertiesI(this);
}
}
-
- public ArrayList getUnusedProperties()
+
+ public List<string> getUnusedProperties()
{
lock(this)
{
- ArrayList unused = new ArrayList();
- foreach(DictionaryEntry entry in _properties)
+ List<string> unused = new List<string>();
+ foreach(KeyValuePair<string, PropertyValue> entry in _properties)
{
- if(!((PropertyValue)entry.Value).used)
+ if(!entry.Value.used)
{
unused.Add(entry.Key);
}
@@ -361,37 +360,33 @@ namespace Ice
internal PropertiesI(PropertiesI p)
{
- _properties = new Hashtable();
- foreach(DictionaryEntry entry in p._properties)
- {
- _properties[entry.Key] = new PropertyValue((PropertyValue)entry.Value);
- }
+ _properties = new Dictionary<string, PropertyValue>(p._properties);
}
internal PropertiesI()
{
- _properties = new Hashtable();
+ _properties = new Dictionary<string, PropertyValue>();
}
internal PropertiesI(ref string[] args, Properties defaults)
{
if(defaults == null)
{
- _properties = new Hashtable();
+ _properties = new Dictionary<string, PropertyValue>();
}
else
{
_properties = ((PropertiesI)defaults)._properties;
}
- PropertyValue pv = (PropertyValue)_properties["Ice.ProgramName"];
- if(pv == null)
+ PropertyValue pv;
+ if(_properties.TryGetValue("Ice.ProgramName", out pv))
{
- _properties["Ice.ProgramName"] = new PropertyValue(System.AppDomain.CurrentDomain.FriendlyName, true);
+ pv.used = true;
}
else
{
- pv.used = true;
+ _properties["Ice.ProgramName"] = new PropertyValue(System.AppDomain.CurrentDomain.FriendlyName, true);
}
bool loadConfigFiles = false;
@@ -423,7 +418,7 @@ namespace Ice
//
// If Ice.Config is not set, load from ICE_CONFIG (if set)
//
- loadConfigFiles = (_properties["Ice.Config"] == null);
+ loadConfigFiles = !_properties.ContainsKey("Ice.Config");
}
if(loadConfigFiles)
@@ -626,7 +621,7 @@ namespace Ice
{
string val = getProperty("Ice.Config");
-#if !COMPACT
+#if !COMPACT && !SILVERLIGHT
if(val.Length == 0 || val.Equals("1"))
{
string s = System.Environment.GetEnvironmentVariable("ICE_CONFIG");
@@ -650,6 +645,6 @@ namespace Ice
_properties["Ice.Config"] = new PropertyValue(val, true);
}
- private Hashtable _properties;
+ private Dictionary<string, PropertyValue> _properties;
}
}
diff --git a/cs/src/Ice/ProtocolPluginFacade.cs b/cs/src/Ice/ProtocolPluginFacade.cs
index adac4589b59..27c8a3b268e 100644
--- a/cs/src/Ice/ProtocolPluginFacade.cs
+++ b/cs/src/Ice/ProtocolPluginFacade.cs
@@ -17,11 +17,12 @@ namespace IceInternal
//
Ice.Communicator getCommunicator();
+#if !SILVERLIGHT
//
// Get the endpoint host resolver.
//
IceInternal.EndpointHostResolver getEndpointHostResolver();
-
+#endif
//
// Get the protocol support.
//
@@ -71,6 +72,7 @@ namespace IceInternal
return _communicator;
}
+#if !SILVERLIGHT
//
// Get the endpoint host resolver.
//
@@ -78,6 +80,7 @@ namespace IceInternal
{
return _instance.endpointHostResolver();
}
+#endif
//
// Get the protocol support.
diff --git a/cs/src/Ice/Reference.cs b/cs/src/Ice/Reference.cs
index 7d5759f2838..c52bfa90a6e 100644
--- a/cs/src/Ice/Reference.cs
+++ b/cs/src/Ice/Reference.cs
@@ -1360,7 +1360,7 @@ namespace IceInternal
private EndpointI[] filterEndpoints(EndpointI[] allEndpoints)
{
- ArrayList endpoints = new ArrayList();
+ List<EndpointI> endpoints = new List<EndpointI>();
//
// Filter out unknown endpoints.
@@ -1385,7 +1385,7 @@ namespace IceInternal
//
// Filter out datagram endpoints.
//
- ArrayList tmp = new ArrayList();
+ List<EndpointI> tmp = new List<EndpointI>();
foreach(EndpointI endpoint in endpoints)
{
if(!endpoint.datagram())
@@ -1403,7 +1403,7 @@ namespace IceInternal
//
// Filter out non-datagram endpoints.
//
- ArrayList tmp = new ArrayList();
+ List<EndpointI> tmp = new List<EndpointI>();
foreach(EndpointI endpoint in endpoints)
{
if(endpoint.datagram())
@@ -1431,7 +1431,7 @@ namespace IceInternal
Debug.Assert(r >= i && r < endpoints.Count);
if(r != i)
{
- object tmp = endpoints[i];
+ EndpointI tmp = endpoints[i];
endpoints[i] = endpoints[r];
endpoints[r] = tmp;
}
@@ -1461,7 +1461,7 @@ namespace IceInternal
DefaultsAndOverrides overrides = getInstance().defaultsAndOverrides();
if(overrides.overrideSecure ? overrides.overrideSecureValue : getSecure())
{
- ArrayList tmp = new ArrayList();
+ List<EndpointI> tmp = new List<EndpointI>();
foreach(EndpointI endpoint in endpoints)
{
if(endpoint.secure())
@@ -1473,11 +1473,11 @@ namespace IceInternal
}
else if(getPreferSecure())
{
- IceUtilInternal.Arrays.Sort(ref endpoints, _preferSecureEndpointComparator);
+ Sort(ref endpoints, _preferSecureEndpointComparator);
}
else
{
- IceUtilInternal.Arrays.Sort(ref endpoints, _preferNonSecureEndpointComparator);
+ Sort(ref endpoints, _preferNonSecureEndpointComparator);
}
EndpointI[] arr = new EndpointI[endpoints.Count];
@@ -1642,17 +1642,15 @@ namespace IceInternal
}
}
- private class EndpointComparator : IComparer
+ private class EndpointComparator : IComparer<IceInternal.EndpointI>
{
public EndpointComparator(bool preferSecure)
{
_preferSecure = preferSecure;
}
- public int Compare(object l, object r)
+ public int Compare(IceInternal.EndpointI le, IceInternal.EndpointI re)
{
- IceInternal.EndpointI le = (IceInternal.EndpointI)l;
- IceInternal.EndpointI re = (IceInternal.EndpointI)r;
bool ls = le.secure();
bool rs = re.secure();
if((ls && rs) || (!ls && !rs))
@@ -1685,6 +1683,63 @@ namespace IceInternal
private bool _preferSecure;
}
+
+ private static void Sort(ref List<IceInternal.EndpointI> array, IComparer<IceInternal.EndpointI> comparator)
+ {
+ //
+ // This Sort method implements the merge sort algorithm
+ // which is a stable sort (unlike the Sort method of the
+ // System.Collections.ArrayList which is unstable).
+ //
+ Sort1(ref array, 0, array.Count, comparator);
+ }
+
+ private static void Sort1(ref List<IceInternal.EndpointI> array, int begin, int end, IComparer<IceInternal.EndpointI> comparator)
+ {
+ int mid;
+ if(end - begin <= 1)
+ {
+ return;
+ }
+
+ mid = (begin + end) / 2;
+ Sort1(ref array, begin, mid, comparator);
+ Sort1(ref array, mid, end, comparator);
+ Merge(ref array, begin, mid, end, comparator);
+ }
+
+ private static void Merge(ref List<IceInternal.EndpointI> array, int begin, int mid, int end, IComparer<IceInternal.EndpointI> comparator)
+ {
+ int i = begin;
+ int j = mid;
+ int k = 0;
+
+ IceInternal.EndpointI[] tmp = new IceInternal.EndpointI[end - begin];
+ while(i < mid && j < end)
+ {
+ if(comparator.Compare(array[i], array[j]) <= 0)
+ {
+ tmp[k++] = array[i++];
+ }
+ else
+ {
+ tmp[k++] = array[j++];
+ }
+ }
+
+ while(i < mid)
+ {
+ tmp[k++] = array[i++];
+ }
+ while(j < end)
+ {
+ tmp[k++] = array[j++];
+ }
+ for(i = 0; i < (end - begin); ++i)
+ {
+ array[begin + i] = tmp[i];
+ }
+ }
private static EndpointComparator _preferNonSecureEndpointComparator = new EndpointComparator(false);
private static EndpointComparator _preferSecureEndpointComparator = new EndpointComparator(true);
diff --git a/cs/src/Ice/ReferenceFactory.cs b/cs/src/Ice/ReferenceFactory.cs
index d01b5bb420c..b1b03ecc17e 100644
--- a/cs/src/Ice/ReferenceFactory.cs
+++ b/cs/src/Ice/ReferenceFactory.cs
@@ -353,11 +353,11 @@ namespace IceInternal
return create(ident, facet, mode, secure, null, null, propertyPrefix);
}
- ArrayList endpoints = new ArrayList();
+ List<EndpointI> endpoints = new List<EndpointI>();
if(s[beg] == ':')
{
- ArrayList unknownEndpoints = new ArrayList();
+ List<string> unknownEndpoints = new List<string>();
end = beg;
while(end < s.Length && s[end] == ':')
@@ -440,7 +440,7 @@ namespace IceInternal
instance_.initializationData().logger.warning(msg.ToString());
}
- EndpointI[] ep = (EndpointI[])endpoints.ToArray(typeof(EndpointI));
+ EndpointI[] ep = endpoints.ToArray();
return create(ident, facet, mode, secure, ep, null, propertyPrefix);
}
else if(s[beg] == '@')
@@ -629,13 +629,17 @@ namespace IceInternal
// set.
//
WeakReference w = new WeakReference(@ref);
- WeakReference val = (WeakReference)_references[w];
- if(val != null)
+ object v;
+ if(_references.TryGetValue(w, out v))
{
- Reference r = (Reference)val.Target;
- if(r != null && r.Equals(@ref))
+ WeakReference val = (WeakReference)v;
+ if(val != null)
{
- return r;
+ Reference r = (Reference)val.Target;
+ if(r != null && r.Equals(@ref))
+ {
+ return r;
+ }
}
}
_references[w] = w;
@@ -668,7 +672,7 @@ namespace IceInternal
}
}
- ArrayList unknownProps = new ArrayList();
+ List<string> unknownProps = new List<string>();
Dictionary<string, string> props
= instance_.initializationData().properties.getPropertiesForPrefix(prefix + ".");
foreach(String prop in props.Keys)
@@ -820,7 +824,7 @@ namespace IceInternal
private Ice.Communicator _communicator;
private Ice.RouterPrx _defaultRouter;
private Ice.LocatorPrx _defaultLocator;
- private Hashtable _references = new Hashtable();
+ private Dictionary<Object, Object> _references = new Dictionary<Object, Object>();
}
}
diff --git a/cs/src/Ice/SliceChecksums.cs b/cs/src/Ice/SliceChecksums.cs
index d4f63cb24db..b72d38ca32e 100644
--- a/cs/src/Ice/SliceChecksums.cs
+++ b/cs/src/Ice/SliceChecksums.cs
@@ -19,7 +19,7 @@ namespace Ice
{
public static Dictionary<string, string> checksums = new Dictionary<string, string>();
-#if !COMPACT
+#if !COMPACT && !SILVERLIGHT
static SliceChecksums()
{
Type[] types = IceInternal.AssemblyUtil.findTypesWithPrefix("IceInternal.SliceChecksums");
diff --git a/cs/src/Ice/SysLoggerI.cs b/cs/src/Ice/SysLoggerI.cs
index 1354af063fa..71aee38c187 100644
--- a/cs/src/Ice/SysLoggerI.cs
+++ b/cs/src/Ice/SysLoggerI.cs
@@ -7,6 +7,7 @@
//
// **********************************************************************
+#if !SILVERLIGHT
using System.Net.Sockets;
namespace Ice
@@ -120,8 +121,8 @@ namespace Ice
//
try
{
- _host = IceInternal.Network.getAddress(System.Net.Dns.GetHostName(), _port,
- IceInternal.Network.EnableBoth).Address;
+ _host = ((System.Net.IPEndPoint)IceInternal.Network.getAddress(System.Net.Dns.GetHostName(), _port,
+ IceInternal.Network.EnableBoth)).Address;
_socket = new UdpClient();
_socket.Connect(_host, _port);
}
@@ -225,3 +226,4 @@ namespace Ice
}
}
+#endif
diff --git a/cs/src/Ice/TcpAcceptor.cs b/cs/src/Ice/TcpAcceptor.cs
index 21a1d58be34..d997ca8c5ff 100644
--- a/cs/src/Ice/TcpAcceptor.cs
+++ b/cs/src/Ice/TcpAcceptor.cs
@@ -7,6 +7,8 @@
//
// **********************************************************************
+#if !SILVERLIGHT
+
namespace IceInternal
{
@@ -57,7 +59,13 @@ namespace IceInternal
{
try
{
- _result = _fd.BeginAccept(callback, state);
+ _result = _fd.BeginAccept(delegate(IAsyncResult result)
+ {
+ if(!result.CompletedSynchronously)
+ {
+ callback(result.AsyncState);
+ }
+ }, state);
}
catch(SocketException ex)
{
@@ -90,9 +98,9 @@ namespace IceInternal
}
Network.setBlock(_acceptFd, false);
-#if !COMPACT
+# if !COMPACT
Network.setTcpBufSize(_acceptFd, instance_.initializationData().properties, _logger);
-#endif
+# endif
if(_traceLevels.network >= 1)
{
@@ -125,12 +133,12 @@ namespace IceInternal
try
{
- _addr = Network.getAddressForServer(host, port, instance_.protocolSupport());
+ _addr = (IPEndPoint)Network.getAddressForServer(host, port, instance_.protocolSupport());
_fd = Network.createSocket(false, _addr.AddressFamily);
Network.setBlock(_fd, false);
-#if !COMPACT
+# if !COMPACT
Network.setTcpBufSize(_fd, instance_.initializationData().properties, _logger);
-#endif
+# endif
if(AssemblyUtil.platform_ != AssemblyUtil.Platform.Windows)
{
//
@@ -172,5 +180,5 @@ namespace IceInternal
private IPEndPoint _addr;
private IAsyncResult _result;
}
-
}
+#endif
diff --git a/cs/src/Ice/TcpConnector.cs b/cs/src/Ice/TcpConnector.cs
index 7045e258ebd..8af5f967246 100644
--- a/cs/src/Ice/TcpConnector.cs
+++ b/cs/src/Ice/TcpConnector.cs
@@ -28,8 +28,13 @@ namespace IceInternal
try
{
+
+#if SILVERLIGHT
+ Socket fd = Network.createSocket(false, AddressFamily.InterNetwork);
+#else
Socket fd = Network.createSocket(false, _addr.AddressFamily);
Network.setBlock(fd, false);
+#endif
#if !COMPACT
Network.setTcpBufSize(fd, _instance.initializationData().properties, _logger);
#endif
@@ -58,12 +63,16 @@ namespace IceInternal
//
// Only for use by TcpEndpoint
//
- internal TcpConnector(Instance instance, IPEndPoint addr, int timeout, string connectionId)
+ internal TcpConnector(Instance instance, EndPoint addr, int timeout, string connectionId)
{
_instance = instance;
_traceLevels = instance.traceLevels();
_logger = instance.initializationData().logger;
- _addr = addr;
+#if SILVERLIGHT
+ _addr = (DnsEndPoint)addr;
+#else
+ _addr = (IPEndPoint)addr;
+#endif
_timeout = timeout;
_connectionId = connectionId;
@@ -100,7 +109,7 @@ namespace IceInternal
return false;
}
- return Network.compareAddress(_addr, p._addr) == 0;
+ return _addr.Equals(p._addr);
}
public override string ToString()
@@ -116,7 +125,11 @@ namespace IceInternal
private Instance _instance;
private TraceLevels _traceLevels;
private Ice.Logger _logger;
+#if SILVERLIGHT
+ private DnsEndPoint _addr;
+#else
private IPEndPoint _addr;
+#endif
private int _timeout;
private string _connectionId;
private int _hashCode;
diff --git a/cs/src/Ice/TcpEndpointI.cs b/cs/src/Ice/TcpEndpointI.cs
index 6012874b68e..42150007914 100644
--- a/cs/src/Ice/TcpEndpointI.cs
+++ b/cs/src/Ice/TcpEndpointI.cs
@@ -391,11 +391,17 @@ namespace IceInternal
return connectors(Network.getAddresses(_host, _port, _instance.protocolSupport()));
}
+
public override void connectors_async(EndpointI_connectors callback)
{
+#if SILVERLIGHT
+ callback.connectors(connectors());
+#else
_instance.endpointHostResolver().resolve(_host, _port, this, callback);
+#endif
}
+
//
// Return an acceptor for this endpoint, or null if no acceptors
// is available. In case an acceptor is created, this operation
@@ -405,9 +411,13 @@ namespace IceInternal
//
public override Acceptor acceptor(ref EndpointI endpoint, string adapterName)
{
+#if SILVERLIGHT
+ throw new Ice.FeatureNotSupportedException("server endpoint not supported for `" + ToString() + "'");
+#else
TcpAcceptor p = new TcpAcceptor(_instance, _host, _port);
endpoint = new TcpEndpointI(_instance, _host, p.effectivePort(), _timeout, _connectionId, _compress);
return p;
+#endif
}
//
@@ -449,10 +459,10 @@ namespace IceInternal
return tcpEndpointI._host.Equals(_host) && tcpEndpointI._port == _port;
}
- public override List<Connector> connectors(List<IPEndPoint> addresses)
+ public override List<Connector> connectors(List<EndPoint> addresses)
{
List<Connector> connectors = new List<Connector>();
- foreach(IPEndPoint addr in addresses)
+ foreach(EndPoint addr in addresses)
{
connectors.Add(new TcpConnector(_instance, addr, _timeout, _connectionId));
}
diff --git a/cs/src/Ice/TcpTransceiver.cs b/cs/src/Ice/TcpTransceiver.cs
index c7210b1d37b..dab6897e12f 100644
--- a/cs/src/Ice/TcpTransceiver.cs
+++ b/cs/src/Ice/TcpTransceiver.cs
@@ -29,8 +29,23 @@ namespace IceInternal
{
try
{
+#if SILVERLIGHT
+ if(_writeEventArgs.SocketError != SocketError.Success)
+ {
+ SocketException ex = new SocketException((int)_writeEventArgs.SocketError);
+ if(Network.connectionRefused(ex))
+ {
+ throw new Ice.ConnectionRefusedException(ex);
+ }
+ else
+ {
+ throw new Ice.ConnectFailedException(ex);
+ }
+ }
+#else
Network.doFinishConnectAsync(_fd, _writeResult);
_writeResult = null;
+#endif
_state = StateConnected;
_desc = Network.fdToString(_fd);
}
@@ -88,9 +103,9 @@ namespace IceInternal
public bool write(Buffer buf)
{
-#if COMPACT
+#if COMPACT || SILVERLIGHT
//
- // The Compact Framework does not support the use of synchronous socket
+ // Silverlight and the Compact .NET Frameworks don't support the use of synchronous socket
// operations on a non-blocking socket. Returning false here forces the
// caller to schedule an asynchronous operation.
//
@@ -128,7 +143,7 @@ namespace IceInternal
{
ret = _fd.Send(buf.b.rawBytes(), buf.b.position(), packetSize, SocketFlags.None);
}
- catch(Win32Exception e)
+ catch(SocketException e)
{
if(Network.wouldBlock(e))
{
@@ -173,9 +188,9 @@ namespace IceInternal
public bool read(Buffer buf)
{
-#if COMPACT
+#if COMPACT || SILVERLIGHT
//
- // The .NET Compact Framework does not support the use of synchronous socket
+ // Silverlight and the Compact .NET Framework don't support the use of synchronous socket
// operations on a non-blocking socket.
//
return false;
@@ -211,7 +226,7 @@ namespace IceInternal
throw new Ice.ConnectionLostException();
}
}
- catch(Win32Exception e)
+ catch(SocketException e)
{
if(Network.wouldBlock(e))
{
@@ -236,7 +251,7 @@ namespace IceInternal
remaining -= ret;
buf.b.position(position += ret);
}
- catch(Win32Exception ex)
+ catch(SocketException ex)
{
//
// On Mono, calling shutdownReadWrite() followed by read() causes Socket.Receive() to
@@ -268,8 +283,13 @@ namespace IceInternal
public bool startRead(Buffer buf, AsyncCallback callback, object state)
{
+#if SILVERLIGHT
+ Debug.Assert(_fd != null && _readEventArgs != null);
+#else
Debug.Assert(_fd != null && _readResult == null);
+#endif
+#if !COMPACT && !SILVERLIGHT
// COMPILERFIX: Workaround for Mac OS X broken poll(), see Mono bug #470120
if(AssemblyUtil.osx_)
{
@@ -278,6 +298,7 @@ namespace IceInternal
Network.setBlock(_fd, true);
}
}
+#endif
int packetSize = buf.b.remaining();
if(_maxReceivePacketSize > 0 && packetSize > _maxReceivePacketSize)
@@ -287,10 +308,18 @@ namespace IceInternal
try
{
- _readResult = _fd.BeginReceive(buf.b.rawBytes(), buf.b.position(), packetSize, SocketFlags.None,
- callback, state);
+ _readCallback = callback;
+#if SILVERLIGHT
+ _readEventArgs.UserToken = state;
+ _readEventArgs.SetBuffer(buf.b.rawBytes(), buf.b.position(), packetSize);
+ return !_fd.ReceiveAsync(_readEventArgs);
+#else
+ _readResult = _fd.BeginReceive(buf.b.rawBytes(), buf.b.position(), packetSize, SocketFlags.None,
+ readCompleted, state);
+ return _readResult.CompletedSynchronously;
+#endif
}
- catch(Win32Exception ex)
+ catch(SocketException ex)
{
if(Network.connectionLost(ex))
{
@@ -299,29 +328,43 @@ namespace IceInternal
throw new Ice.SocketException(ex);
}
-
- return _readResult.CompletedSynchronously;
}
public void finishRead(Buffer buf)
{
if(_fd == null) // Transceiver was closed
+#if SILVERLIGHT
+ {
+ _readEventArgs = null;
+ return;
+ }
+ Debug.Assert(_fd != null && _readEventArgs != null);
+#else
{
_readResult = null;
return;
}
-
Debug.Assert(_fd != null && _readResult != null);
+#endif
try
{
+#if SILVERLIGHT
+ if(_readEventArgs.SocketError != SocketError.Success)
+ {
+ throw new SocketException((int)_readEventArgs.SocketError);
+ }
+ int ret = _readEventArgs.BytesTransferred;
+#else
int ret = _fd.EndReceive(_readResult);
_readResult = null;
+#endif
if(ret == 0)
{
throw new Ice.ConnectionLostException();
}
+#if !COMPACT && !SILVERLIGHT
// COMPILERFIX: Workaround for Mac OS X broken poll(), see Mono bug #470120
if(AssemblyUtil.osx_)
{
@@ -330,6 +373,7 @@ namespace IceInternal
Network.setBlock(_fd, false);
}
}
+#endif
Debug.Assert(ret > 0);
if(_traceLevels.network >= 3)
@@ -350,7 +394,7 @@ namespace IceInternal
buf.b.position(buf.b.position() + ret);
}
- catch(Win32Exception ex)
+ catch(SocketException ex)
{
if(Network.connectionLost(ex))
{
@@ -367,8 +411,13 @@ namespace IceInternal
public bool startWrite(Buffer buf, AsyncCallback callback, object state, out bool completed)
{
+#if SILVERLIGHT
+ Debug.Assert(_fd != null && _writeEventArgs != null);
+#else
Debug.Assert(_fd != null && _writeResult == null);
+#endif
+#if !COMPACT && !SILVERLIGHT
// COMPILERFIX: Workaround for Mac OS X broken poll(), see Mono bug #470120
if(AssemblyUtil.osx_)
{
@@ -377,12 +426,19 @@ namespace IceInternal
Network.setBlock(_fd, true);
}
}
+#endif
if(_state < StateConnected)
{
- _writeResult = Network.doConnectAsync(_fd, _addr, callback, state);
completed = false;
+ _writeCallback = callback;
+#if SILVERLIGHT
+ _writeEventArgs.UserToken = state;
+ return !_fd.ConnectAsync(_writeEventArgs);
+#else
+ _writeResult = Network.doConnectAsync(_fd, _addr, callback, state);
return _writeResult.CompletedSynchronously;
+#endif
}
//
@@ -397,10 +453,20 @@ namespace IceInternal
try
{
+ _writeCallback = callback;
+#if SILVERLIGHT
+ _writeEventArgs.UserToken = state;
+ _writeEventArgs.SetBuffer(buf.b.rawBytes(), buf.b.position(), packetSize);
+ bool completedSynchronously = !_fd.SendAsync(_writeEventArgs);
+#else
_writeResult = _fd.BeginSend(buf.b.rawBytes(), buf.b.position(), packetSize, SocketFlags.None,
- callback, state);
+ writeCompleted, state);
+ bool completedSynchronously = _writeResult.CompletedSynchronously;
+#endif
+ completed = packetSize == buf.b.remaining();
+ return completedSynchronously;
}
- catch(Win32Exception ex)
+ catch(SocketException ex)
{
if(Network.connectionLost(ex))
{
@@ -413,9 +479,6 @@ namespace IceInternal
{
throw new Ice.ConnectionLostException(ex);
}
-
- completed = packetSize == buf.b.remaining();
- return _writeResult.CompletedSynchronously;
}
public void finishWrite(Buffer buf)
@@ -426,11 +489,19 @@ namespace IceInternal
{
buf.b.position(buf.size()); // Assume all the data was sent for at-most-once semantics.
}
+#if SILVERLIGHT
+ _writeEventArgs = null;
+#else
_writeResult = null;
+#endif
return;
}
+#if SILVERLIGHT
+ Debug.Assert(_fd != null && _writeEventArgs != null);
+#else
Debug.Assert(_fd != null && _writeResult != null);
+#endif
if(_state < StateConnected)
{
@@ -439,14 +510,23 @@ namespace IceInternal
try
{
+#if SILVERLIGHT
+ if(_writeEventArgs.SocketError != SocketError.Success)
+ {
+ throw new SocketException((int)_writeEventArgs.SocketError);
+ }
+ int ret = _writeEventArgs.BytesTransferred;
+#else
int ret = _fd.EndSend(_writeResult);
_writeResult = null;
+#endif
if(ret == 0)
{
throw new Ice.ConnectionLostException();
}
Debug.Assert(ret > 0);
+#if !COMPACT && !SILVERLIGHT
// COMPILERFIX: Workaround for Mac OS X broken poll(), see Mono bug #470120
if(AssemblyUtil.osx_)
{
@@ -455,6 +535,7 @@ namespace IceInternal
Network.setBlock(_fd, false);
}
}
+#endif
if(_traceLevels.network >= 3)
{
@@ -474,7 +555,7 @@ namespace IceInternal
buf.b.position(buf.b.position() + ret);
}
- catch(Win32Exception ex)
+ catch(SocketException ex)
{
if(Network.connectionLost(ex))
{
@@ -499,20 +580,12 @@ namespace IceInternal
{
Debug.Assert(_fd != null);
Ice.TCPConnectionInfo info = new Ice.TCPConnectionInfo();
- IPEndPoint localEndpoint = Network.getLocalAddress(_fd);
- info.localAddress = localEndpoint.Address.ToString();
- info.localPort = localEndpoint.Port;
- IPEndPoint remoteEndpoint = Network.getRemoteAddress(_fd);
- if(remoteEndpoint != null)
- {
- info.remoteAddress = remoteEndpoint.Address.ToString();
- info.remotePort = remoteEndpoint.Port;
- }
- else
- {
- info.remoteAddress = "";
- info.remotePort = -1;
- }
+ EndPoint localEndpoint = Network.getLocalAddress(_fd);
+ info.localAddress = Network.endpointAddressToString(localEndpoint);
+ info.localPort = Network.endpointPort(localEndpoint);
+ EndPoint remoteEndpoint = Network.getRemoteAddress(_fd);
+ info.remoteAddress = Network.endpointAddressToString(remoteEndpoint);
+ info.remotePort = Network.endpointPort(remoteEndpoint);
return info;
}
@@ -532,10 +605,29 @@ namespace IceInternal
//
// Only for use by TcpConnector, TcpAcceptor
//
- internal TcpTransceiver(Instance instance, Socket fd, IPEndPoint addr, bool connected)
+ internal TcpTransceiver(Instance instance, Socket fd, EndPoint addr, bool connected)
{
_fd = fd;
_addr = addr;
+
+#if SILVERLIGHT
+ _readEventArgs = new SocketAsyncEventArgs();
+ if(instance.initializationData().properties.getProperty("Ice.ClientAccessPolicyProtocol").Equals("Http"))
+ {
+ _readEventArgs.SocketClientAccessPolicyProtocol = SocketClientAccessPolicyProtocol.Http;
+ }
+ _readEventArgs.RemoteEndPoint = _addr;
+ _readEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(ioCompleted);
+
+ _writeEventArgs = new SocketAsyncEventArgs();
+ if(instance.initializationData().properties.getProperty("Ice.ClientAccessPolicyProtocol").Equals("Http"))
+ {
+ _writeEventArgs.SocketClientAccessPolicyProtocol = SocketClientAccessPolicyProtocol.Http;
+ }
+ _writeEventArgs.RemoteEndPoint = _addr;
+ _writeEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(ioCompleted);
+#endif
+
_traceLevels = instance.traceLevels();
_logger = instance.initializationData().logger;
_stats = instance.initializationData().stats;
@@ -555,8 +647,42 @@ namespace IceInternal
}
}
+#if SILVERLIGHT
+ internal void ioCompleted(object sender, SocketAsyncEventArgs e)
+ {
+ switch (e.LastOperation)
+ {
+ case SocketAsyncOperation.Receive:
+ _readCallback(e.UserToken);
+ break;
+ case SocketAsyncOperation.Send:
+ case SocketAsyncOperation.Connect:
+ _writeCallback(e.UserToken);
+ break;
+ default:
+ throw new ArgumentException("The last operation completed on the socket was not a receive or send");
+ }
+ }
+#else
+ internal void readCompleted(IAsyncResult result)
+ {
+ if(!result.CompletedSynchronously)
+ {
+ _readCallback(result.AsyncState);
+ }
+ }
+
+ internal void writeCompleted(IAsyncResult result)
+ {
+ if(!result.CompletedSynchronously)
+ {
+ _writeCallback(result.AsyncState);
+ }
+ }
+#endif
+
private Socket _fd;
- private IPEndPoint _addr;
+ private EndPoint _addr;
private TraceLevels _traceLevels;
private Ice.Logger _logger;
private Ice.Stats _stats;
@@ -565,9 +691,20 @@ namespace IceInternal
private int _maxSendPacketSize;
private int _maxReceivePacketSize;
+#if !COMPACT && !SILVERLIGHT
private int _blocking = 0;
+#endif
+
+#if SILVERLIGHT
+ private SocketAsyncEventArgs _writeEventArgs;
+ private SocketAsyncEventArgs _readEventArgs;
+#else
private IAsyncResult _writeResult;
private IAsyncResult _readResult;
+#endif
+
+ AsyncCallback _writeCallback;
+ AsyncCallback _readCallback;
private const int StateNeedConnect = 0;
private const int StateConnectPending = 1;
diff --git a/cs/src/Ice/ThreadPool.cs b/cs/src/Ice/ThreadPool.cs
index 4b3e64f4d06..5f8175231dd 100644
--- a/cs/src/Ice/ThreadPool.cs
+++ b/cs/src/Ice/ThreadPool.cs
@@ -16,6 +16,7 @@ namespace IceInternal
using System.Threading;
public delegate void ThreadPoolWorkItem();
+ public delegate void AsyncCallback(object state);
internal struct ThreadPoolMessage
{
@@ -199,6 +200,7 @@ namespace IceInternal
}
_stackSize = stackSize;
+#if !SILVERLIGHT
_hasPriority = properties.getProperty(_prefix + ".ThreadPriority").Length > 0;
_priority = IceInternal.Util.stringToThreadPriority(properties.getProperty(_prefix + ".ThreadPriority"));
if(!_hasPriority)
@@ -206,6 +208,7 @@ namespace IceInternal
_hasPriority = properties.getProperty("Ice.ThreadPriority").Length > 0;
_priority = IceInternal.Util.stringToThreadPriority(properties.getProperty("Ice.ThreadPriority"));
}
+#endif
if(_instance.traceLevels().threadPool >= 1)
{
@@ -223,6 +226,7 @@ namespace IceInternal
{
WorkerThread thread = new WorkerThread(this, _threadPrefix + "-" + _threadIndex++);
_threads.Add(thread);
+#if !SILVERLIGHT
if(_hasPriority)
{
thread.start(_priority);
@@ -231,6 +235,9 @@ namespace IceInternal
{
thread.start(ThreadPriority.Normal);
}
+#else
+ thread.start();
+#endif
}
}
catch(System.Exception ex)
@@ -390,6 +397,7 @@ namespace IceInternal
try
{
WorkerThread t = new WorkerThread(this, _threadPrefix + "-" + _threadIndex++);
+#if !SILVERLIGHT
if(_hasPriority)
{
t.start(_priority);
@@ -398,6 +406,9 @@ namespace IceInternal
{
t.start(ThreadPriority.Normal);
}
+#else
+ t.start();
+#endif
_threads.Add(t);
}
catch(System.Exception ex)
@@ -665,22 +676,12 @@ namespace IceInternal
public void asyncReadCallback(object state)
{
- IAsyncResult result = (IAsyncResult)state;
- if(result.CompletedSynchronously)
- {
- return;
- }
- messageCallback(new ThreadPoolCurrent(this, (EventHandler)result.AsyncState, SocketOperation.Read));
+ messageCallback(new ThreadPoolCurrent(this, (EventHandler)state, SocketOperation.Read));
}
public void asyncWriteCallback(object state)
{
- IAsyncResult result = (IAsyncResult)state;
- if(result.CompletedSynchronously)
- {
- return;
- }
- messageCallback(new ThreadPoolCurrent(this, (EventHandler)result.AsyncState, SocketOperation.Write));
+ messageCallback(new ThreadPoolCurrent(this, (EventHandler)state, SocketOperation.Write));
}
public void messageCallback(ThreadPoolCurrent current)
@@ -736,6 +737,7 @@ namespace IceInternal
_thread.Join();
}
+#if !SILVERLIGHT
public void start(ThreadPriority priority)
{
if(_threadPool._stackSize == 0)
@@ -751,6 +753,15 @@ namespace IceInternal
_thread.Priority = priority;
_thread.Start();
}
+#else
+ public void start()
+ {
+ _thread = new Thread(new ThreadStart(Run));
+ _thread.IsBackground = true;
+ _thread.Name = _name;
+ _thread.Start();
+ }
+#endif
public void Run()
{
@@ -801,8 +812,10 @@ namespace IceInternal
private readonly int _sizeMax; // Maximum number of threads.
private readonly int _sizeWarn; // If _inUse reaches _sizeWarn, a "low on threads" warning will be printed.
private readonly bool _serialize; // True if requests need to be serialized over the connection.
+#if !SILVERLIGHT
private readonly ThreadPriority _priority;
private readonly bool _hasPriority = false;
+#endif
private readonly int _serverIdleTime;
private readonly int _threadIdleTime;
private readonly int _stackSize;
diff --git a/cs/src/Ice/Time.cs b/cs/src/Ice/Time.cs
index a853a9df5f0..21195543ca6 100644
--- a/cs/src/Ice/Time.cs
+++ b/cs/src/Ice/Time.cs
@@ -9,6 +9,7 @@
namespace IceInternal
{
+#if !SILVERLIGHT
using System.Diagnostics;
public sealed class Time
@@ -25,4 +26,20 @@ namespace IceInternal
private static Stopwatch _stopwatch = new Stopwatch();
}
+#else
+ public sealed class Time
+ {
+ static Time()
+ {
+ _begin = System.DateTime.Now.Ticks;
+ }
+
+ public static long currentMonotonicTimeMillis()
+ {
+ return (System.DateTime.Now.Ticks - _begin) / 10000;
+ }
+
+ private static long _begin;
+ }
+#endif
}
diff --git a/cs/src/Ice/Timer.cs b/cs/src/Ice/Timer.cs
index 23bcc7bce12..23f1335640e 100644
--- a/cs/src/Ice/Timer.cs
+++ b/cs/src/Ice/Timer.cs
@@ -18,6 +18,7 @@ namespace IceInternal
using System;
using System.Diagnostics;
using System.Threading;
+ using System.Collections;
using System.Collections.Generic;
public interface TimerTask
@@ -66,7 +67,16 @@ namespace IceInternal
try
{
_tasks.Add(task, token);
+#if SILVERLIGHT
+ int index = _tokens.BinarySearch(token);
+ Debug.Assert(index < 0);
+ if(index < 0)
+ {
+ _tokens.Insert(~index, token);
+ }
+#else
_tokens.Add(token, null);
+#endif
}
catch(System.ArgumentException)
{
@@ -99,7 +109,16 @@ namespace IceInternal
try
{
_tasks.Add(task, token);
+#if SILVERLIGHT
+ int index = _tokens.BinarySearch(token);
+ Debug.Assert(index < 0);
+ if(index < 0)
+ {
+ _tokens.Insert(~index, token);
+ }
+#else
_tokens.Add(token, null);
+#endif
}
catch(System.ArgumentException)
{
@@ -145,17 +164,27 @@ namespace IceInternal
//
// Only for use by Instance.
//
+#if !SILVERLIGHT
internal Timer(IceInternal.Instance instance, ThreadPriority priority)
{
init(instance, priority, true);
}
-
+#endif
+
internal Timer(IceInternal.Instance instance)
{
+#if !SILVERLIGHT
init(instance, ThreadPriority.Normal, false);
+#else
+ init(instance);
+#endif
}
- internal void init(IceInternal.Instance instance, ThreadPriority priority, bool hasPriority)
+#if !SILVERLIGHT
+ internal void init(IceInternal.Instance instance, ThreadPriority priority, bool hasPriority)
+#else
+ internal void init(IceInternal.Instance instance)
+#endif
{
_instance = instance;
@@ -168,10 +197,12 @@ namespace IceInternal
_thread = new Thread(new ThreadStart(Run));
_thread.IsBackground = true;
_thread.Name = threadName + "Ice.Timer";
+#if !SILVERLIGHT
if(hasPriority)
{
_thread.Priority = priority;
}
+#endif
_thread.Start();
}
@@ -194,7 +225,16 @@ namespace IceInternal
if(_tasks.ContainsKey(token.task))
{
token.scheduledTime = Time.currentMonotonicTimeMillis() + token.delay;
+#if SILVERLIGHT
+ int index = _tokens.BinarySearch(token);
+ Debug.Assert(index < 0);
+ if(index < 0)
+ {
+ _tokens.Insert(~index, token);
+ }
+#else
_tokens.Add(token, null);
+#endif
}
}
}
@@ -221,7 +261,11 @@ namespace IceInternal
long now = Time.currentMonotonicTimeMillis();
Token first = null;
+#if SILVERLIGHT
+ foreach(Token t in _tokens)
+#else
foreach(Token t in _tokens.Keys)
+#endif
{
first = t;
break;
@@ -351,6 +395,8 @@ namespace IceInternal
#if COMPACT
private IDictionary<Token, object> _tokens = new SortedList<Token, object>();
+#elif SILVERLIGHT
+ private List<Token> _tokens = new List<Token>();
#else
private IDictionary<Token, object> _tokens = new SortedDictionary<Token, object>();
#endif
@@ -361,5 +407,6 @@ namespace IceInternal
private Thread _thread;
private readonly IceUtilInternal.Monitor _m = new IceUtilInternal.Monitor();
- }
+}
+
}
diff --git a/cs/src/Ice/UdpConnector.cs b/cs/src/Ice/UdpConnector.cs
index 1e572d02305..1f1b43ea7f8 100644
--- a/cs/src/Ice/UdpConnector.cs
+++ b/cs/src/Ice/UdpConnector.cs
@@ -29,12 +29,16 @@ namespace IceInternal
//
// Only for use by TcpEndpoint
//
- internal UdpConnector(Instance instance, IPEndPoint addr, string mcastInterface, int mcastTtl,
+ internal UdpConnector(Instance instance, EndPoint addr, string mcastInterface, int mcastTtl,
byte protocolMajor, byte protocolMinor, byte encodingMajor, byte encodingMinor,
string connectionId)
{
instance_ = instance;
- _addr = addr;
+#if SILVERLIGHT
+ _addr = (DnsEndPoint)addr;
+#else
+ _addr = (IPEndPoint)addr;
+#endif
_mcastInterface = mcastInterface;
_mcastTtl = mcastTtl;
_protocolMajor = protocolMajor;
@@ -102,7 +106,7 @@ namespace IceInternal
return false;
}
- return Network.compareAddress(_addr, p._addr) == 0;
+ return _addr.Equals(p._addr);
}
public override string ToString()
@@ -116,7 +120,11 @@ namespace IceInternal
}
private Instance instance_;
+#if SILVERLIGHT
+ private DnsEndPoint _addr;
+#else
private IPEndPoint _addr;
+#endif
private string _mcastInterface;
private int _mcastTtl;
private byte _protocolMajor;
diff --git a/cs/src/Ice/UdpEndpointI.cs b/cs/src/Ice/UdpEndpointI.cs
index e76e6d54c85..1f9764c79da 100644
--- a/cs/src/Ice/UdpEndpointI.cs
+++ b/cs/src/Ice/UdpEndpointI.cs
@@ -614,11 +614,16 @@ namespace IceInternal
return connectors(Network.getAddresses(_host, _port, instance_.protocolSupport()));
}
+
public override void connectors_async(EndpointI_connectors callback)
{
+#if SILVERLIGHT
+ callback.connectors(connectors());
+#else
instance_.endpointHostResolver().resolve(_host, _port, this, callback);
+#endif
}
-
+
//
// Return an acceptor for this endpoint, or null if no acceptors
// is available. In case an acceptor is created, this operation
@@ -674,10 +679,10 @@ namespace IceInternal
return udpEndpointI._host.Equals(_host) && udpEndpointI._port == _port;
}
- public override List<Connector> connectors(List<IPEndPoint> addresses)
+ public override List<Connector> connectors(List<EndPoint> addresses)
{
List<Connector> connectors = new List<Connector>();
- foreach(IPEndPoint addr in addresses)
+ foreach(EndPoint addr in addresses)
{
connectors.Add(new UdpConnector(instance_, addr, _mcastInterface, _mcastTtl, _protocolMajor,
_protocolMinor, _encodingMajor, _encodingMinor, _connectionId));
diff --git a/cs/src/Ice/UdpTransceiver.cs b/cs/src/Ice/UdpTransceiver.cs
index d8f7107fb72..ecc51c5a0fb 100644
--- a/cs/src/Ice/UdpTransceiver.cs
+++ b/cs/src/Ice/UdpTransceiver.cs
@@ -29,15 +29,16 @@ namespace IceInternal
}
else if(_state <= StateConnectPending)
{
- if(Network.isMulticast(_addr))
+#if !SILVERLIGHT
+ if(Network.isMulticast((IPEndPoint)_addr))
{
- Network.setMcastGroup(_fd, _addr.Address, _mcastInterface);
-
+ Network.setMcastGroup(_fd, ((IPEndPoint)_addr).Address, _mcastInterface);
if(_mcastTtl != -1)
{
Network.setMcastTtl(_fd, _mcastTtl, _addr.AddressFamily);
}
}
+#endif
_state = StateConnected;
}
@@ -77,9 +78,9 @@ namespace IceInternal
public bool write(Buffer buf)
{
-#if COMPACT
+#if COMPACT || SILVERLIGHT
//
- // The Compact Framework does not support the use of synchronous socket
+ // Silverlight and the Compact .NET Framework don't support the use of synchronous socket
// operations on a non-blocking socket. Returning false here forces the
// caller to schedule an asynchronous operation.
//
@@ -110,7 +111,7 @@ namespace IceInternal
}
break;
}
- catch(Win32Exception ex)
+ catch(SocketException ex)
{
if(Network.interrupted(ex))
{
@@ -158,9 +159,9 @@ namespace IceInternal
public bool read(Buffer buf)
{
-#if COMPACT
+#if COMPACT || SILVERLIGHT
//
- // The Compact Framework does not support the use of synchronous socket
+ // Silverlight and the Compact .NET Framework don't support the use of synchronous socket
// operations on a non-blocking socket. Returning false here forces the
// caller to schedule an asynchronous operation.
//
@@ -203,7 +204,7 @@ namespace IceInternal
}
break;
}
- catch(Win32Exception e)
+ catch(SocketException e)
{
if(Network.recvTruncated(e))
{
@@ -292,13 +293,26 @@ namespace IceInternal
{
if(_state == StateConnected)
{
- _readResult = _fd.BeginReceive(buf.b.rawBytes(), 0, buf.b.limit(), SocketFlags.None, callback,
- state);
+ _readCallback = callback;
+#if SILVERLIGHT
+ _readEventArgs.UserToken = state;
+ _readEventArgs.SetBuffer(buf.b.rawBytes(), buf.b.position(), packetSize);
+ return !_fd.ReceiveAsync(_readEventArgs);
+#else
+ _readResult = _fd.BeginReceive(buf.b.rawBytes(), 0, buf.b.limit(), SocketFlags.None,
+ readCompleted, state);
+ return _readResult.CompletedSynchronously;
+#endif
}
else
{
Debug.Assert(_incoming);
-
+ _readCallback = callback;
+#if SILVERLIGHT
+ _readEventArgs.UserToken = state;
+ _readEventArgs.SetBuffer(buf.b.rawBytes(), 0, buf.b.limit());
+ return !_fd.ReceiveFromAsync(_readEventArgs);
+#else
EndPoint peerAddr = _peerAddr;
if(peerAddr == null)
{
@@ -312,16 +326,18 @@ namespace IceInternal
peerAddr = new IPEndPoint(IPAddress.IPv6Any, 0);
}
}
-
_readResult = _fd.BeginReceiveFrom(buf.b.rawBytes(), 0, buf.b.limit(), SocketFlags.None,
- ref peerAddr, callback, state);
+ ref peerAddr, readCompleted, state);
+ return _readResult.CompletedSynchronously;
+#endif
}
}
- catch(Win32Exception ex)
+ catch(SocketException ex)
{
if(Network.recvTruncated(ex))
{
- // Nothing todo
+ // Nothing todo
+ return true;
}
else
{
@@ -335,8 +351,6 @@ namespace IceInternal
}
}
}
-
- return _readResult.CompletedSynchronously;
}
public void finishRead(Buffer buf)
@@ -349,6 +363,17 @@ namespace IceInternal
int ret;
try
{
+#if SILVERLIGHT
+ if(_readEventArgs.SocketError != SocketError.Success)
+ {
+ throw new SocketException((int)_readEventArgs.SocketError);
+ }
+ ret = _readEventArgs.BytesTransferred;
+ if(_state != StateConnected)
+ {
+ _peerAddr = _readEventArgs.RemoteEndPoint;
+ }
+#else
Debug.Assert(_readResult != null);
if(_state == StateConnected)
{
@@ -370,8 +395,9 @@ namespace IceInternal
_peerAddr = (IPEndPoint)peerAddr;
}
_readResult = null;
+#endif
}
- catch(Win32Exception ex)
+ catch(SocketException ex)
{
if(Network.recvTruncated(ex))
{
@@ -413,7 +439,11 @@ namespace IceInternal
// If we must connect, then we connect to the first peer that
// sends us a packet.
//
+#if SILVERLIGHT
+ bool connected = !_fd.ConnectAsync(_readEventArgs);
+#else
bool connected = Network.doConnect(_fd, _peerAddr);
+#endif
Debug.Assert(connected);
_state = StateConnected; // We're connected now
@@ -444,9 +474,14 @@ namespace IceInternal
if(!_incoming && _state < StateConnected)
{
Debug.Assert(_addr != null);
- _writeResult = Network.doConnectAsync(_fd, _addr, callback, state);
completed = false;
+#if SILVERLIGHT
+ _writeEventArgs.UserToken = state;
+ return !_fd.ConnectAsync(_writeEventArgs);
+#else
+ _writeResult = Network.doConnectAsync(_fd, _addr, callback, state);
return _writeResult.CompletedSynchronously;
+#endif
}
Debug.Assert(_fd != null);
@@ -456,11 +491,22 @@ namespace IceInternal
Debug.Assert(buf.b.position() == 0);
+ bool completedSynchronously;
try
{
+ _writeCallback = callback;
+
if(_state == StateConnected)
{
- _writeResult = _fd.BeginSend(buf.b.rawBytes(), 0, buf.b.limit(), SocketFlags.None, callback, state);
+#if SILVERLIGHT
+ _writeEventArgs.UserToken = state;
+ _writeEventArgs.SetBuffer(buf.b.rawBytes(), 0, buf.b.limit());
+ completedSynchronously = !_fd.SendAsync(_writeEventArgs);
+#else
+ _writeResult = _fd.BeginSend(buf.b.rawBytes(), 0, buf.b.limit(), SocketFlags.None,
+ writeCompleted, state);
+ completedSynchronously = _writeResult.CompletedSynchronously;
+#endif
}
else
{
@@ -468,11 +514,19 @@ namespace IceInternal
{
throw new Ice.SocketException();
}
+#if SILVERLIGHT
+ _writeEventArgs.RemoteEndPoint = _peerAddr;
+ _writeEventArgs.UserToken = state;
+ _writeEventArgs.SetBuffer(buf.b.rawBytes(), 0, buf.b.limit());
+ completedSynchronously = !_fd.SendToAsync(_writeEventArgs);
+#else
_writeResult = _fd.BeginSendTo(buf.b.rawBytes(), 0, buf.b.limit(), SocketFlags.None, _peerAddr,
- callback, state);
+ writeCompleted, state);
+ completedSynchronously = _writeResult.CompletedSynchronously;
+#endif
}
}
- catch(Win32Exception ex)
+ catch(SocketException ex)
{
if(Network.connectionLost(ex))
{
@@ -485,7 +539,7 @@ namespace IceInternal
}
completed = true;
- return _writeResult.CompletedSynchronously;
+ return completedSynchronously;
}
public void finishWrite(Buffer buf)
@@ -493,22 +547,48 @@ namespace IceInternal
if(_fd == null)
{
buf.b.position(buf.size()); // Assume all the data was sent for at-most-once semantics.
+#if SILVERLIGHT
+ _writeEventArgs = null;
+#else
_writeResult = null;
+#endif
return;
}
if(!_incoming && _state < StateConnected)
{
+#if SILVERLIGHT
+ if(_writeEventArgs.SocketError != SocketError.Success)
+ {
+ SocketException ex = new SocketException((int)_writeEventArgs.SocketError);
+ if(Network.connectionRefused(ex))
+ {
+ throw new Ice.ConnectionRefusedException(ex);
+ }
+ else
+ {
+ throw new Ice.ConnectFailedException(ex);
+ }
+ }
+#else
Debug.Assert(_writeResult != null);
Network.doFinishConnectAsync(_fd, _writeResult);
_writeResult = null;
+#endif
return;
}
int ret;
try
{
- if(_state == StateConnected)
+#if SILVERLIGHT
+ if(_writeEventArgs.SocketError != SocketError.Success)
+ {
+ throw new SocketException((int)_writeEventArgs.SocketError);
+ }
+ ret = _writeEventArgs.BytesTransferred;
+#else
+ if (_state == StateConnected)
{
ret = _fd.EndSend(_writeResult);
}
@@ -517,8 +597,9 @@ namespace IceInternal
ret = _fd.EndSendTo(_writeResult);
}
_writeResult = null;
+#endif
}
- catch(Win32Exception ex)
+ catch(SocketException ex)
{
if(Network.connectionLost(ex))
{
@@ -562,15 +643,15 @@ namespace IceInternal
{
Debug.Assert(_fd != null);
Ice.UDPConnectionInfo info = new Ice.UDPConnectionInfo();
- IPEndPoint localEndpoint = Network.getLocalAddress(_fd);
- info.localAddress = localEndpoint.Address.ToString();
- info.localPort = localEndpoint.Port;
+ EndPoint localEndpoint = Network.getLocalAddress(_fd);
+ info.localAddress = Network.endpointAddressToString(localEndpoint);
+ info.localPort = Network.endpointPort(localEndpoint);
if(_state == StateNotConnected)
{
if(_peerAddr != null)
{
- info.remoteAddress = _peerAddr.Address.ToString();
- info.remotePort = _peerAddr.Port;
+ info.remoteAddress = Network.endpointAddressToString(_peerAddr);
+ info.remotePort = Network.endpointPort(_peerAddr);
}
else
{
@@ -580,11 +661,11 @@ namespace IceInternal
}
else
{
- IPEndPoint remoteEndpoint = Network.getRemoteAddress(_fd);
+ EndPoint remoteEndpoint = Network.getRemoteAddress(_fd);
if(remoteEndpoint != null)
{
- info.remoteAddress = remoteEndpoint.Address.ToString();
- info.remotePort = remoteEndpoint.Port;
+ info.remoteAddress = Network.endpointAddressToString(remoteEndpoint);
+ info.remotePort = Network.endpointPort(remoteEndpoint);
}
else
{
@@ -593,12 +674,14 @@ namespace IceInternal
}
}
+#if !SILVERLIGHT
if(_mcastAddr != null)
{
- info.mcastAddress = _mcastAddr.Address.ToString();
- info.mcastPort = _mcastAddr.Port;
+ info.mcastAddress = Network.endpointAddressToString(_mcastAddr);
+ info.mcastPort = Network.endpointPort(_mcastAddr);
}
else
+#endif
{
info.mcastAddress = "";
info.mcastPort = -1;
@@ -645,27 +728,44 @@ namespace IceInternal
s = Network.fdToString(_fd);
}
+#if !SILVERLIGHT
if(_mcastAddr != null)
{
s += "\nmulticast address = " + Network.addrToString(_mcastAddr);
- }
+ }
+#endif
return s;
}
public int effectivePort()
{
- return _addr.Port;
+#if SILVERLIGHT
+ return ((DnsEndPoint)_addr).Port;
+#else
+ return ((IPEndPoint)_addr).Port;
+#endif
}
//
// Only for use by UdpConnector.
//
- internal UdpTransceiver(Instance instance, IPEndPoint addr, string mcastInterface, int mcastTtl)
+ internal UdpTransceiver(Instance instance, EndPoint addr, string mcastInterface, int mcastTtl)
{
_traceLevels = instance.traceLevels();
_logger = instance.initializationData().logger;
_stats = instance.initializationData().stats;
_addr = addr;
+
+#if SILVERLIGHT
+ _readEventArgs = new SocketAsyncEventArgs();
+ _readEventArgs.RemoteEndPoint = _addr;
+ _readEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(ioCompleted);
+
+ _writeEventArgs = new SocketAsyncEventArgs();
+ _writeEventArgs.RemoteEndPoint = _addr;
+ _writeEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(ioCompleted);
+#endif
+
_mcastInterface = mcastInterface;
_mcastTtl = mcastTtl;
_state = StateNeedConnect;
@@ -675,7 +775,9 @@ namespace IceInternal
{
_fd = Network.createSocket(true, _addr.AddressFamily);
setBufSize(instance);
+#if !SILVERLIGHT
Network.setBlock(_fd, false);
+#endif
}
catch(Ice.LocalException)
{
@@ -698,18 +800,33 @@ namespace IceInternal
try
{
_addr = Network.getAddressForServer(host, port, instance.protocolSupport());
+
+#if SILVERLIGHT
+ _readEventArgs = new SocketAsyncEventArgs();
+ _readEventArgs.RemoteEndPoint = _addr;
+ _readEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(ioCompleted);
+
+ _writeEventArgs = new SocketAsyncEventArgs();
+ _writeEventArgs.RemoteEndPoint = _addr;
+ _writeEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(ioCompleted);
+#endif
+
_fd = Network.createSocket(true, _addr.AddressFamily);
setBufSize(instance);
+#if !SILVERLIGHT
Network.setBlock(_fd, false);
+#endif
if(_traceLevels.network >= 2)
{
string s = "attempting to bind to udp socket " + Network.addrToString(_addr);
_logger.trace(_traceLevels.networkCat, s);
}
- if(Network.isMulticast(_addr))
+
+#if !SILVERLIGHT
+ if(Network.isMulticast((IPEndPoint)_addr))
{
Network.setReuseAddress(_fd, true);
- _mcastAddr = _addr;
+ _mcastAddr = (IPEndPoint)_addr;
if(AssemblyUtil.platform_ == AssemblyUtil.Platform.Windows)
{
//
@@ -731,7 +848,7 @@ namespace IceInternal
_addr = Network.doBind(_fd, _addr);
if(port == 0)
{
- _mcastAddr.Port = _addr.Port;
+ _mcastAddr.Port = ((IPEndPoint)_addr).Port;
}
Network.setMcastGroup(_fd, _mcastAddr.Address, mcastInterface);
}
@@ -756,19 +873,22 @@ namespace IceInternal
}
_addr = Network.doBind(_fd, _addr);
}
-
+#endif
if(_traceLevels.network >= 1)
{
StringBuilder s = new StringBuilder("starting to receive udp packets\n");
- s.Append(ToString());
-
- List<string> interfaces =
- Network.getHostsForEndpointExpand(_addr.Address.ToString(), instance.protocolSupport(), true);
+ s.Append(ToString());
+#if SILVERLIGHT
+ s.Append("\nlocal interfaces: " + ((DnsEndPoint)_addr).Host);
+#else
+ List<string> interfaces = Network.getHostsForEndpointExpand(((IPEndPoint)_addr).Address.ToString(),
+ instance.protocolSupport(), true);
if(interfaces.Count != 0)
{
s.Append("\nlocal interfaces: ");
s.Append(String.Join(", ", interfaces.ToArray()));
}
+#endif
_logger.trace(_traceLevels.networkCat, s.ToString());
}
}
@@ -847,6 +967,39 @@ namespace IceInternal
}
}
+#if SILVERLIGHT
+ internal void ioCompleted(object sender, SocketAsyncEventArgs e)
+ {
+ switch (e.LastOperation)
+ {
+ case SocketAsyncOperation.Receive:
+ _readCallback(e.UserToken);
+ break;
+ case SocketAsyncOperation.Send:
+ _writeCallback(e.UserToken);
+ break;
+ default:
+ throw new ArgumentException("The last operation completed on the socket was not a receive or send");
+ }
+ }
+#else
+ internal void readCompleted(IAsyncResult result)
+ {
+ if(!result.CompletedSynchronously)
+ {
+ _readCallback(result.AsyncState);
+ }
+ }
+
+ internal void writeCompleted(IAsyncResult result)
+ {
+ if(!result.CompletedSynchronously)
+ {
+ _writeCallback(result.AsyncState);
+ }
+ }
+#endif
+
private TraceLevels _traceLevels;
private Ice.Logger _logger;
private Ice.Stats _stats;
@@ -855,14 +1008,24 @@ namespace IceInternal
private int _rcvSize;
private int _sndSize;
private Socket _fd;
- private IPEndPoint _addr;
+ private EndPoint _addr;
+#if !SILVERLIGHT
private IPEndPoint _mcastAddr = null;
- private IPEndPoint _peerAddr = null;
+#endif
+ private EndPoint _peerAddr = null;
private string _mcastInterface = null;
private int _mcastTtl = -1;
+#if SILVERLIGHT
+ private SocketAsyncEventArgs _writeEventArgs;
+ private SocketAsyncEventArgs _readEventArgs;
+#else
private IAsyncResult _writeResult;
private IAsyncResult _readResult;
+#endif
+
+ AsyncCallback _writeCallback;
+ AsyncCallback _readCallback;
private const int StateNeedConnect = 0;
private const int StateConnectPending = 1;
diff --git a/cs/src/Ice/Util.cs b/cs/src/Ice/Util.cs
index 017db4bdf12..f9d11aac99f 100644
--- a/cs/src/Ice/Util.cs
+++ b/cs/src/Ice/Util.cs
@@ -506,6 +506,7 @@ namespace IceInternal
return new ProtocolPluginFacadeI(communicator);
}
+#if !SILVERLIGHT
public static System.Threading.ThreadPriority stringToThreadPriority(string s)
{
if(String.IsNullOrEmpty(s))
@@ -538,5 +539,16 @@ namespace IceInternal
}
return ThreadPriority.Normal;
}
+#endif
+ }
+}
+
+#if SILVERLIGHT
+namespace System
+{
+ public interface ICloneable
+ {
+ Object Clone();
}
}
+#endif
diff --git a/cs/src/Ice/ValueWriter.cs b/cs/src/Ice/ValueWriter.cs
index 17f6966d40d..24f50221ff5 100644
--- a/cs/src/Ice/ValueWriter.cs
+++ b/cs/src/Ice/ValueWriter.cs
@@ -11,6 +11,7 @@ namespace IceInternal
{
using System.Collections;
+ using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using IceUtilInternal;
@@ -22,7 +23,7 @@ namespace IceInternal
writeValue(null, obj, null, output);
}
- private static void writeValue(string name, object val, Hashtable objectTable, OutputBase output)
+ private static void writeValue(string name, object val, Dictionary<Ice.Object, object> objectTable, OutputBase output)
{
if(val == null)
{
@@ -46,10 +47,10 @@ namespace IceInternal
output.print(val.ToString());
output.print("\"");
}
- else if(val is CollectionBase)
+ else if(val is IList)
{
int n = 0;
- IEnumerator i = ((CollectionBase)val).GetEnumerator();
+ IEnumerator i = ((IList)val).GetEnumerator();
while(i.MoveNext())
{
string elem = (name != null ? name : "");
@@ -77,7 +78,7 @@ namespace IceInternal
//
// Check for recursion.
//
- if(objectTable != null && objectTable.Contains(val))
+ if(objectTable != null && objectTable.ContainsKey((Ice.Object)val))
{
writeName(name, output);
output.print("(recursive)");
@@ -86,9 +87,9 @@ namespace IceInternal
{
if(objectTable == null)
{
- objectTable = new Hashtable();
+ objectTable = new Dictionary<Ice.Object, object>();
}
- objectTable[val] = null;
+ objectTable[(Ice.Object)val] = null;
writeFields(name, val, c, objectTable, output);
}
}
@@ -107,7 +108,7 @@ namespace IceInternal
}
}
- private static void writeFields(string name, object obj, System.Type c, Hashtable objectTable,
+ private static void writeFields(string name, object obj, System.Type c, Dictionary<Ice.Object, object> objectTable,
OutputBase output)
{
if(!c.Equals(typeof(object)))
diff --git a/cs/src/IceSSL/AcceptorI.cs b/cs/src/IceSSL/AcceptorI.cs
index 8c9b7c59c2f..fd1648e2984 100644
--- a/cs/src/IceSSL/AcceptorI.cs
+++ b/cs/src/IceSSL/AcceptorI.cs
@@ -63,7 +63,7 @@ namespace IceSSL
}
}
- public bool startAccept(AsyncCallback callback, object state)
+ public bool startAccept(IceInternal.AsyncCallback callback, object state)
{
//
// The plug-in may not be fully initialized.
@@ -77,7 +77,13 @@ namespace IceSSL
try
{
- _result = _fd.BeginAccept(callback, state);
+ _result = _fd.BeginAccept(delegate(IAsyncResult result)
+ {
+ if(!result.CompletedSynchronously)
+ {
+ callback(result.AsyncState);
+ }
+ }, state);
return _result.CompletedSynchronously;
}
catch(SocketException ex)
@@ -155,7 +161,7 @@ namespace IceSSL
try
{
- _addr = IceInternal.Network.getAddressForServer(host, port, _instance.protocolSupport());
+ _addr = (IPEndPoint)IceInternal.Network.getAddressForServer(host, port, _instance.protocolSupport());
_fd = IceInternal.Network.createSocket(false, _addr.AddressFamily);
IceInternal.Network.setBlock(_fd, false);
IceInternal.Network.setTcpBufSize(_fd, _instance.communicator().getProperties(), _logger);
diff --git a/cs/src/IceSSL/ConnectorI.cs b/cs/src/IceSSL/ConnectorI.cs
index cf387fd268b..78595c318ea 100644
--- a/cs/src/IceSSL/ConnectorI.cs
+++ b/cs/src/IceSSL/ConnectorI.cs
@@ -118,7 +118,7 @@ namespace IceSSL
return false;
}
- return IceInternal.Network.compareAddress(_addr, p._addr) == 0;
+ return _addr.Equals(p._addr);
}
public override string ToString()
diff --git a/cs/src/IceSSL/EndpointI.cs b/cs/src/IceSSL/EndpointI.cs
index af6d7de138b..40b2eed39ca 100644
--- a/cs/src/IceSSL/EndpointI.cs
+++ b/cs/src/IceSSL/EndpointI.cs
@@ -449,12 +449,12 @@ namespace IceSSL
return sslEndpointI._host.Equals(_host) && sslEndpointI._port == _port;
}
- public override List<IceInternal.Connector> connectors(List<IPEndPoint> addresses)
+ public override List<IceInternal.Connector> connectors(List<EndPoint> addresses)
{
List<IceInternal.Connector> connectors = new List<IceInternal.Connector>();
- foreach(IPEndPoint addr in addresses)
+ foreach(EndPoint addr in addresses)
{
- connectors.Add(new ConnectorI(_instance, _host, addr, _timeout, _connectionId));
+ connectors.Add(new ConnectorI(_instance, _host, (IPEndPoint)addr, _timeout, _connectionId));
}
return connectors;
}
diff --git a/cs/src/IceSSL/TransceiverI.cs b/cs/src/IceSSL/TransceiverI.cs
index 88ad2426039..3ddb342fe14 100644
--- a/cs/src/IceSSL/TransceiverI.cs
+++ b/cs/src/IceSSL/TransceiverI.cs
@@ -126,7 +126,7 @@ namespace IceSSL
return false; // Caller will use async read.
}
- public bool startRead(IceInternal.Buffer buf, AsyncCallback callback, object state)
+ public bool startRead(IceInternal.Buffer buf, IceInternal.AsyncCallback callback, object state)
{
Debug.Assert(_fd != null);
@@ -138,7 +138,8 @@ namespace IceSSL
try
{
- _readResult = _stream.BeginRead(buf.b.rawBytes(), buf.b.position(), packetSize, callback, state);
+ _readCallback = callback;
+ _readResult = _stream.BeginRead(buf.b.rawBytes(), buf.b.position(), packetSize, readCompleted, state);
return _readResult.CompletedSynchronously;
}
catch(IOException ex)
@@ -232,7 +233,8 @@ namespace IceSSL
}
}
- public bool startWrite(IceInternal.Buffer buf, AsyncCallback callback, object state, out bool completed)
+ public bool startWrite(IceInternal.Buffer buf, IceInternal.AsyncCallback callback, object state,
+ out bool completed)
{
Debug.Assert(_fd != null);
@@ -263,7 +265,8 @@ namespace IceSSL
try
{
- _writeResult = _stream.BeginWrite(buf.b.rawBytes(), buf.b.position(), packetSize, callback, state);
+ _writeCallback = callback;
+ _writeResult = _stream.BeginWrite(buf.b.rawBytes(), buf.b.position(), packetSize, writeCompleted, state);
completed = packetSize == buf.b.remaining();
return _writeResult.CompletedSynchronously;
}
@@ -434,10 +437,10 @@ namespace IceSSL
{
Debug.Assert(_fd != null && _stream != null);
IceSSL.NativeConnectionInfo info = new IceSSL.NativeConnectionInfo();
- IPEndPoint localEndpoint = IceInternal.Network.getLocalAddress(_fd);
+ IPEndPoint localEndpoint = (IPEndPoint)IceInternal.Network.getLocalAddress(_fd);
info.localAddress = localEndpoint.Address.ToString();
info.localPort = localEndpoint.Port;
- IPEndPoint remoteEndpoint = IceInternal.Network.getRemoteAddress(_fd);
+ IPEndPoint remoteEndpoint = (IPEndPoint)IceInternal.Network.getRemoteAddress(_fd);
if(remoteEndpoint != null)
{
info.remoteAddress = remoteEndpoint.Address.ToString();
@@ -468,7 +471,7 @@ namespace IceSSL
return info;
}
- private bool beginAuthenticate(AsyncCallback callback, object state)
+ private bool beginAuthenticate(IceInternal.AsyncCallback callback, object state)
{
NetworkStream ns = new NetworkStream(_fd, true);
_stream = new SslStream(ns, false, new RemoteCertificateValidationCallback(validationCallback), null);
@@ -483,7 +486,13 @@ namespace IceSSL
_writeResult = _stream.BeginAuthenticateAsClient(_host, _instance.certs(),
_instance.protocols(),
_instance.checkCRL() > 0,
- callback, state);
+ delegate(IAsyncResult result)
+ {
+ if(!result.CompletedSynchronously)
+ {
+ callback(result.AsyncState);
+ }
+ }, state);
}
else
{
@@ -500,7 +509,14 @@ namespace IceSSL
}
_writeResult = _stream.BeginAuthenticateAsServer(cert, _verifyPeer > 1, _instance.protocols(),
- _instance.checkCRL() > 0, callback, state);
+ _instance.checkCRL() > 0,
+ delegate(IAsyncResult result)
+ {
+ if(!result.CompletedSynchronously)
+ {
+ callback(result.AsyncState);
+ }
+ }, state);
}
}
catch(IOException ex)
@@ -738,6 +754,22 @@ namespace IceSSL
return true;
}
+ internal void readCompleted(IAsyncResult result)
+ {
+ if(!result.CompletedSynchronously)
+ {
+ _readCallback(result.AsyncState);
+ }
+ }
+
+ internal void writeCompleted(IAsyncResult result)
+ {
+ if(!result.CompletedSynchronously)
+ {
+ _writeCallback(result.AsyncState);
+ }
+ }
+
private Instance _instance;
private Socket _fd;
private string _host;
@@ -754,6 +786,8 @@ namespace IceSSL
private int _state;
private IAsyncResult _writeResult;
private IAsyncResult _readResult;
+ private IceInternal.AsyncCallback _readCallback;
+ private IceInternal.AsyncCallback _writeCallback;
private X509Certificate2[] _chain;
private const int StateNeedConnect = 0;
diff --git a/cs/src/Makefile.mak b/cs/src/Makefile.mak
index cb2ece80039..bfd84b5412a 100644
--- a/cs/src/Makefile.mak
+++ b/cs/src/Makefile.mak
@@ -11,12 +11,16 @@ top_srcdir = ..
!include $(top_srcdir)\config\Make.rules.mak.cs
-SUBDIRS = Ice IceStorm Glacier2 IcePatch2 IceGrid IceBox
+SUBDIRS = Ice IceStorm Glacier2 IcePatch2 IceGrid
-!if "$(COMPACT)" != "yes"
+!if "$(COMPACT)" != "yes" && "$(SILVERLIGHT)" != "yes"
SUBDIRS = $(SUBDIRS) IceSSL
!endif
+!if "$(SILVERLIGHT)" != "yes"
+SUBDIRS = $(SUBDIRS) IceBox PolicyServer
+!endif
+
$(EVERYTHING)::
@for %i in ( $(SUBDIRS) ) do \
@echo "making $@ in %i" && \
diff --git a/cs/src/PolicyServer/AssemblyInfo.cs b/cs/src/PolicyServer/AssemblyInfo.cs
new file mode 100644
index 00000000000..fc57cb98c8a
--- /dev/null
+++ b/cs/src/PolicyServer/AssemblyInfo.cs
@@ -0,0 +1,45 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2012 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice for Silverlight is licensed to you under the terms
+// described in the ICESL_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("PolicyServer")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("ZeroC")]
+[assembly: AssemblyProduct("PolicyServer")]
+[assembly: AssemblyCopyright("Copyright © ZeroC 2012")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("ddd45a23-8a57-4389-aad4-401a2ae2a7fa")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/cs/src/PolicyServer/Makefile.mak b/cs/src/PolicyServer/Makefile.mak
new file mode 100644
index 00000000000..54a9e1b2c75
--- /dev/null
+++ b/cs/src/PolicyServer/Makefile.mak
@@ -0,0 +1,39 @@
+# **********************************************************************
+#
+# Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.
+#
+# This copy of Ice for Silverlight is licensed to you under the terms
+# described in the ICESL_LICENSE file included in this distribution.
+#
+# **********************************************************************
+
+top_srcdir = ..\..
+
+TARGETS = $(bindir)\policyserver.exe
+TARGETS_CONFIG = $(TARGETS:.exe=.exe.config)
+
+SRCS = PolicyServer.cs \
+ AssemblyInfo.cs
+
+!include $(top_srcdir)\config\Make.rules.mak.cs
+
+MCS = csc -nologo
+
+MCSFLAGS = -warnaserror -d:MAKEFILE_BUILD
+!if "$(DEBUG)" == "yes"
+MCSFLAGS = $(MCSFLAGS) -debug -define:DEBUG
+!endif
+
+!if "$(OPTIMIZE)" == "yes"
+MCSFLAGS = $(MCSFLAGS) -optimize+
+!endif
+
+MCSFLAGS = $(MCSFLAGS) -target:exe
+
+$(bindir)\policyserver.exe: $(SRCS)
+ $(MCS) $(MCSFLAGS) -out:$@ $(SRCS)
+
+!if "$(DEBUG)" == "yes"
+clean::
+ del /q $(bindir)\policyserver.pdb
+!endif \ No newline at end of file
diff --git a/cs/src/PolicyServer/PolicyServer.cs b/cs/src/PolicyServer/PolicyServer.cs
new file mode 100644
index 00000000000..487700dfe17
--- /dev/null
+++ b/cs/src/PolicyServer/PolicyServer.cs
@@ -0,0 +1,127 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice for Silverlight is licensed to you under the terms
+// described in the ICESL_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+using System;
+using System.IO;
+using System.Net;
+using System.Net.Sockets;
+using System.Threading;
+using System.Text;
+
+namespace PolicyService
+{
+
+//
+// This class implements a simple policy server for
+// Silverlight.
+//
+public sealed class PolicyServer : IDisposable
+{
+ public PolicyServer(string ipAddress, string policyFile)
+ {
+ _ipAddress = ipAddress;
+ _policyFile = policyFile;
+ }
+
+ public void Start()
+ {
+ IPAddress address = null;
+ try
+ {
+ address = IPAddress.Parse(_ipAddress);
+ }
+ catch(System.FormatException ex)
+ {
+ Console.WriteLine("Invalid IP address format: " + _ipAddress);
+ Console.WriteLine(ex.ToString());
+ return;
+ }
+ // Read policy file
+ try
+ {
+ _policyBytes = File.ReadAllBytes(_policyFile);
+ }
+ catch(System.IO.IOException ex)
+ {
+ Console.WriteLine("Error reading policy file: " + _policyFile);
+ Console.WriteLine(ex.ToString());
+ return;
+ }
+ _policyListener = new TcpListener(address, 943);
+ try
+ {
+ // Listen for policy requests
+ _policyListener.Start();
+ }
+ catch(SocketException ex)
+ {
+ Console.WriteLine("Error starting Policy Server:\n" + ex.ToString());
+ return;
+ }
+ Console.WriteLine("Policy Server started...");
+ // Start policy response thread
+ Thread policyThread = new Thread(ServePolicy);
+ policyThread.IsBackground = true;
+ policyThread.Start();
+ policyThread.Join();
+ }
+
+ private void ServePolicy()
+ {
+ while(true)
+ {
+ Console.WriteLine("Accepting Policy Requests...");
+ using(Socket client = _policyListener.AcceptSocket())
+ {
+ Console.WriteLine("Policy Request Accepted...");
+
+ // Get policy request header
+ byte[] buffer = new byte[1024];
+ int bytesReceived = client.Receive(buffer);
+
+ // Basic check of request header
+ string header = Encoding.UTF8.GetString(buffer, 0, bytesReceived);
+ if(header == "<policy-file-request/>")
+ {
+ client.Send(_policyBytes, 0, _policyBytes.Length, SocketFlags.None);
+ }
+ }
+ }
+ }
+
+ public void Dispose()
+ {
+ }
+
+ private string _ipAddress = "";
+ private string _policyFile = "";
+ private byte[] _policyBytes = null; // byte array used to store the response in memory.
+ private TcpListener _policyListener = null;
+}
+
+class Program
+{
+ static void Main(string[] args)
+ {
+ if(args.Length == 2)
+ {
+ // Start our Policy Service
+ using (PolicyServer server = new PolicyServer(args[0], args[1]))
+ {
+ server.Start();
+ }
+ }
+ else
+ {
+ Console.WriteLine("Usage: PolicyServer <ip-address> <policy-file>");
+ }
+ }
+}
+
+}