Exemplo n.º 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);
    }
Exemplo n.º 2
0
    static void TimeoutCheck(object state)
    {
        MyPipeClient client            = (MyPipeClient)state;
        TimeSpan     timeSinceLastRead = DateTime.Now - client.LastRead;

        if (timeSinceLastRead.TotalSeconds > TimeoutSeconds)
        {
            client.Disconnect();
        }
    }
Exemplo n.º 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;
        }
    }
Exemplo n.º 4
0
 public PipeState(MyPipeClient client)
 {
     Client = client;
 }