[System.ServiceModel] Don't use DateTime.Now for measuring elapsed time
authorAlexander Köplinger <alex.koeplinger@outlook.com>
Sun, 2 Jul 2017 16:35:51 +0000 (18:35 +0200)
committerAlexander Köplinger <alex.koeplinger@outlook.com>
Sun, 2 Jul 2017 21:31:34 +0000 (23:31 +0200)
Use Stopwatch or DateTime.UtcNow instead which aren't affected
by things like daylight-saving time

26 files changed:
mcs/class/System.ServiceModel.Discovery/System.ServiceModel.Discovery.Udp/UdpDuplexChannel.cs
mcs/class/System.ServiceModel.Discovery/System.ServiceModel.Discovery/DiscoveryChannelDispatcher.cs
mcs/class/System.ServiceModel.Discovery/System.ServiceModel.Discovery/DiscoveryRequestChannel.cs
mcs/class/System.ServiceModel.Discovery/Test/System.ServiceModel.Discovery/DiscoveryClientBindingElementTest.cs
mcs/class/System.ServiceModel/System.ServiceModel.Channels.Http/HttpChannelListener.cs
mcs/class/System.ServiceModel/System.ServiceModel.Channels.Http/HttpListenerManager.cs
mcs/class/System.ServiceModel/System.ServiceModel.Channels.Http/HttpReplyChannel.cs
mcs/class/System.ServiceModel/System.ServiceModel.Channels.NetTcp/PeerDuplexChannel.cs
mcs/class/System.ServiceModel/System.ServiceModel.Channels.NetTcp/TcpChannelListener.cs
mcs/class/System.ServiceModel/System.ServiceModel.Channels.NetTcp/TcpDuplexSessionChannel.cs
mcs/class/System.ServiceModel/System.ServiceModel.Channels.NetTcp/TcpReplyChannel.cs
mcs/class/System.ServiceModel/System.ServiceModel.Channels.NetTcp/TcpRequestChannel.cs
mcs/class/System.ServiceModel/System.ServiceModel.Channels.Security/SecurityReplyChannel.cs
mcs/class/System.ServiceModel/System.ServiceModel.Channels/ChannelFactoryBase.cs
mcs/class/System.ServiceModel/System.ServiceModel.Channels/NamedPipeChannelListener.cs
mcs/class/System.ServiceModel/System.ServiceModel.Channels/NamedPipeReplyChannel.cs
mcs/class/System.ServiceModel/System.ServiceModel.Channels/NamedPipeRequestChannel.cs
mcs/class/System.ServiceModel/System.ServiceModel.Channels/PeerChannelListener.cs
mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/ChannelDispatcher.cs
mcs/class/System.ServiceModel/System.ServiceModel.PeerResolvers/LocalPeerResolverService.cs
mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs
mcs/class/System.ServiceModel/System.ServiceModel/DuplexClientRuntimeChannel.cs
mcs/class/System.ServiceModel/System.ServiceModel/ServiceHostBase.cs
mcs/class/System.ServiceModel/Test/FeatureBased/Features.Serialization/OperationContractTester.cs
mcs/class/System.ServiceModel/old-code/HttpChannelListener.cs
mcs/class/System.ServiceModel/old-code/HttpReplyChannel.cs

