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 namespace Beagle
.Util
{
40 public class UnixClient
: IDisposable
{
52 client
= new Socket (AddressFamily
.Unix
, SocketType
.Stream
, 0);
55 public UnixClient (string path
) : this ()
58 throw new ArgumentNullException ("ep");
63 public UnixClient (UnixEndPoint ep
) : this ()
66 throw new ArgumentNullException ("ep");
71 // UnixListener uses this when accepting a connection.
72 internal UnixClient (Socket sock
)
77 protected Socket Client
{
78 get { return client; }
85 public PeerCred PeerCredential
{
88 return new PeerCred (client
);
92 public LingerOption LingerState
{
95 return (LingerOption
) client
.GetSocketOption (SocketOptionLevel
.Socket
,
96 SocketOptionName
.Linger
);
101 client
.SetSocketOption (SocketOptionLevel
.Socket
,
102 SocketOptionName
.Linger
, value);
106 public int ReceiveBufferSize
{
109 return (int) client
.GetSocketOption (SocketOptionLevel
.Socket
,
110 SocketOptionName
.ReceiveBuffer
);
115 client
.SetSocketOption (SocketOptionLevel
.Socket
,
116 SocketOptionName
.ReceiveBuffer
, value);
120 public int ReceiveTimeout
{
123 return (int) client
.GetSocketOption (SocketOptionLevel
.Socket
,
124 SocketOptionName
.ReceiveTimeout
);
129 client
.SetSocketOption (SocketOptionLevel
.Socket
,
130 SocketOptionName
.ReceiveTimeout
, value);
134 public int SendBufferSize
{
137 return (int) client
.GetSocketOption (SocketOptionLevel
.Socket
,
138 SocketOptionName
.SendBuffer
);
143 client
.SetSocketOption (SocketOptionLevel
.Socket
,
144 SocketOptionName
.SendBuffer
, value);
148 public int SendTimeout
{
151 return (int) client
.GetSocketOption (SocketOptionLevel
.Socket
,
152 SocketOptionName
.SendTimeout
);
157 client
.SetSocketOption (SocketOptionLevel
.Socket
,
158 SocketOptionName
.SendTimeout
, value);
168 public void Connect (UnixEndPoint remoteEndPoint
)
171 client
.Connect (remoteEndPoint
);
172 stream
= new NetworkStream (client
, true);
175 public void Connect (string path
)
178 Connect (new UnixEndPoint (path
));
181 public void Dispose ()
184 GC
.SuppressFinalize (this);
187 protected virtual void Dispose (bool disposing
)
193 // release managed resources
194 NetworkStream s
= stream
;
197 // This closes the socket as well, as the NetworkStream
201 } else if (client
!= null){
210 public NetworkStream
GetStream ()
214 stream
= new NetworkStream (client
, true);
219 void CheckDisposed ()
222 throw new ObjectDisposedException (GetType().FullName
);