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
)
75 protected Socket Client
{
76 get { return client; }
83 public PeerCred PeerCredential
{
86 return new PeerCred (client
);
90 public LingerOption LingerState
{
93 return (LingerOption
) client
.GetSocketOption (SocketOptionLevel
.Socket
,
94 SocketOptionName
.Linger
);
99 client
.SetSocketOption (SocketOptionLevel
.Socket
,
100 SocketOptionName
.Linger
, value);
104 public int ReceiveBufferSize
{
107 return (int) client
.GetSocketOption (SocketOptionLevel
.Socket
,
108 SocketOptionName
.ReceiveBuffer
);
113 client
.SetSocketOption (SocketOptionLevel
.Socket
,
114 SocketOptionName
.ReceiveBuffer
, value);
118 public int ReceiveTimeout
{
121 return (int) client
.GetSocketOption (SocketOptionLevel
.Socket
,
122 SocketOptionName
.ReceiveTimeout
);
127 client
.SetSocketOption (SocketOptionLevel
.Socket
,
128 SocketOptionName
.ReceiveTimeout
, value);
132 public int SendBufferSize
{
135 return (int) client
.GetSocketOption (SocketOptionLevel
.Socket
,
136 SocketOptionName
.SendBuffer
);
141 client
.SetSocketOption (SocketOptionLevel
.Socket
,
142 SocketOptionName
.SendBuffer
, value);
146 public int SendTimeout
{
149 return (int) client
.GetSocketOption (SocketOptionLevel
.Socket
,
150 SocketOptionName
.SendTimeout
);
155 client
.SetSocketOption (SocketOptionLevel
.Socket
,
156 SocketOptionName
.SendTimeout
, value);
166 public void Connect (UnixEndPoint remoteEndPoint
)
169 client
.Connect (remoteEndPoint
);
170 stream
= new NetworkStream (client
, true);
173 public void Connect (string path
)
176 Connect (new UnixEndPoint (path
));
179 public void Dispose ()
182 GC
.SuppressFinalize (this);
185 protected virtual void Dispose (bool disposing
)
191 // release managed resources
192 NetworkStream s
= stream
;
195 // This closes the socket as well, as the NetworkStream
199 } else if (client
!= null){
208 public NetworkStream
GetStream ()
212 stream
= new NetworkStream (client
, true);
217 void CheckDisposed ()
220 throw new ObjectDisposedException (GetType().FullName
);