2008-03-05 09:52:00 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Microsoft Research Singularity
|
|
|
|
//
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
|
|
|
// Note: Simple ping-pong second child process
|
|
|
|
//
|
|
|
|
|
|
|
|
using Microsoft.SingSharp;
|
|
|
|
using Microsoft.SingSharp.Runtime;
|
|
|
|
using Microsoft.Singularity.Diagnostics.Contracts;
|
|
|
|
using Microsoft.Singularity.Channels;
|
|
|
|
using Microsoft.Singularity.Directory;
|
|
|
|
using Microsoft.Singularity.WebApps;
|
|
|
|
using Microsoft.Singularity.PingPong.Contracts;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace Microsoft.Singularity.Applications
|
|
|
|
{
|
|
|
|
public class CPong
|
|
|
|
{
|
|
|
|
public static int Main()
|
|
|
|
{
|
|
|
|
Endpoint * in ExHeap ep = Process.GetStartupEndpoint(0);
|
|
|
|
PongContract.Exp conn = ep as PongContract.Exp;
|
|
|
|
if (conn == null) {
|
|
|
|
delete ep;
|
|
|
|
Console.WriteLine("CPong : Missing PongContract endpoint.");
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
Console.WriteLine("CPong : Ready...");
|
|
|
|
conn.SendPongReady();
|
|
|
|
|
|
|
|
try {
|
2008-11-17 18:29:00 -05:00
|
|
|
while (true) {
|
2008-03-05 09:52:00 -05:00
|
|
|
switch receive {
|
|
|
|
case conn.Ping(int data):
|
|
|
|
Console.WriteLine("CPong : Ping({0}) to Pong...", data);
|
|
|
|
conn.SendPong(data + 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case conn.ChannelClosed():
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
delete conn;
|
|
|
|
}
|
|
|
|
Console.WriteLine("CPong : Exiting...");
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|