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
)
81 get { return client; }
88 public PeerCred PeerCredential
{
91 return new PeerCred (client
);
95 public LingerOption LingerState
{
98 return (LingerOption
) client
.GetSocketOption (SocketOptionLevel
.Socket
,
99 SocketOptionName
.Linger
);
104 client
.SetSocketOption (SocketOptionLevel
.Socket
,
105 SocketOptionName
.Linger
, value);
109 public int ReceiveBufferSize
{
112 return (int) client
.GetSocketOption (SocketOptionLevel
.Socket
,
113 SocketOptionName
.ReceiveBuffer
);
118 client
.SetSocketOption (SocketOptionLevel
.Socket
,
119 SocketOptionName
.ReceiveBuffer
, value);
123 public int ReceiveTimeout
{
126 return (int) client
.GetSocketOption (SocketOptionLevel
.Socket
,
127 SocketOptionName
.ReceiveTimeout
);
132 client
.SetSocketOption (SocketOptionLevel
.Socket
,
133 SocketOptionName
.ReceiveTimeout
, value);
137 public int SendBufferSize
{
140 return (int) client
.GetSocketOption (SocketOptionLevel
.Socket
,
141 SocketOptionName
.SendBuffer
);
146 client
.SetSocketOption (SocketOptionLevel
.Socket
,
147 SocketOptionName
.SendBuffer
, value);
151 public int SendTimeout
{
154 return (int) client
.GetSocketOption (SocketOptionLevel
.Socket
,
155 SocketOptionName
.SendTimeout
);
160 client
.SetSocketOption (SocketOptionLevel
.Socket
,
161 SocketOptionName
.SendTimeout
, value);
171 public void Connect (UnixEndPoint remoteEndPoint
)
174 client
.Connect (remoteEndPoint
);
175 stream
= new NetworkStream (client
, true);
178 public void Connect (string path
)
181 Connect (new UnixEndPoint (path
));
184 public void Dispose ()
187 GC
.SuppressFinalize (this);
190 protected virtual void Dispose (bool disposing
)
196 // release managed resources
197 NetworkStream s
= stream
;
200 // This closes the socket as well, as the NetworkStream
204 } else if (client
!= null){
213 public NetworkStream
GetStream ()
217 stream
= new NetworkStream (client
, true);
222 void CheckDisposed ()
225 throw new ObjectDisposedException (GetType().FullName
);