Skip to content

Commit

Permalink
Merge branch 'devel-1.64' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
akeshet committed Jul 18, 2012
2 parents cdeaab3 + 5a2c20d commit b8f87f9
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 25 deletions.
3 changes: 1 addition & 2 deletions AtticusServer/AtticusSplashForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions AtticusServer/AtticusSplashForm.cs
Expand Up @@ -26,9 +26,9 @@ private void timer1_Tick(object sender, EventArgs e)
this.Close();
}

public AtticusSplashForm(bool runTimer) : this()
public AtticusSplashForm(bool autoCloseAfterTimeout) : this()
{
this.timer1.Enabled = runTimer;
this.timer1.Enabled = autoCloseAfterTimeout;
}
}
}
8 changes: 7 additions & 1 deletion AtticusServer/ServerRuntime/AtticusServerCommunicator.cs
Expand Up @@ -209,7 +209,13 @@ public AtticusServerCommunicator(ServerSettings settings)
resetNetworkClocks();

DataStructures.Timing.NetworkClockProvider.registerStaticMessageLogHandler(this.messageLog);
DataStructures.Timing.NetworkClockProvider.startListener(DataStructures.Timing.NetworkClockEndpointInfo.HostTypes.Atticus_Server);
bool created = DataStructures.Timing.NetworkClockProvider.startListener(DataStructures.Timing.NetworkClockEndpointInfo.HostTypes.Atticus_Server);
if (!created)
{
messageLog(this, new MessageEvent("Unable to start network clock listener. Is it possible that a separate Atticus instance is running on this computer?",
0, MessageEvent.MessageTypes.Error, MessageEvent.MessageCategories.Networking));

}



Expand Down
69 changes: 56 additions & 13 deletions DataStructures/Timing/NetworkClockProvider.cs
Expand Up @@ -56,20 +56,46 @@ private static void staticLogMessage(MessageEvent e)
private static Dictionary<uint, NetworkClockProvider> providers = new Dictionary<uint,NetworkClockProvider>();
private static NetworkClockEndpointInfo.HostTypes myListenerType;

public static void startListener(NetworkClockEndpointInfo.HostTypes listenerType) {
/// <summary>
/// Returns true if successful, false otherwise.
/// </summary>
/// <param name="listenerType"></param>
/// <returns></returns>
public static bool startListener(NetworkClockEndpointInfo.HostTypes listenerType) {
lock (staticLockObj)
{
staticLogMessage(new MessageEvent("Starting network clock listener...", 0, MessageEvent.MessageTypes.Routine, MessageEvent.MessageCategories.SoftwareClock));
myListenerType = listenerType;

// Check if a listener thread is running already.
if (listenerThread != null)
{
throw new SoftwareClockProviderException("Attempted to start listener thread when already started.");
}


// Open a UDP socket
staticLogMessage(new MessageEvent("Opening UDP input socket for network clock.", 1, MessageEvent.MessageTypes.Log, MessageEvent.MessageCategories.Networking));
try
{
udpClient = new UdpClient(NetworkClockEndpointInfo.getListenerPort(myListenerType));
}
catch (System.Net.Sockets.SocketException e)
{
staticLogMessage(new MessageEvent("Unable to open input socket for network clock due to socket exception: " + e.Message,
0, MessageEvent.MessageTypes.Error, MessageEvent.MessageCategories.Networking));
udpClient = null;
return false;
}



listenerThread = new Thread(listenerThreadProc);
listenerThread.Start();
providers = new Dictionary<uint, NetworkClockProvider>();
staticLogMessage(new MessageEvent("...done", 0, MessageEvent.MessageTypes.Routine, MessageEvent.MessageCategories.SoftwareClock));

}
return true;
}

public static void shutDown()
Expand All @@ -79,11 +105,17 @@ public static void shutDown()
staticLogMessage(new MessageEvent("Shutting down network clock listener.", 0, MessageEvent.MessageTypes.Routine, MessageEvent.MessageCategories.SoftwareClock));
if (listenerThread == null)
{
throw new SoftwareClockProviderException("Attempted to stop a listener that was not running.");
//throw new SoftwareClockProviderException("Attempted to stop a listener that was not running.");
return;
}
listenerThread.Abort();
listenerThread = null;

if (udpClient != null)
{
udpClient.Close();
udpClient = null;
}

List<uint> providerIDs = providers.Keys.ToList();
foreach (uint id in providerIDs)
Expand All @@ -92,8 +124,6 @@ public static void shutDown()
}