index 38caf713397ccface5320f616d4ff86ff78bb92a..e8f53c7b598b0b0972faa7710ac6beb4f226297d 100644 (file)
@@ -152,7 +152,7 @@ namespace System.ServiceModel.Discovery.Udp
 
                public bool TryReceive (TimeSpan timeout, out Message msg)
                {
-                       DateTime start = DateTime.Now;
+                       DateTime start = DateTime.UtcNow;
                        ThrowIfDisposedOrNotOpen ();
                        msg = null;
 
@@ -188,7 +188,7 @@ namespace System.ServiceModel.Discovery.Udp
                        msg = message_encoder.ReadMessage (new MemoryStream (bytes), int.MaxValue);
                        var id = msg.Headers.MessageId;
                        if (message_ids.Contains (id))
-                               return TryReceive (timeout - (DateTime.Now - start), out msg);
+                               return TryReceive (timeout - (DateTime.UtcNow - start), out msg);
                        if (id != null) {
                                message_ids.Enqueue (id);
                                if (message_ids.Count >= binding_element.TransportSettings.DuplicateMessageHistoryLength)
index 82740e5a1e3b7acf61342b79998f2573e70b8092..2d00fc5c748da3b01986e09d7d8a0f9a0d4f1f9b 100644 (file)
@@ -86,7 +86,7 @@ namespace System.ServiceModel.Discovery
                        if (!handle_announce_online)
                                return; // Offline announcement is done by another DiscoveryChannelDispatcher
 
-                       DateTime start = DateTime.Now;
+                       DateTime start = DateTime.UtcNow;
                        Communication.Open (timeout);
 
                        // and call AnnouncementOnline().
@@ -94,7 +94,7 @@ namespace System.ServiceModel.Discovery
                        // Published endpoints are added by DicoveryEndpointPublisherBehavior, which is added to each ServiceEndpoint in the primary (non-announcement) service.
                        if (dx != null) {
                                foreach (var edm in dx.PublishedEndpoints) {
-                                       client.InnerChannel.OperationTimeout = timeout - (DateTime.Now - start);
+                                       client.InnerChannel.OperationTimeout = timeout - (DateTime.UtcNow - start);
                                        client.AnnounceOnline (edm);
                                }
                        }
@@ -115,19 +115,19 @@ namespace System.ServiceModel.Discovery
                        if (handle_announce_online)
                                return; // Offline announcement is done by another DiscoveryChannelDispatcher
 
-                       DateTime start = DateTime.Now;
+                       DateTime start = DateTime.UtcNow;
                        // and call AnnouncementOnline().
                        var dx = host.Extensions.Find<DiscoveryServiceExtension> ();
                        // Published endpoints are added by DicoveryEndpointPublisherBehavior, which is added to each ServiceEndpoint in the primary (non-announcement) service.
                        if (dx != null) {
                                foreach (var edm in dx.PublishedEndpoints) {
-                                       client.InnerChannel.OperationTimeout = timeout - (DateTime.Now - start);
+                                       client.InnerChannel.OperationTimeout = timeout - (DateTime.UtcNow - start);
                                        client.AnnounceOffline (edm);
                                }
                        }
 
                        // Then close the client.
-                       Communication.Close (timeout - (DateTime.Now - start));
+                       Communication.Close (timeout - (DateTime.UtcNow - start));
                }
 
                protected override IAsyncResult OnBeginClose (TimeSpan timeout, AsyncCallback callback, object state)
index 893fdf60912fbc03874c526746297bc2e56fd046..46e450eed156ffde7dae33a105f0823d114cdf55 100644 (file)
@@ -107,9 +107,9 @@ namespace System.ServiceModel.Discovery
                protected override void OnOpen (TimeSpan timeout)
                {
                        // FIXME: use timeout
-                       DateTime start = DateTime.Now;
+                       DateTime start = DateTime.UtcNow;
                        inner = CreateDiscoveryInnerChannel<TChannel> (factory);
-                       ((IChannel) inner).Open (timeout - (DateTime.Now - start));
+                       ((IChannel) inner).Open (timeout - (DateTime.UtcNow - start));
                }
 
                public Message Request (Message msg)
index 26083822660fd180c4cc965eb0a583ab5ba24795..6aa0faed67ef57ccdbc6e6e32a6ab5aa8c8a1495 100644 (file)
@@ -23,6 +23,7 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 using System;
+using System.Diagnostics;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.IO;
@@ -176,9 +177,9 @@ namespace MonoTests.System.ServiceModel.Discovery
                        Assert.IsNull (cf.GetProperty<DiscoveryEndpoint> (), "#1");
                        var ch = cf.CreateChannel (DiscoveryClientBindingElement.DiscoveryEndpointAddress);
                        Assert.IsNull (ch.GetProperty<DiscoveryEndpoint> (), "#2");
-                       DateTime start = DateTime.Now;
+                       var sw = Stopwatch.StartNew ();
                        ch.Open (TimeSpan.FromSeconds (5));
-                       Assert.IsTrue (DateTime.Now - start < TimeSpan.FromSeconds (15), "It is likely that FindCriteria.Duration is ignored");
+                       Assert.IsTrue (sw.Elapsed < TimeSpan.FromSeconds (15), "It is likely that FindCriteria.Duration is ignored");
                }
 
                [Test]
@@ -193,9 +194,9 @@ namespace MonoTests.System.ServiceModel.Discovery
                        var cf = be.BuildChannelFactory<IDuplexSessionChannel> (bc);
                        cf.Open ();
                        var ch = cf.CreateChannel (DiscoveryClientBindingElement.DiscoveryEndpointAddress);
-                       DateTime start = DateTime.Now;
+                       var sw = Stopwatch.StartNew ();
                        ch.Open (TimeSpan.FromSeconds (5));
-                       Assert.IsTrue (DateTime.Now - start < TimeSpan.FromSeconds (15), "It is likely that FindCriteria.Duration is ignored");
+                       Assert.IsTrue (sw.Elapsed < TimeSpan.FromSeconds (15), "It is likely that FindCriteria.Duration is ignored");
                }
 
                [Test]
