Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Issue #42 fixes. #55

Closed
wants to merge 3 commits into from

2 participants

@mjwood7

Fixes for issue #42. Usage of System.Environment.TickCount has been replaced with DateTime milliseconds.

@gbirchmeier
Collaborator

Thanks, Matt. I'll try to have a look at it today.

@gbirchmeier
Collaborator

Apologies for the delay. I've spent two days recovering from a HD crash on my primary machine. I plan to look at this over the weekend.

@mjwood7

No problem... sorry to hear about the crash.

@gbirchmeier
Collaborator

This did not build for me. Did build the UnitTests project? I'm getting lots of compile failures in SessionStateTest.cs.

@mjwood7

I didn't do anything with the UnitTests project. I'll have to look into it.

@gbirchmeier
Collaborator

The entire solution must build, and all applicable tests must be adjusted/corrected or removed with reason. Depending on the fix, the addition of new tests may be appropriate.

We're very big on using using tests to prevent against accidental breakage of features.

@gbirchmeier
Collaborator

Can you use DateTime.UtcNow instead of DateTime.Now?

@gbirchmeier
Collaborator

Submission does not build as part of whole solution. (Unit test project is broken.) We cannot accept.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 26, 2012
  1. quickfixn issue #42 fixes. Environment.tickcount

    Matt Wood authored
  2. @mjwood7
  3. @mjwood7

    QuickFixn Issue #42 fixes.

    mjwood7 authored
