Beispiel #1
0
    static void ReadCallback(IAsyncResult ar)
    {
        PipeState    state  = (PipeState)ar.AsyncState;
        MyPipeClient client = state.Client;

        client.LastRead = DateTime.Now;
        int bytesRead;

        try
        {
            bytesRead = client.PipeClient.EndRead(ar);
        }
        catch (IOException)     //closed
        {
            return;
        }
        if (bytesRead > 0)
        {
            byte[] data = state.Buffer;
            //TODO: something
        }
        else     //i've never used pipes, so i'm assuming this behavior exists with them
        {
            client.Disconnect();
            return;
        }
        Read(client);
    }
Beispiel #2
0
    static void TimeoutCheck(object state)
    {
        MyPipeClient client            = (MyPipeClient)state;
        TimeSpan     timeSinceLastRead = DateTime.Now - client.LastRead;

        if (timeSinceLastRead.TotalSeconds > TimeoutSeconds)
        {
            client.Disconnect();
        }
    }
Beispiel #3
0
    static void Read(MyPipeClient client)
    {
        PipeState state = new PipeState(client);

        try
        {
            client.PipeClient.BeginRead(state.Buffer, 0, state.Buffer.Length, ReadCallback, state);
        }
        catch (InvalidOperationException)     //disconnected/disposed
        {
            return;
        }
    }
Beispiel #4
0
 public PipeState(MyPipeClient client)
 {
     Client = client;
 }