/***********************************************************************
*
* Copyright (C) 2005-2006 Novell, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* To contact Novell about this file by physical or electronic mail,
* you may find current contact information at www.novell.com.
*
***********************************************************************/
using System;
using System.IO;
using AppModule.InterProcessComm;
namespace AppModule.NamedPipes {
#region Comments
///
/// Used by server applications to communicate with client ones by using named pipes.
///
#endregion
public sealed class ServerPipeConnection : APipeConnection {
#region Comments
///
/// Disconnects a client named pipe.
///
///
/// When a client named pipe is disconnected, the server one is not closed.
/// The latter can later be reused by starting to listen again.
/// In a message oriented protocol the server will disconnect the client when the
/// response is sent and all the data is flushed. The same server named pipe
/// could then be reused by calling the
/// Connect method.
///
#endregion
public void Disconnect() {
CheckIfDisposed();
NamedPipeWrapper.Disconnect(this.Handle);
}
#region Comments
///
/// Closes the operating system native handle of the named pipe.
///
#endregion
public override void Close() {
CheckIfDisposed();
NamedPipeWrapper.Close(this.Handle);
}
#region Comments
///
/// Starts listening to client pipe connections.
///
///
/// This method will block the program execution until a client pipe attempts
/// to establish a connection.
/// When a client named pipe is disconnected, the server one is not closed.
/// The latter can later be reused by starting to listen again.
///
#endregion
public override void Connect() {
CheckIfDisposed();
NamedPipeWrapper.Connect(this.Handle);
}
#region Comments
///
/// Creates a ServerPipeConnection instance and the underlying operating system handle.
///
/// The name of the pipe.
/// The outbound buffer.
/// The inbound buffer.
/// The maximum bytes to read from clients.
#endregion
public ServerPipeConnection(string name, uint outBuffer, uint inBuffer, int maxReadBytes) {
this.Name = name;
this.Handle = NamedPipeWrapper.Create(name, outBuffer, inBuffer, true);
this.maxReadBytes = maxReadBytes;
}
#region Comments
///
/// Creates a ServerPipeConnection instance and the underlying operating system handle.
///
/// The name of the pipe.
/// The outbound buffer.
/// The inbound buffer.
/// Specifies whether the pipe is secure.
/// The maximum bytes to read from clients.
/// If the secure parameter is true the default security descriptor is used. The ACLs in the default security descriptor for a named pipe grant full control to the LocalSystem account, administrators, and the creator owner. They also grant read access to members of the Everyone group and the anonymous account.
///
/// If the secure parameter is false the method creates a security descriptor that grants full access to Everyone.
///
#endregion
public ServerPipeConnection(string name, uint outBuffer, uint inBuffer, int maxReadBytes, bool secure) {
this.Name = name;
this.Handle = NamedPipeWrapper.Create(name, outBuffer, inBuffer, secure);
this.maxReadBytes = maxReadBytes;
}
#region Comments
///
/// Object destructor.
///
#endregion
~ServerPipeConnection() {
Dispose(false);
}
}
}