providers = null;

staticLogMessage(new MessageEvent("...done"));
}
}

Expand All @@ -111,20 +141,33 @@ public static void registerStaticMessageLogHandler(EventHandler<MessageEvent> ha

private static UdpClient udpClient;



private static void listenerThreadProc()
{
lock (staticLockObj)
{
staticLogMessage(new MessageEvent("Starting Network Clock listener thread...", 1, MessageEvent.MessageTypes.Log, MessageEvent.MessageCategories.Networking));
udpClient = new UdpClient(NetworkClockEndpointInfo.getListenerPort(myListenerType));
staticLogMessage(new MessageEvent("...done", 1, MessageEvent.MessageTypes.Log, MessageEvent.MessageCategories.Networking));
}
staticLogMessage(new MessageEvent("Network Clock listener thread is alive", 1, MessageEvent.MessageTypes.Log, MessageEvent.MessageCategories.Networking));


while (true)
{
// Wait for a datagram from the udpClient.
// This makes use of a temporary local reference to udpClient so that we can be sure
// that even if the static udpClient member is changed when we don't hold the static lock
// we will at least run the callback on the correct instance of udpClient.
// (I didn't want to lock the receive callback on staticLockObj, because the callback may
// take arbitrarily long to return, and I don't want to be locked out of other static activities like
// shutting down the listener.

System.Net.IPEndPoint remoteEnd = null;
IAsyncResult result = udpClient.BeginReceive(null, null);
byte[] received = udpClient.EndReceive(result, ref remoteEnd);
IAsyncResult result;
byte[] received;
UdpClient udpClientNonstatic;
lock (staticLockObj)
{
udpClientNonstatic = udpClient;
result = udpClient.BeginReceive(null, null);
}
received = udpClientNonstatic.EndReceive(result, ref remoteEnd);

if (received.Length != NetworkClockDatagram.datagramByteLength)
{
Expand Down
3 changes: 1 addition & 2 deletions WordGenerator/Controls/Dialogs/CiceroSplashForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions WordGenerator/Controls/Dialogs/CiceroSplashForm.cs
Expand Up @@ -34,10 +34,10 @@ private void timer1_Tick(object sender, EventArgs e)
this.Close();
}

public CiceroSplashForm(bool runTimer)
public CiceroSplashForm(bool autoCloseAfterTimeout)
: this()
{
this.timer1.Enabled = runTimer;
this.timer1.Enabled = autoCloseAfterTimeout;
}


Expand Down
12 changes: 9 additions & 3 deletions WordGenerator/Controls/MainClientForm.cs
Expand Up @@ -245,9 +245,7 @@ public MainClientForm(RunLog runLog)
debugToolStripMenuItem.Visible = true;
#endif

CiceroSplashForm splash = new CiceroSplashForm();

splash.Show();

if (hotKeyBindings == null)
hotKeyBindings = new List<object>();
Expand Down Expand Up @@ -593,9 +591,17 @@ private void mainClientForm_Load(object sender, EventArgs e)
this.WindowState = FormWindowState.Maximized;
formOpen = true;
DataStructures.Timing.NetworkClockProvider.registerStaticMessageLogHandler(addMessageLogText);
DataStructures.Timing.NetworkClockProvider.startListener(DataStructures.Timing.NetworkClockEndpointInfo.HostTypes.Cicero_Client);
bool listenerCreated =
DataStructures.Timing.NetworkClockProvider.startListener(DataStructures.Timing.NetworkClockEndpointInfo.HostTypes.Cicero_Client);
if (!listenerCreated)
{
MessageBox.Show("Unable to start network clock listener. Is it possible that a separate Cicero instance is running on this computer?", "Unable to create clock listener.");
}
/* CiceroSplashForm splash = new CiceroSplashForm();
splash.Show();*/
CiceroSplashForm splash = new CiceroSplashForm();

splash.ShowDialog();
}

protected override bool IsInputChar(char charCode)
Expand Down

0 comments on commit b8f87f9

Please sign in to comment.