index 895cf92ffbdd9d8773b7887b82e961680e4cd064..62a2c81f98e3ac1cf14fc608660c2235da9d8841 100644 (file)
@@ -87,15 +87,15 @@ namespace System.ServiceModel.Channels.Http
                {
                        // HTTP channel could be accepted while there is no incoming request yet. The reply channel waits for the actual request.
                        // HTTP channel listeners do not accept more than one channel at a time.
-                       DateTime start = DateTime.Now;
+                       DateTime start = DateTime.UtcNow;
                        TimeSpan waitTimeout;
                        if (timeout == TimeSpan.MaxValue)
                                waitTimeout = TimeSpan.FromMilliseconds(int.MaxValue);
                        else
-                               waitTimeout = timeout - (DateTime.Now - start);
+                               waitTimeout = timeout - (DateTime.UtcNow - start);
                        accept_channel_handle.WaitOne (waitTimeout);
                        accept_channel_handle.Reset (); 
-                       TChannel ch = CreateChannel (timeout - (DateTime.Now - start));
+                       TChannel ch = CreateChannel (timeout - (DateTime.UtcNow - start));
                        ch.Closed += delegate {
                                accept_channel_handle.Set ();
                        };
index 5ccee0a2605dfa6d5e968e426f232e0fcf9542fd..88d9ab0ff8c55fa6341f8b471b05fd3859372a7d 100644 (file)
@@ -94,7 +94,7 @@ namespace System.ServiceModel.Channels.Http
 
                public bool TryDequeueRequest (ChannelDispatcher channel, TimeSpan timeout, out HttpContextInfo context)
                {
-                       DateTime start = DateTime.Now;
+                       DateTime start = DateTime.UtcNow;
 
                        context = null;
                        HttpChannelListenerEntry ce = null;
@@ -111,7 +111,7 @@ namespace System.ServiceModel.Channels.Http
                                        if (timeout == TimeSpan.MaxValue)
                                                waitTimeout = TimeSpan.FromMilliseconds (int.MaxValue);
                                        bool ret = ce.WaitHandle.WaitOne (waitTimeout);
-                                       return ret && TryDequeueRequest (channel, waitTimeout - (DateTime.Now - start), out context); // recurse, am lazy :/
+                                       return ret && TryDequeueRequest (channel, waitTimeout - (DateTime.UtcNow - start), out context); // recurse, am lazy :/
                                }
                                context = q.Dequeue ();
                                return true;
index 098b622aa836a1ca86cba5c3fd4e1872fbc0aee8..768486c2fd4a6348bbb21b498dc86dc5499f3938 100644 (file)
@@ -113,12 +113,12 @@ namespace System.ServiceModel.Channels.Http
                                        return;
                                close_started = true;
                        }
-                       DateTime start = DateTime.Now;
+                       DateTime start = DateTime.UtcNow;
 
                        // FIXME: consider timeout
-                       AbortConnections (timeout - (DateTime.Now - start));
+                       AbortConnections (timeout - (DateTime.UtcNow - start));
 
-                       base.OnClose (timeout - (DateTime.Now - start));
+                       base.OnClose (timeout - (DateTime.UtcNow - start));
                }
 
                protected string GetHeaderItem (string raw)
index 4544e27fdb3e3bae71eb968d29edb349081c55d9..c934031bd5d2281bb9cde58c292f58c7ef7589bc 100644 (file)
@@ -221,7 +221,7 @@ namespace System.ServiceModel.Channels
                {
                        ThrowIfDisposedOrNotOpen ();
 
-                       DateTime start = DateTime.Now;
+                       DateTime start = DateTime.UtcNow;
 
                        // FIXME: give max buffer size
                        var mb = message.CreateBufferedCopy (0x10000);
@@ -234,14 +234,14 @@ namespace System.ServiceModel.Channels
                                        pc.Status = RemotePeerStatus.Error; // prepare for cases that it resulted in an error in the middle.
                                        var inner = CreateInnerClient (pc);
                                        pc.Channel = inner;
-                                       inner.Open (timeout - (DateTime.Now - start));
-                                       inner.OperationTimeout = timeout - (DateTime.Now - start);
+                                       inner.Open (timeout - (DateTime.UtcNow - start));
+                                       inner.OperationTimeout = timeout - (DateTime.UtcNow - start);
                                        inner.Connect (new ConnectInfo () { Address = local_node_address, NodeId = (uint) node.NodeId });
-                                       pc.Instance.WaitForConnectResponse (timeout - (DateTime.Now - start));
+                                       pc.Instance.WaitForConnectResponse (timeout - (DateTime.UtcNow - start));
                                        pc.Status = RemotePeerStatus.Connected;
                                }
 
-                               pc.Channel.OperationTimeout = timeout - (DateTime.Now - start);
+                               pc.Channel.OperationTimeout = timeout - (DateTime.UtcNow - start);
 
                                // see [MC-PRCH] 3.2.4.1
                                if (message.Headers.MessageId == null)
