fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / libjava / java / nio / channels / SocketChannel.java
blobc22eb1d1945ea94e1104970095ff8bcd337bad20
1 /* SocketChannel.java --
2 Copyright (C) 2002 Free Software Foundation, Inc.
4 This file is 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, or (at your option)
9 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; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 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. */
38 package java.nio.channels;
40 import java.nio.channels.spi.AbstractSelectableChannel;
41 import java.nio.channels.spi.SelectorProvider;
42 import java.nio.ByteBuffer;
43 import java.io.IOException;
44 import java.net.Socket;
45 import java.net.SocketAddress;
47 /**
48 * @author Michael Koch
49 * @since 1.4
51 abstract public class SocketChannel extends AbstractSelectableChannel
52 implements ByteChannel, ScatteringByteChannel, GatheringByteChannel
54 /**
55 * Initializes this socket.
57 protected SocketChannel (SelectorProvider provider)
59 super (provider);
62 /**
63 * Opens a socket channel.
65 * @exception IOException If an error occurs
67 public static SocketChannel open () throws IOException
69 return SelectorProvider.provider ().openSocketChannel ();
72 /**
73 * Opens a channel and connects it to a remote address.
75 * @exception AsynchronousCloseException If this channel is already connected.
76 * @exception ClosedByInterruptException If another thread interrupts the
77 * current thread while the connect operation is in progress, thereby closing
78 * the channel and setting the current thread's interrupt status.
79 * @exception IOException If an error occurs
80 * @exception SecurityException If a security manager has been installed and
81 * it does not permit access to the given remote endpoint.
82 * @exception UnresolvedAddressException If the given remote address is not
83 * fully resolved.
84 * @exception UnsupportedAddressTypeException If the type of the given remote
85 * address is not supported.
87 public static SocketChannel open (SocketAddress remote) throws IOException
89 SocketChannel ch = open ();
91 if (ch.connect (remote))
95 return ch;
98 /**
99 * Reads data from the channel.
101 * @exception IOException If an error occurs
102 * @exception NotYetConnectedException If this channel is not yet connected.
104 public final long read (ByteBuffer[] dsts) throws IOException
106 long b = 0;
108 for (int i = 0; i < dsts.length; i++)
110 b += read (dsts [i]);
113 return b;
117 * Writes data to the channel.
119 * @exception IOException If an error occurs
120 * @exception NotYetConnectedException If this channel is not yet connected.
122 public final long write (ByteBuffer[] dsts) throws IOException
124 long b = 0;
126 for (int i= 0; i < dsts.length; i++)
128 b += write (dsts [i]);
131 return b;
135 * Retrieves the valid operations for this channel.
137 public final int validOps ()
139 return SelectionKey.OP_CONNECT | SelectionKey.OP_READ | SelectionKey.OP_WRITE;
143 * Reads data from the channel.
145 * @exception IOException If an error occurs
146 * @exception NotYetConnectedException If this channel is not yet connected.
148 public abstract int read (ByteBuffer dst) throws IOException;
151 * Connects the channel's socket to the remote address.
153 * @exception AlreadyConnectedException If this channel is already connected.
154 * @exception AsynchronousCloseException If this channel is already connected.
155 * @exception ClosedByInterruptException If another thread interrupts the
156 * current thread while the connect operation is in progress, thereby closing
157 * the channel and setting the current thread's interrupt status.
158 * @exception ClosedChannelException If this channel is closed.
159 * @exception ConnectionPendingException If a non-blocking connection
160 * operation is already in progress on this channel.
161 * @exception IOException If an error occurs
162 * @exception SecurityException If a security manager has been installed and
163 * it does not permit access to the given remote endpoint.
164 * @exception UnresolvedAddressException If the given remote address is not
165 * fully resolved.
166 * @exception UnsupportedAddressTypeException If the type of the given remote
167 * address is not supported.
169 public abstract boolean connect (SocketAddress remote) throws IOException;
172 * Finishes the process of connecting a socket channel.
174 * @exception AsynchronousCloseException If this channel is already connected.
175 * @exception ClosedByInterruptException If another thread interrupts the
176 * current thread while the connect operation is in progress, thereby closing
177 * the channel and setting the current thread's interrupt status.
178 * @exception ClosedChannelException If this channel is closed.
179 * @exception IOException If an error occurs
180 * @exception NoConnectionPendingException If this channel is not connected
181 * and a connection operation has not been initiated.
183 public abstract boolean finishConnect () throws IOException;
186 * Tells whether or not the channel's socket is connected.
188 public abstract boolean isConnected ();
191 * Tells whether or not a connection operation is in progress on this channel.
193 public abstract boolean isConnectionPending ();
196 * Reads data from the channel.
198 * @exception IOException If an error occurs
199 * @exception NotYetConnectedException If this channel is not yet connected.
201 public abstract long read (ByteBuffer[] dsts, int offset, int length)
202 throws IOException;
205 * Retrieves the channel's socket.
207 public abstract Socket socket ();
210 * Writes data to the channel.
212 * @exception IOException If an error occurs
213 * @exception NotYetConnectedException If this channel is not yet connected.
215 public abstract int write (ByteBuffer src) throws IOException;
218 * Writes data to the channel.
220 * @exception IOException If an error occurs
221 * @exception NotYetConnectedException If this channel is not yet connected.
223 public abstract long write (ByteBuffer[] srcs, int offset, int length)
224 throws IOException;