Imported GNU Classpath 0.90
[official-gcc.git] / libjava / classpath / gnu / java / net / local / LocalSocket.java
blobb977d69c1bc9d2c152ec017a9fef908f49cf585f
1 /* LocalSocket.java -- a unix domain client socket.
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 This file is a part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or (at
9 your option) any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
19 USA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package gnu.java.net.local;
41 import java.io.IOException;
42 import java.io.InputStream;
43 import java.io.OutputStream;
45 import java.net.InetAddress;
46 import java.net.Socket;
47 import java.net.SocketAddress;
48 import java.net.SocketException;
49 import java.net.SocketImpl;
51 import java.nio.channels.IllegalBlockingModeException;
52 import java.nio.channels.SocketChannel;
54 /**
55 * A local, or unix-domain socket. Unix domain sockets are connected on the
56 * local filesystem itself, rather than a remote address.
58 public final class LocalSocket extends Socket
61 // Fields.
62 // -------------------------------------------------------------------------
64 private final LocalSocketImpl localimpl;
65 boolean localClosed;
66 boolean localConnected;
68 // Constructors.
69 // -------------------------------------------------------------------------
71 public LocalSocket () throws SocketException
73 super ();
74 localimpl = new LocalSocketImpl ();
77 public LocalSocket (LocalSocketAddress addr) throws SocketException
79 this ();
80 try
82 connect (addr);
84 catch (IOException ioe)
86 SocketException se = new SocketException ();
87 se.initCause (ioe);
88 throw se;
92 LocalSocket (boolean nocreate) throws IOException
94 super ();
95 localimpl = new LocalSocketImpl (nocreate);
98 // Instance methods.
99 // -------------------------------------------------------------------------
101 public void bind (SocketAddress bindpoint) throws IOException
103 throw new SocketException ("binding local client sockets is nonsensical");
106 public void connect (SocketAddress endpoint, int timeout) throws IOException
108 if (isClosed ())
110 throw new SocketException ("socket is closed");
112 if (! (endpoint instanceof LocalSocketAddress))
114 throw new IllegalArgumentException ("socket address is not a local address");
116 if (getChannel() != null && !getChannel().isBlocking())
118 throw new IllegalBlockingModeException ();
123 localimpl.doCreate ();
124 localimpl.localConnect ((LocalSocketAddress) endpoint);
126 catch (IOException ioe)
128 close ();
129 throw ioe;
131 localConnected = true;
134 public InetAddress getInetAddress ()
136 return null;
139 public InetAddress getLocalAddress ()
141 return null;
144 public int getPort ()
146 return -1;
149 public int getLocalPort ()
151 return -1;
154 public SocketChannel getChannel ()
156 return null;
159 public SocketAddress getLocalSocketAddress ()
161 return localimpl.getLocalAddress ();
164 public SocketAddress getRemoteSocketAddress ()
166 return localimpl.getRemoteAddress ();
169 public InputStream getInputStream () throws IOException
171 return localimpl.getInputStream ();
174 public OutputStream getOutputStream () throws IOException
176 return localimpl.getOutputStream ();
179 public void sendUrgentData (int b) throws IOException
181 localimpl.sendUrgentData (b);
184 public synchronized void close () throws IOException
186 localimpl.close ();
187 localClosed = true;
190 public void shutdownInput () throws IOException
192 localimpl.shutdownInput ();
195 public void shutdownOutput () throws IOException
197 localimpl.shutdownOutput ();
200 public boolean isClosed ()
202 return localClosed;
205 public boolean isBound ()
207 return false;
210 public boolean isConnected ()
212 return localConnected;
215 // Unsupported methods.
216 // -------------------------------------------------------------------------
218 public void setTcpNoDelay (boolean b) throws SocketException
220 throw new SocketException ("local sockets do not support this option");
223 public boolean getTcpNoDelay() throws SocketException
225 throw new SocketException ("local sockets do not support this option");
228 public void setSoLinger (boolean b, int i) throws SocketException
230 throw new SocketException ("local sockets do not support this option");
233 public int getSoLinger () throws SocketException
235 throw new SocketException ("local sockets do not support this option");
238 public void setOOBInline (boolean b) throws SocketException
240 throw new SocketException ("local sockets do not support this option");
243 public boolean getOOBInline () throws SocketException
245 throw new SocketException ("local sockets do not support this option");
248 public void setSoTimeout (int i) throws SocketException
250 throw new SocketException ("local sockets do not support this option");
253 public int getSoTimeout () throws SocketException
255 throw new SocketException ("local sockets do not support this option");
258 public void setSendBufferSize (int i) throws SocketException
260 throw new SocketException ("local sockets do not support this option");
263 public int getSendBufferSize() throws SocketException
265 throw new SocketException ("local sockets do not support this option");
268 public void setReceiveBufferSize (int i) throws SocketException
270 throw new SocketException ("local sockets do not support this option");
273 public int getReceiveBufferSize () throws SocketException
275 throw new SocketException ("local sockets do not support this option");
278 public void setKeepAlive (boolean b) throws SocketException
280 throw new SocketException ("local sockets do not support this option");
283 public boolean getKeepAlive () throws SocketException
285 throw new SocketException ("local sockets do not support this option");
288 public void setTrafficClass (int i) throws SocketException
290 throw new SocketException ("local sockets do not support this option");
293 public int getTrafficClass () throws SocketException
295 throw new SocketException ("local sockets do not support this option");
298 public void setReuseAddress (boolean b) throws SocketException
300 throw new SocketException ("local sockets do not support this option");
303 public boolean getReuseAddress () throws SocketException
305 throw new SocketException ("local sockets do not support this option");
308 LocalSocketImpl getLocalImpl ()
310 return localimpl;