This page is out of date. Refresh to see the latest.
View
7 QuickFIX.NET/Session.cs
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using QuickFix.Fields;
+using System;
namespace QuickFix
{
@@ -863,7 +864,7 @@ public bool Verify(Message msg, bool checkTooHigh, bool checkTooLow)
return false;
}
- state_.LastReceivedTimeTickCount = System.Environment.TickCount;
+ state_.LastReceivedTimeDT = DateTime.Now;
state_.TestRequestCounter = 0;
if (Message.IsAdminMsgType(msgType))
@@ -1099,7 +1100,7 @@ protected bool GenerateLogon()
logon.SetField(new Fields.ResetSeqNumFlag(true));
InitializeHeader(logon);
- state_.LastReceivedTimeTickCount = System.Environment.TickCount;
+ state_.LastReceivedTimeDT = DateTime.Now;
state_.TestRequestCounter = 0;
state_.SentLogon = true;
return SendRaw(logon, 0);
@@ -1294,7 +1295,7 @@ protected void PopulateRejectReason(Message reject, string text)
/// <param name="m"></param>
protected void InitializeHeader(Message m, int msgSeqNum)
{
- state_.LastSentTimeTickCount = System.Environment.TickCount;
+ state_.LastSentTimeDT = DateTime.Now;
m.Header.SetField(new Fields.BeginString(this.SessionID.BeginString));
m.Header.SetField(new Fields.SenderCompID(this.SessionID.SenderCompID));
if (SessionID.IsSet(this.SessionID.SenderSubID))
View
92 QuickFIX.NET/SessionState.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using System;
namespace QuickFix
{
@@ -20,8 +21,8 @@ public class SessionState : MessageStore
private int testRequestCounter_ = 0;
private int heartBtInt_ = 0;
private int heartBtIntAsTickCount_ = 0;
- private int lastReceivedTimeTickCount_;
- private int lastSentTimeTickCount_;
+ private DateTime lastReceivedTimeDT_ = DateTime.MinValue;
+ private DateTime lastSentTimeDT_ = DateTime.MinValue;
private int logonTimeout_ = 10;
private long logonTimeoutAsTickCount_ = 10 * 1000;
private int logoutTimeout_ = 2;
@@ -110,16 +111,17 @@ public int HeartBtIntAsTickCount
get { lock (sync_) { return heartBtIntAsTickCount_; } }
}
- public int LastReceivedTimeTickCount
+ public DateTime LastReceivedTimeDT
{
- get { lock (sync_) { return lastReceivedTimeTickCount_; } }
- set { lock (sync_) { lastReceivedTimeTickCount_ = value; } }
+ get { lock (sync_) { return lastReceivedTimeDT_; } }
+ set { lock (sync_) { lastReceivedTimeDT_ = value; } }
}
- public int LastSentTimeTickCount
+
+ public DateTime LastSentTimeDT
{
- get { lock (sync_) { return lastSentTimeTickCount_; } }
- set { lock (sync_) { lastSentTimeTickCount_ = value; } }
+ get { lock (sync_) { return lastSentTimeDT_; } }
+ set { lock (sync_) { lastSentTimeDT_ = value; } }
}
public int LogonTimeout
@@ -158,112 +160,112 @@ public SessionState(Log log, int heartBtInt)
this.HeartBtInt = heartBtInt;
this.IsInitiator = (0 != heartBtInt);
int now = System.Environment.TickCount;
- lastReceivedTimeTickCount_ = now;
- lastSentTimeTickCount_ = now;
+ lastReceivedTimeDT_ = DateTime.Now;
+ lastSentTimeDT_ = DateTime.Now;
}
/// <summary>
/// All time args are in milliseconds
/// </summary>
- /// <param name="now">current system time in milliseconds</param>
- /// <param name="lastReceivedTime">last received time in milliseconds</param>
+ /// <param name="now">current system time</param>
+ /// <param name="lastReceivedTime">last received time</param>
/// <param name="logonTimeout">number of milliseconds to wait for a Logon from the counterparty</param>
/// <returns></returns>
- public static bool LogonTimedOut(int now, long logonTimeout, int lastReceivedTime)
+ public static bool LogonTimedOut(DateTime now, long logonTimeout, DateTime lastReceivedTime)
{
- return (now - lastReceivedTime) >= logonTimeout;
+ return (now.Subtract(lastReceivedTime).TotalMilliseconds) >= logonTimeout;
}
public bool LogonTimedOut()
{
- return LogonTimedOut(System.Environment.TickCount, this.LogonTimeoutAsTickCount, this.LastReceivedTimeTickCount);
+ return LogonTimedOut(DateTime.Now, this.LogonTimeoutAsTickCount, this.LastReceivedTimeDT);
}
/// <summary>
/// All time args are in milliseconds
/// </summary>
- /// <param name="now">current system time in milliseconds</param>
+ /// <param name="now">current system datetime</param>
/// <param name="heartBtIntMillis">heartbeat interval in milliseconds</param>
- /// <param name="lastReceivedTime">last received time in milliseconds</param>
+ /// <param name="lastReceivedTime">last received datetime</param>
/// <returns>true if timed out</returns>
- public static bool TimedOut(int now, int heartBtIntMillis, int lastReceivedTime)
+ public static bool TimedOut(DateTime now, int heartBtIntMillis, DateTime lastReceivedTime)
{
- int elapsed = now - lastReceivedTime;
+ double elapsed = now.Subtract(lastReceivedTime).TotalMilliseconds;
return elapsed >= (2.4 * heartBtIntMillis);
}
public bool TimedOut()
{
- return TimedOut(System.Environment.TickCount, this.HeartBtIntAsTickCount, this.LastReceivedTimeTickCount);
+ return TimedOut(DateTime.Now, this.HeartBtIntAsTickCount, this.LastReceivedTimeDT);
}
/// <summary>
/// All time args are in milliseconds
/// </summary>
- /// <param name="now">current system time in milliseconds</param>
+ /// <param name="now">current system time</param>
/// <param name="sentLogout">true if a Logout has been sent to the counterparty, otherwise false</param>
/// <param name="logoutTimeout">number of milliseconds to wait for a Logout from the counterparty</param>
- /// <param name="lastSentTime">last sent time in milliseconds</param>
+ /// <param name="lastSentTime">last sent time</param>
/// <returns></returns>
- public static bool LogoutTimedOut(int now, bool sentLogout, long logoutTimeout, int lastSentTime)
+ public static bool LogoutTimedOut(DateTime now, bool sentLogout, long logoutTimeout, DateTime lastSentTime)
{
- return sentLogout && ((now - lastSentTime) >= logoutTimeout);
+ return sentLogout && ((now.Subtract(lastSentTime).TotalMilliseconds) >= logoutTimeout);
}
public bool LogoutTimedOut()
{
- return LogoutTimedOut(System.Environment.TickCount, this.SentLogout, this.LogoutTimeoutAsTickCount, this.LastSentTimeTickCount);
+ return LogoutTimedOut(DateTime.Now, this.SentLogout, this.LogoutTimeoutAsTickCount, this.LastSentTimeDT);
}
/// <summary>
/// All time args are in milliseconds
/// </summary>
- /// <param name="now">current system time in milliseconds</param>
+ /// <param name="now">current system time</param>
/// <param name="heartBtIntMillis">heartbeat interval in milliseconds</param>
- /// <param name="lastReceivedTime">last received time in milliseconds</param>
+ /// <param name="lastReceivedTime">last received time</param>
/// <param name="testRequestCounter">test request counter</param>
/// <returns>true if test request is needed</returns>
- public static bool NeedTestRequest(int now, int heartBtIntMillis, int lastReceivedTime, int testRequestCounter)
+ public static bool NeedTestRequest(DateTime now, int heartBtIntMillis, DateTime lastReceivedTime, int testRequestCounter)
{
- int elapsedTickCount = now - lastReceivedTime;
+ double elapsedTickCount = now.Subtract(lastReceivedTime).TotalMilliseconds;
return elapsedTickCount >= (1.2 * ((testRequestCounter + 1) * heartBtIntMillis));
}
public bool NeedTestRequest()
{
- return NeedTestRequest(System.Environment.TickCount, this.HeartBtIntAsTickCount, this.LastReceivedTimeTickCount, this.TestRequestCounter);
+ return NeedTestRequest(DateTime.Now, this.HeartBtIntAsTickCount, this.LastReceivedTimeDT, this.TestRequestCounter);
}
/// <summary>
/// All time args are in milliseconds
/// </summary>
- /// <param name="now">current system time in milliseconds</param>
+ /// <param name="now">current system time</param>
/// <param name="heartBtIntMillis">heartbeat interval in milliseconds</param>
- /// <param name="lastSentTime">last sent time in milliseconds</param>
+ /// <param name="lastSentTime">last sent time</param>
/// <param name="testRequestCounter">test request counter</param>
/// <returns>true if heartbeat is needed</returns>
- public static bool NeedHeartbeat(int now, int heartBtIntMillis, int lastSentTime, int testRequestCounter)
+ public static bool NeedHeartbeat(DateTime now, int heartBtIntMillis, DateTime lastSentTime, int testRequestCounter)
{
- int elapsed = now - lastSentTime;
- return (elapsed >= heartBtIntMillis) && (0 == testRequestCounter);
+ double elapsed = now.Subtract(lastSentTime).TotalMilliseconds;
+ return (elapsed >= Convert.ToDouble(heartBtIntMillis)) && (0 == testRequestCounter);
}
public bool NeedHeartbeat()
{
- return NeedHeartbeat(System.Environment.TickCount, this.HeartBtIntAsTickCount, this.LastSentTimeTickCount, this.TestRequestCounter);
+ return NeedHeartbeat(DateTime.Now, this.HeartBtIntAsTickCount, this.LastSentTimeDT, this.TestRequestCounter);
}
/// <summary>
/// All time args are in milliseconds
/// </summary>
- /// <param name="now">current system time in milliseconds</param>
+ /// <param name="now">current system time</param>
/// <param name="heartBtIntMillis">heartbeat interval in milliseconds</param>
- /// <param name="lastSentTime">last sent time in milliseconds</param>
- /// <param name="lastReceivedTime">last received time in milliseconds</param>
+ /// <param name="lastSentTime">last sent time</param>
+ /// <param name="lastReceivedTime">last received time</param>
/// <returns>true if within heartbeat interval</returns>
- public static bool WithinHeartbeat(int now, int heartBtIntMillis, int lastSentTime, int lastReceivedTime)
+ public static bool WithinHeartbeat(DateTime now, int heartBtIntMillis, DateTime lastSentTime, DateTime lastReceivedTime)
{
- return ((now - lastSentTime) < heartBtIntMillis)
- && ((now - lastReceivedTime) < heartBtIntMillis);
+ return ((now.Subtract(lastSentTime).TotalMilliseconds) < Convert.ToDouble(heartBtIntMillis))
+ && ((now.Subtract(lastReceivedTime).TotalMilliseconds) < Convert.ToDouble(heartBtIntMillis));
}
public bool WithinHeartbeat()
{
- return WithinHeartbeat(System.Environment.TickCount, this.HeartBtIntAsTickCount, this.LastSentTimeTickCount, this.LastReceivedTimeTickCount);
+ return WithinHeartbeat(DateTime.Now, this.HeartBtIntAsTickCount, this.LastSentTimeDT, this.LastReceivedTimeDT);
}
public ResendRange GetResendRange()
@@ -328,8 +330,8 @@ public override string ToString()
return new System.Text.StringBuilder("SessionState ")
.Append("[ Now=").Append(System.Environment.TickCount)
.Append(", HeartBtInt=").Append(this.HeartBtIntAsTickCount)
- .Append(", LastSentTime=").Append(this.LastSentTimeTickCount)
- .Append(", LastReceivedTime=").Append(this.LastReceivedTimeTickCount)
+ .Append(", LastSentTime=").Append(this.LastSentTimeDT.Ticks)
+ .Append(", LastReceivedTime=").Append(this.LastReceivedTimeDT.Ticks)
.Append(", TestRequestCounter=").Append(this.TestRequestCounter)
.Append(", WithinHeartbeat=").Append(WithinHeartbeat())
.Append(", NeedHeartbeat=").Append(NeedHeartbeat())
View
10 QuickFIX.NET/Transport/SocketInitiator.cs
@@ -43,7 +43,7 @@ public bool Connected
private Socket socket_ = null;
private byte[] _readBuffer = new byte[512];
private volatile bool shutdownRequested_ = false;
- private int lastConnectTickCount = 0;
+ private DateTime lastConnectTimeDT = DateTime.MinValue;
private int reconnectInterval_ = 30;
private SocketSettings socketSettings_ = new SocketSettings();
private Dictionary<SessionID, SocketInitiatorThread> threads_ = new Dictionary<SessionID, SocketInitiatorThread>();
@@ -159,13 +159,13 @@ protected override void OnStart()
while(!shutdownRequested_)
{
- int reconnectIntervalAsTicks = 1000 * reconnectInterval_;
- int nowTickCount = Environment.TickCount;
+ double reconnectIntervalAsTicks = 1000 * reconnectInterval_;
+ DateTime nowDT = DateTime.Now;
- if ((nowTickCount - lastConnectTickCount) >= reconnectIntervalAsTicks)
+ if ((nowDT.Subtract(lastConnectTimeDT).TotalMilliseconds) >= reconnectIntervalAsTicks)
{
Connect();
- lastConnectTickCount = nowTickCount;
+ lastConnectTimeDT = nowDT;
}
Thread.Sleep(1 * 1000);
Something went wrong with that request. Please try again.