@@ -265,7 +265,6 @@ namespace System.ServiceModel.Channels
                public override bool TryReceive (TimeSpan timeout, out Message message)
                {
                        ThrowIfDisposedOrNotOpen ();
-                       DateTime start = DateTime.Now;
 
                        if (queue.Count > 0 || receive_handle.WaitOne (timeout)) {
                                message = queue.Dequeue ();
@@ -296,21 +295,21 @@ namespace System.ServiceModel.Channels
 
                protected override void OnClose (TimeSpan timeout)
                {
-                       DateTime start = DateTime.Now;
+                       DateTime start = DateTime.UtcNow;
                        if (client_factory != null)
-                               client_factory.Close (timeout - (DateTime.Now - start));
+                               client_factory.Close (timeout - (DateTime.UtcNow - start));
                        peers.Clear ();
-                       resolver.Unregister (node.RegisteredId, timeout - (DateTime.Now - start));
+                       resolver.Unregister (node.RegisteredId, timeout - (DateTime.UtcNow - start));
                        node.SetOffline ();
                        if (listener_host != null)
-                               listener_host.Close (timeout - (DateTime.Now - start));
+                               listener_host.Close (timeout - (DateTime.UtcNow - start));
                        node.RegisteredId = null;
                }
 
 
                protected override void OnOpen (TimeSpan timeout)
                {
-                       DateTime start = DateTime.Now;
+                       DateTime start = DateTime.UtcNow;
 
                        // FIXME: supply maxAddresses
                        foreach (var a in resolver.Resolve (node.MeshId, 3, timeout))
@@ -323,7 +322,7 @@ namespace System.ServiceModel.Channels
                        int port = 0;
                        var rnd = new Random ();
                        for (int i = 0; i < 1000; i++) {
-                               if (DateTime.Now - start > timeout)
+                               if (DateTime.UtcNow - start > timeout)
                                        throw new TimeoutException ();
                                try {
                                        port = rnd.Next (50000, 51000);
@@ -351,13 +350,13 @@ namespace System.ServiceModel.Channels
                        // FIXME: remove debugging code
                        listener_host.UnknownMessageReceived += delegate (object obj, UnknownMessageReceivedEventArgs earg) { Console.WriteLine ("%%%%% UNKOWN MESSAGE " + earg.Message); };
 
-                       listener_host.Open (timeout - (DateTime.Now - start));
+                       listener_host.Open (timeout - (DateTime.UtcNow - start));
 
                        var nid = (ulong) new Random ().Next (0, int.MaxValue);
                        var ea = new EndpointAddress (uri);
                        var pna = new PeerNodeAddress (ea, new ReadOnlyCollection<IPAddress> (Dns.GetHostEntry (name).AddressList));
                        local_node_address = pna;
-                       node.RegisteredId = resolver.Register (node.MeshId, pna, timeout - (DateTime.Now - start));
+                       node.RegisteredId = resolver.Register (node.MeshId, pna, timeout - (DateTime.UtcNow - start));
                        node.NodeId = nid;
 
                        // Add itself to the local list as well.
index 598ce3940299614566c568117cf2aefd46c8fb4e..aa3836518db02b1c275ec980868662ebb6015dd9 100644 (file)
@@ -73,7 +73,7 @@ namespace System.ServiceModel.Channels.NetTcp
 
                protected override TChannel OnAcceptChannel (TimeSpan timeout)
                {
-                       DateTime start = DateTime.Now;
+                       DateTime start = DateTime.UtcNow;
 
                        // Close channels that are incorrectly kept open first.
                        var l = new List<TcpDuplexSessionChannel> ();
@@ -83,9 +83,9 @@ namespace System.ServiceModel.Channels.NetTcp
                                        l.Add (dch);
                        }
                        foreach (var dch in l)
-                               dch.Close (timeout - (DateTime.Now - start));
+                               dch.Close (timeout - (DateTime.UtcNow - start));
 
-                       TcpClient client = AcceptTcpClient (timeout - (DateTime.Now - start));
+                       TcpClient client = AcceptTcpClient (timeout - (DateTime.UtcNow - start));
                        if (client == null)
                                return null; // onclose
 
@@ -109,7 +109,7 @@ namespace System.ServiceModel.Channels.NetTcp
                // TcpReplyChannel requires refreshed connection after each request processing.
                internal TcpClient AcceptTcpClient (TimeSpan timeout)
                {
-                       DateTime start = DateTime.Now;
+                       DateTime start = DateTime.UtcNow;
 
                        TcpClient client = accepted_clients.Count == 0 ? null : accepted_clients.Dequeue ();
                        if (client == null) {
@@ -121,7 +121,7 @@ namespace System.ServiceModel.Channels.NetTcp
                                }
                                accept_handles.Remove (wait);
                                // recurse with new timeout, or return null if it's either being closed or timed out.
-                               timeout -= (DateTime.Now - start);
+                               timeout -= (DateTime.UtcNow - start);
                                return State == CommunicationState.Opened && timeout > TimeSpan.Zero ? AcceptTcpClient (timeout) : null;
                        }
 
@@ -132,7 +132,7 @@ namespace System.ServiceModel.Channels.NetTcp
                                        continue;
                                if (((IPEndPoint) dch.TcpClient.Client.RemoteEndPoint).Equals (client.Client.RemoteEndPoint))
                                        // ... then it should be handled in another BeginTryReceive/EndTryReceive loop in ChannelDispatcher.
-                                       return AcceptTcpClient (timeout - (DateTime.Now - start));
+                                       return AcceptTcpClient (timeout - (DateTime.UtcNow - start));
                        }
 
                        return client;
index 45f9def56ec5ecc4354012ed9f0916d92334a9db..60d9c42aadcf69b9aa73403928f627596eba62a4 100644 (file)
@@ -187,12 +187,12 @@ namespace System.ServiceModel.Channels.NetTcp
                        if (client.Available > 0)
                                return true;
 
-                       DateTime start = DateTime.Now;
+                       DateTime start = DateTime.UtcNow;
                        do {
                                Thread.Sleep (50);
                                if (client.Available > 0)
                                        return true;
-                       } while (DateTime.Now - start < timeout);
+                       } while (DateTime.UtcNow - start < timeout);
                        return false;
                }
                
index b005ad6c18a06fef5ffcb22513f9eb31f318e041..a83d1f2669b2a2ff4cd571feb9d7e92a709ba00a 100644 (file)
@@ -58,8 +58,6 @@ namespace System.ServiceModel.Channels.NetTcp
                        if (timeout <= TimeSpan.Zero)
                                throw new ArgumentException (String.Format ("Timeout value must be positive value. It was {0}", timeout));
 
-                       DateTime start = DateTime.Now;
-
                        // FIXME: use timeout
                        if (client == null)
                                client = ((TcpChannelListener<IReplyChannel>) Manager).AcceptTcpClient (timeout);
@@ -110,7 +108,6 @@ namespace System.ServiceModel.Channels.NetTcp
                        {
                                Logger.LogMessage (MessageLogSourceKind.TransportSend, ref message, owner.info.BindingElement.MaxReceivedMessageSize);
 
-                               DateTime start = DateTime.Now;
                                owner.frame.WriteUnsizedMessage (message, timeout);
                                // FIXME: consider timeout here too.
                                owner.frame.WriteEndRecord ();
@@ -120,7 +117,6 @@ namespace System.ServiceModel.Channels.NetTcp
                public override bool TryReceiveRequest (TimeSpan timeout, out RequestContext context)
                {
                        try {
-                               DateTime start = DateTime.Now;
                                context = ReceiveRequest (timeout);
                                return context != null;
                        } catch (Exception ex) {
index 27d62eec7785c808b03c99de593b87f47b395d75..9ce56a5470107855a48a87341a2f0c3589adf4b6 100644 (file)
@@ -82,7 +82,7 @@ namespace System.ServiceModel.Channels.NetTcp
 
                public override Message Request (Message input, TimeSpan timeout)
                {
-                       DateTime start = DateTime.Now;
+                       DateTime start = DateTime.UtcNow;
 
                        // FIXME: use timeouts.
                        frame.ProcessPreambleInitiator ();
@@ -95,13 +95,13 @@ namespace System.ServiceModel.Channels.NetTcp
 
                        Logger.LogMessage (MessageLogSourceKind.TransportSend, ref input, int.MaxValue); // It is not a receive buffer
 
-                       frame.WriteUnsizedMessage (input, timeout - (DateTime.Now - start));
+                       frame.WriteUnsizedMessage (input, timeout - (DateTime.UtcNow - start));
 
                        // LAMESPEC: it contradicts the protocol described at section 3.1.1.1.1 in [MC-NMF].
                        // Moving this WriteEndRecord() after ReadUnsizedMessage() causes TCP connection blocking.
                        frame.WriteEndRecord ();
 
-                       var ret = frame.ReadUnsizedMessage (timeout - (DateTime.Now - start));
+                       var ret = frame.ReadUnsizedMessage (timeout - (DateTime.UtcNow - start));
 
                        Logger.LogMessage (MessageLogSourceKind.TransportReceive, ref ret, info.BindingElement.MaxReceivedMessageSize);
 
index d4c44b62b13030e62ff70ed49888efdc0de37bb1..9f5314b98bd5653fdf53dbbc2ccc6924fc3038dd 100644 (file)
@@ -77,7 +77,7 @@ namespace System.ServiceModel.Channels.Security
 
                public override bool TryReceiveRequest (TimeSpan timeout, out RequestContext context)
                {
-                       DateTime start = DateTime.Now;
+                       DateTime start = DateTime.UtcNow;
 
                        if (!inner.TryReceiveRequest (timeout, out context))
                                return false;
@@ -95,14 +95,14 @@ namespace System.ServiceModel.Channels.Security
                                var support = Source.SecuritySupport;
                                var commAuth = support.TokenAuthenticator as CommunicationSecurityTokenAuthenticator;
                                if (commAuth != null)
-                                       res = commAuth.Communication.ProcessNegotiation (req, timeout - (DateTime.Now - start));
+                                       res = commAuth.Communication.ProcessNegotiation (req, timeout - (DateTime.UtcNow - start));
                                else
                                        throw new MessageSecurityException ("This reply channel does not expect incoming WS-Trust requests");
 
-                               context.Reply (res, timeout - (DateTime.Now - start));
-                               context.Close (timeout - (DateTime.Now - start));
+                               context.Reply (res, timeout - (DateTime.UtcNow - start));
+                               context.Close (timeout - (DateTime.UtcNow - start));
                                // wait for another incoming message
-                               return TryReceiveRequest (timeout - (DateTime.Now - start), out context);
+                               return TryReceiveRequest (timeout - (DateTime.UtcNow - start), out context);
 
                                break;
                        }
index d4df2f0f12fbe00c94cc284c68bbbf2a7299b997..d2d054d07fefa019c63187eaffa8e778b531e827 100644 (file)
@@ -132,11 +132,11 @@ namespace System.ServiceModel.Channels
 
                protected override void OnClose (TimeSpan timeout)
                {
-                       DateTime start = DateTime.Now;
+                       DateTime start = DateTime.UtcNow;
                        // this implicitly premises: TChannel is IChannel
                        foreach (IChannel ch in channels)
-                               ch.Close (timeout - (DateTime.Now - start));
-                       base.OnClose (timeout - (DateTime.Now - start));
+                               ch.Close (timeout - (DateTime.UtcNow - start));
+                       base.OnClose (timeout - (DateTime.UtcNow - start));
                }
 
                protected override IAsyncResult OnBeginClose (TimeSpan timeout, AsyncCallback callback, object state)
index ebe57f13b8cce892e8145c6d82bd5dc4457e1e24..51feed017961e36d104b36ef4add80d78fbf2a4c 100644 (file)
@@ -69,7 +69,6 @@ namespace System.ServiceModel.Channels
                {
 Console.WriteLine ("NamedPipeChannelListener.OnAcceptChannel");
 
-                       DateTime start = DateTime.Now;
                        if (active_server != null) {
                                try {
                                        server_release_handle.WaitOne (timeout);
index 89feba11fb9103598976b77cb86b3ba2ba507f61..93d06113fa096880ec40701bea7ba988f52270ea 100644 (file)
@@ -95,7 +95,6 @@ namespace System.ServiceModel.Channels
                                if (message.Headers.RelatesTo == null)
                                        message.Headers.RelatesTo = request.Headers.MessageId;
 
-                               DateTime start = DateTime.Now;
                                owner.frame.WriteUnsizedMessage (message, timeout);
                                owner.frame.WriteEndRecord ();
                                owner.server.Close ();
@@ -106,7 +105,6 @@ namespace System.ServiceModel.Channels
                public override bool TryReceiveRequest (TimeSpan timeout, out RequestContext context)
                {
                        try {
-                               DateTime start = DateTime.Now;
                                context = ReceiveRequest (timeout);
                                return context != null;
                        } catch (TimeoutException) {
@@ -126,8 +124,6 @@ namespace System.ServiceModel.Channels
 
                protected override void OnOpen (TimeSpan timeout)
                {
-                       DateTime start = DateTime.Now;
-
                        // FIXME: use timeout
                        frame = new TcpBinaryFrameManager (TcpBinaryFrameManager.SingletonUnsizedMode, server, true) { Encoder = this.Encoder };
                        frame.ProcessPreambleRecipient ();
index 178ae7522a2c5c58639e467d33c4a1f7ececfbc0..5d676a26adec7552d3e34ab1859cbe324526cf45 100644 (file)
@@ -78,7 +78,7 @@ namespace System.ServiceModel.Channels
 
                public override Message Request (Message input, TimeSpan timeout)
                {
-                       DateTime start = DateTime.Now;
+                       DateTime start = DateTime.UtcNow;
 
                        CreateClient (timeout);
 
@@ -87,11 +87,11 @@ namespace System.ServiceModel.Channels
                        if (input.Headers.MessageId == null)
                                input.Headers.MessageId = new UniqueId ();
 
-                       frame.WriteUnsizedMessage (input, timeout - (DateTime.Now - start));
+                       frame.WriteUnsizedMessage (input, timeout - (DateTime.UtcNow - start));
 
                        frame.WriteEndRecord ();
 
-                       var ret = frame.ReadUnsizedMessage (timeout - (DateTime.Now - start));
+                       var ret = frame.ReadUnsizedMessage (timeout - (DateTime.UtcNow - start));
                        frame.ReadEndRecord ();
                        return ret;
                }
index 1a2e6581f472e6979b69deb26c84e5c03b7bc515..39303073f964c48c950304ef7dc5ab60313c6595 100755 (executable)
@@ -70,11 +70,11 @@ namespace System.ServiceModel.Channels
 
                protected override TChannel OnAcceptChannel (TimeSpan timeout)
                {
-                       DateTime start = DateTime.Now;
+                       DateTime start = DateTime.UtcNow;
                        if (channel != null)
                                if (!accept_handle.WaitOne (timeout))
                                        throw new TimeoutException ();
-                       channel = PopulateChannel (timeout - (DateTime.Now - start));
+                       channel = PopulateChannel (timeout - (DateTime.UtcNow - start));
                        ((CommunicationObject) (object) channel).Closed += delegate {
                                this.channel = null;
                                accept_handle.Set ();
index f1a7ca308c058f0ec29cfea5e1516b933687a712..96295321715d7f2da3156eb9bb3bd2d334f49866 100644 (file)
@@ -414,7 +414,7 @@ namespace System.ServiceModel.Dispatcher
                                if (loop_thread == null)
                                        return;
 
-                               close_started = DateTime.Now;
+                               close_started = DateTime.UtcNow;
                                close_timeout = timeout;
                                loop = false;
                                creator_handle.Set ();
@@ -467,7 +467,7 @@ namespace System.ServiceModel.Dispatcher
                                        }
                                        else {
                                                try {
-                                                       ch.Close (close_timeout - (DateTime.Now - close_started));
+                                                       ch.Close (close_timeout - (DateTime.UtcNow - close_started));
                                                } catch (Exception ex) {
                                                        // FIXME: log it.
                                                        Logger.Error (String.Format ("Exception on closing channel ({0})", ch.GetType ()), ex);
index 46338d9bd7824886436d1d5cc9ecc7f34c716b4b..fc9a9febb79c75ba0a8e5866a38ea151b1d0c406 100755 (executable)
@@ -95,7 +95,7 @@ namespace System.ServiceModel.PeerResolvers
                        if (node == null)
                                return new RefreshResponseInfo () { Result = RefreshResult.RegistrationNotFound };
                        node.Refresh ();
-                       return new RefreshResponseInfo () { Result = RefreshResult.Success, RegistrationLifetime = RefreshInterval - (DateTime.Now - node.LastRefreshTime) };
+                       return new RefreshResponseInfo () { Result = RefreshResult.Success, RegistrationLifetime = RefreshInterval - (DateTime.UtcNow - node.LastRefreshTime) };
                }
 
                public RegisterResponseInfo Register (RegisterInfo registerInfo)
@@ -163,7 +163,7 @@ namespace System.ServiceModel.PeerResolvers
                        lock (mesh) {
                                var node = new Node () { ClientId = clientId, Address = addr };
                                mesh.Add (node);
-                               node.LastRefreshTime = DateTime.Now;
+                               node.LastRefreshTime = DateTime.UtcNow;
                                return node;
                        }
                }
@@ -201,13 +201,13 @@ namespace System.ServiceModel.PeerResolvers
 
                public void Refresh ()
                {
-                       LastRefreshTime = DateTime.Now;
+                       LastRefreshTime = DateTime.UtcNow;
                }
 
                public void Update (PeerNodeAddress addr)
                {
                        Address = addr;
-                       LastRefreshTime = DateTime.Now;
+                       LastRefreshTime = DateTime.UtcNow;
                }
        }
 }
index 36ea57b5b9fd7b6170cc447d46b2da4cc1f19b26..df7a9e4cd9742a07869d9f9be7ada306ca16312e 100644 (file)
@@ -383,7 +383,6 @@ namespace System.ServiceModel.MonoInternal
 
                protected override void OnClose (TimeSpan timeout)
                {
-                       DateTime start = DateTime.Now;
                        if (channel.State == CommunicationState.Opened)
                                channel.Close (timeout);
                }
@@ -593,9 +592,9 @@ namespace System.ServiceModel.MonoInternal
                        // FIXME: implement ConcurrencyMode check:
                        // if it is .Single && this instance for a callback channel && the operation is invoked inside service operation, then error.
 
-                       DateTime startTime = DateTime.Now;
+                       DateTime startTime = DateTime.UtcNow;
                        OutputChannel.Send (msg, timeout);
-                       return ((IDuplexChannel) channel).Receive (timeout - (DateTime.Now - startTime));
+                       return ((IDuplexChannel) channel).Receive (timeout - (DateTime.UtcNow - startTime));
                }
 
                internal IAsyncResult BeginRequest (Message msg, TimeSpan timeout, AsyncCallback callback, object state)
index db6647c76f5188f5277d129baca9bb48dc5f225e..08e6a6e38bae049056f0299c43bf761a007f89cc 100644 (file)
@@ -115,12 +115,12 @@ namespace System.ServiceModel.MonoInternal
 
                protected override void OnClose (TimeSpan timeout)
                {
-                       DateTime start = DateTime.Now;
+                       DateTime start = DateTime.UtcNow;
                        base.OnClose (timeout);
                        loop = false;
-                       if (!loop_handle.WaitOne (timeout - (DateTime.Now - start)))
+                       if (!loop_handle.WaitOne (timeout - (DateTime.UtcNow - start)))
                                throw new TimeoutException ();
-                       if (!finish_handle.WaitOne (timeout - (DateTime.Now - start)))
+                       if (!finish_handle.WaitOne (timeout - (DateTime.UtcNow - start)))
                                throw new TimeoutException ();
                }
 
@@ -204,7 +204,7 @@ namespace System.ServiceModel.MonoInternal
                
                internal override Message RequestCorrelated (Message msg, TimeSpan timeout, IOutputChannel channel)
                {
-                       DateTime startTime = DateTime.Now;
+                       DateTime startTime = DateTime.UtcNow;
                        Message ret = null;
                        ManualResetEvent wait = new ManualResetEvent (false);
                        Action<Message> handler = delegate (Message reply) {
@@ -213,7 +213,7 @@ namespace System.ServiceModel.MonoInternal
                        };
                        ReplyHandlerQueue.Enqueue (handler);
                        channel.Send (msg, timeout);
-                       if (ret == null && !wait.WaitOne (timeout - (DateTime.Now - startTime)))
+                       if (ret == null && !wait.WaitOne (timeout - (DateTime.UtcNow - startTime)))
                                throw new TimeoutException ();
                        return ret;
                }
index 1a84cecc5842e18f6e3e6df25253cbea370641fd..e4ae96cc90f289d94e3f13be1596bc8e65531d48 100644 (file)
@@ -528,12 +528,12 @@ namespace System.ServiceModel
                
                void OnCloseOrAbort (TimeSpan timeout)
                {
-                       DateTime start = DateTime.Now;
+                       DateTime start = DateTime.UtcNow;
                        ReleasePerformanceCounters ();
                        List<ChannelDispatcherBase> l = new List<ChannelDispatcherBase> (ChannelDispatchers);
                        foreach (ChannelDispatcherBase e in l) {
                                try {
-                                       TimeSpan ts = timeout - (DateTime.Now - start);
+                                       TimeSpan ts = timeout - (DateTime.UtcNow - start);
                                        if (ts < TimeSpan.Zero)
                                                e.Abort ();
                                        else
@@ -547,7 +547,7 @@ namespace System.ServiceModel
 
                protected override sealed void OnOpen (TimeSpan timeout)
                {
-                       DateTime start = DateTime.Now;
+                       DateTime start = DateTime.UtcNow;
                        InitializeRuntime ();
                        for (int i = 0; i < ChannelDispatchers.Count; i++) {
                                // Skip ServiceMetadataExtension-based one. special case.
@@ -567,7 +567,7 @@ namespace System.ServiceModel
                                var wait = new ManualResetEvent (false);
                                cd.Opened += delegate { wait.Set (); };
                                waits.Add (wait);
-                               cd.Open (timeout - (DateTime.Now - start));
+                               cd.Open (timeout - (DateTime.UtcNow - start));
                        }
 
                        WaitHandle.WaitAll (waits.ToArray ());
index 9eb4671e13a783a970f9b8851827eba68ed92daa..9ae0612c49506d5b6dccd1ef0a54836292cfb9a2 100644 (file)
@@ -27,14 +27,13 @@ namespace MonoTests.Features.Serialization
                                sleepTime = 5 * 1000;\r
                                failTime = 2 * 1000;\r
                        }\r
-                       DateTime start = DateTime.Now;\r
+                       var sw = global::System.Diagnostics.Stopwatch.StartNew ();\r
                        Client.Sleep (sleepTime);\r
-                       DateTime end = DateTime.Now;\r
-                       TimeSpan diff = end.Subtract (start);\r
+                       sw.Stop ();\r
                        TimeSpan max = TimeSpan.FromMilliseconds(failTime);\r
-                       Assert.IsTrue (diff < max, "Sleep({0} milisec) must end in less than {1} seconds",sleepTime,failTime);\r
-                       if (sleepTime > (int) diff.TotalMilliseconds)\r
-                               Thread.Sleep (sleepTime - (int)diff.TotalMilliseconds); // wait for server thread to release itself\r
+                       Assert.IsTrue (sw.Elapsed < max, "Sleep({0} milisec) must end in less than {1} seconds",sleepTime,failTime);\r
+                       if (sleepTime > (int) sw.ElapsedMilliseconds)\r
+                               Thread.Sleep (sleepTime - (int)sw.ElapsedMilliseconds); // wait for server thread to release itself\r
                }\r
 \r
                [Test]\r
index 310a4728787d65c7930b4f38de958cbbb4d1007a..9574291c43dc7a2972ee4ce18410ef5646b28214 100644 (file)
@@ -145,10 +145,10 @@ namespace System.ServiceModel.Channels
                protected override TChannel OnAcceptChannel (TimeSpan timeout)
                {
                        // HTTP channel listeners do not accept more than one channel at a time.
-                       DateTime start = DateTime.Now;
-                       accept_channel_handle.WaitOne (timeout - (DateTime.Now - start));
+                       DateTime start = DateTime.UtcNow;
+                       accept_channel_handle.WaitOne (timeout - (DateTime.UtcNow - start));
                        accept_channel_handle.Reset ();
-                       TChannel ch = CreateChannel (timeout - (DateTime.Now - start));
+                       TChannel ch = CreateChannel (timeout - (DateTime.UtcNow - start));
                        ch.Closed += delegate {
                                accept_channel_handle.Set ();
                        };
index 9e1a0f04e886d419f2291266017f8ed9504e0a7d..a8b28c3ebea482df04545bc14addc81d54772b8a 100644 (file)
@@ -85,14 +85,14 @@ namespace System.ServiceModel.Channels
 
                protected override void OnClose (TimeSpan timeout)
                {
-                       DateTime start = DateTime.Now;
+                       DateTime start = DateTime.UtcNow;
                        if (reqctx != null)
                                reqctx.Close (timeout);
 
                        // FIXME: consider timeout
-                       AbortConnections (timeout - (DateTime.Now - start));
+                       AbortConnections (timeout - (DateTime.UtcNow - start));
 
-                       base.OnClose (timeout - (DateTime.Now - start));
+                       base.OnClose (timeout - (DateTime.UtcNow - start));
                }
 
                public override bool TryReceiveRequest (TimeSpan timeout, out RequestContext context)