5 // Joe Shaw (joeshaw@novell.com)
7 // Copyright (C) 2004-2005 Novell, Inc.
11 // Permission is hereby granted, free of charge, to any person obtaining a
12 // copy of this software and associated documentation files (the "Software"),
13 // to deal in the Software without restriction, including without limitation
14 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 // and/or sell copies of the Software, and to permit persons to whom the
16 // Software is furnished to do so, subject to the following conditions:
18 // The above copyright notice and this permission notice shall be included in
19 // all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 // DEALINGS IN THE SOFTWARE.
33 using System.Net.Sockets;
34 using System.Runtime.InteropServices;
38 public class UnixClient : MarshalByRefObject, IDisposable {
50 client = new Socket (AddressFamily.Unix, SocketType.Stream, 0);
53 public UnixClient (string path) : this ()
56 throw new ArgumentNullException ("ep");
61 public UnixClient (UnixEndPoint ep) : this ()
64 throw new ArgumentNullException ("ep");
69 // UnixListener uses this when accepting a connection.
70 internal UnixClient (Socket sock)
77 get { return client; }
84 public PeerCred PeerCredential {
87 return new PeerCred (client);
91 public LingerOption LingerState {
94 return (LingerOption) client.GetSocketOption (SocketOptionLevel.Socket,
95 SocketOptionName.Linger);
100 client.SetSocketOption (SocketOptionLevel.Socket,
101 SocketOptionName.Linger, value);
105 public int ReceiveBufferSize {
108 return (int) client.GetSocketOption (SocketOptionLevel.Socket,
109 SocketOptionName.ReceiveBuffer);
114 client.SetSocketOption (SocketOptionLevel.Socket,
115 SocketOptionName.ReceiveBuffer, value);
119 public int ReceiveTimeout {
122 return (int) client.GetSocketOption (SocketOptionLevel.Socket,
123 SocketOptionName.ReceiveTimeout);
128 client.SetSocketOption (SocketOptionLevel.Socket,
129 SocketOptionName.ReceiveTimeout, value);
133 public int SendBufferSize {
136 return (int) client.GetSocketOption (SocketOptionLevel.Socket,
137 SocketOptionName.SendBuffer);
142 client.SetSocketOption (SocketOptionLevel.Socket,
143 SocketOptionName.SendBuffer, value);
147 public int SendTimeout {
150 return (int) client.GetSocketOption (SocketOptionLevel.Socket,
151 SocketOptionName.SendTimeout);
156 client.SetSocketOption (SocketOptionLevel.Socket,
157 SocketOptionName.SendTimeout, value);
167 public void Connect (UnixEndPoint remoteEndPoint)
170 client.Connect (remoteEndPoint);
171 stream = new NetworkStream (client, true);
174 public void Connect (string path)
177 Connect (new UnixEndPoint (path));
180 public void Dispose ()
183 GC.SuppressFinalize (this);
186 protected virtual void Dispose (bool disposing)
192 // release managed resources
193 NetworkStream s = stream;
196 // This closes the socket as well, as the NetworkStream
200 } else if (client != null){
209 public NetworkStream GetStream ()
213 stream = new NetworkStream (client, true);
218 void CheckDisposed ()
221 throw new ObjectDisposedException (GetType().FullName);