This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
further expanded patch
- From: Tony Kimball <alk at pobox dot com>
- To: java-patches at gcc dot gnu dot org
- Date: Fri, 5 Jul 2002 10:22:04 -0500
- Subject: further expanded patch
- Reply-to: alk at pobox dot com
This further expansion of the previously submitted patch
completes the implementation of shutdownInput, shutdownOutput
for java.net.Socket.
As my test code is an application which uses these interfaces,
I am unable to supply that code directly. I shall add unit
tests to my todo list.
This is a complete ChangeLog:
* include/win32.sh
include io.h for getcwd et filia (mingw32 target support).
* java/lang/natRuntime.cc
fix misspelled preprocessor token.
* java/io/FileDescriptor.java
add native shutdownInput, shutdownOutput, setLength.
* java/io/RandomAccessFile.java
add setLength.
* java/io/natFileDescriptorEcos.cc
add empty implementation of native shutdownInput, shutdownOutput,
setLength.
* java/io/natFileDescriptorPosix.cc
add implementation of native shutdownInput, shutdownOutput,
setLength.
* java/io/natFileDescriptorWin32.cc
add implementation of native shutdownInput, shutdownOutput,
setLength.
* java/net/DatagramSocket.java
add connect, disconnect, getInetAddress, getPort.
* java/net/PlainSocketImpl.java
add shutdownInput, shutdownOutput.
* java/net/Socket.java
add shutdownInput, shutdownOutput.
* java/net/SocketImpl.java
add shutdownInput, shutdownOutput.
* java/net/URL.java
add getQuery.
* java/net/natPlainDatagramSocket.cc
previous inline definition of close conflicts with io.h
declarations -- changed to macro. Conditionalized multicast
operations.
* java/net/natPlainSocketImpl.cc
previous inline definition of close conflicts with io.h
declarations -- changed to macro.
I submit the patch as an attachment in an effort to avoid any MUA
formatting issues:
Index: include/win32.h
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/include/win32.h,v
retrieving revision 1.8
diff -r1.8 win32.h
17a18
> #include <io.h>
Index: java/lang/natRuntime.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/lang/natRuntime.cc,v
retrieving revision 1.23
diff -r1.23 natRuntime.cc
578c578
< else
---
> #else
cvs server: Diffing java/io
Index: java/io/FileDescriptor.java
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/io/FileDescriptor.java,v
retrieving revision 1.9
diff -r1.9 FileDescriptor.java
67a68,70
> native void shutdownInput () throws IOException;
> native void shutdownOutput () throws IOException;
> native void setLength (long pos) throws IOException;
Index: java/io/RandomAccessFile.java
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/io/RandomAccessFile.java,v
retrieving revision 1.6
diff -r1.6 RandomAccessFile.java
42a43,48
> public void setLength (long pos) throws IOException
> {
> fd.setLength(pos);
> return;
> }
>
Index: java/io/natFileDescriptorEcos.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/io/natFileDescriptorEcos.cc,v
retrieving revision 1.8
diff -r1.8 natFileDescriptorEcos.cc
97a98,112
> void
> java::io::FileDescriptor::shutdownInput (void)
> {
> }
>
> void
> java::io::FileDescriptor::shutdownOutput (void)
> {
> }
>
> void
> java::io::FileDescriptor::setLength (jlong pos)
> {
> }
>
Index: java/io/natFileDescriptorPosix.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/io/natFileDescriptorPosix.cc,v
retrieving revision 1.19
diff -r1.19 natFileDescriptorPosix.cc
19a20,21
> #include <sys/socket.h>
> #include <fcntl.h>
189a192,235
> }
>
> void
> java::io::FileDescriptor::shutdownInput (void)
> {
> if (::shutdown(fd,0))
> throw new IOException (JvNewStringLatin1 (strerror (errno)));
> }
>
> void
> java::io::FileDescriptor::shutdownOutput (void)
> {
> if (::shutdown(fd,1))
> throw new IOException (JvNewStringLatin1 (strerror (errno)));
> }
>
> void
> java::io::FileDescriptor::setLength (jlong pos)
> {
> struct stat sb;
> off_t orig;
>
> if (::fstat (fd, &sb))
> throw new IOException (JvNewStringLatin1 (strerror (errno)));
>
> if ((jlong)sb.st_size == pos)
> return;
>
> orig = ::lseek(fd, (off_t) 0, SEEK_CUR);
> if (orig == -1)
> throw new IOException (JvNewStringLatin1 (strerror (errno)));
>
> if ((jlong)sb.st_size < pos) {
> if (::lseek(fd, (off_t)pos, SEEK_SET) == -1)
> throw new IOException (JvNewStringLatin1 (strerror (errno)));
> if (::lseek(fd, orig, SEEK_SET) == -1)
> throw new IOException (JvNewStringLatin1 (strerror (errno)));
> return;
> }
>
> if (::ftruncate (fd, (off_t) pos))
> throw new IOException (JvNewStringLatin1 (strerror (errno)));
>
> return;
Index: java/io/natFileDescriptorWin32.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/io/natFileDescriptorWin32.cc,v
retrieving revision 1.9
diff -r1.9 natFileDescriptorWin32.cc
188a189,248
> void
> java::io::FileDescriptor::shutdownInput (void)
> {
> if (shutdown((SOCKET)fd,SD_RECEIVE) != 0)
> throw new IOException (JvNewStringLatin1 (winerr ()));
> }
>
> void
> java::io::FileDescriptor::shutdownOutput (void)
> {
> if (shutdown((SOCKET)fd,SD_SEND) != 0)
> throw new IOException (JvNewStringLatin1 (winerr ()));
> }
>
> void
> java::io::FileDescriptor::setLength(jlong pos)
> {
> LONG liOrigFilePointer;
> LONG liNewFilePointer;
> LONG liEndFilePointer;
>
> // get the original file pointer
> if (SetFilePointer((HANDLE)fd, (LONG)0, &liOrigFilePointer, FILE_CURRENT) != (BOOL)0
> && (GetLastError() != NO_ERROR))
> throw new IOException (JvNewStringLatin1 (winerr ()));
>
> // get the length of the file
> if (SetFilePointer((HANDLE)fd, (LONG)0, &liEndFilePointer, FILE_END) != (BOOL)0
> && (GetLastError() != NO_ERROR))
> throw new IOException (JvNewStringLatin1 (winerr ()));
>
> if ((jlong)liEndFilePointer == pos) {
> // restore the file pointer
> if (liOrigFilePointer != liEndFilePointer) {
> if (SetFilePointer((HANDLE)fd, liOrigFilePointer, &liNewFilePointer, FILE_BEGIN) != (BOOL)0
> && (GetLastError() != NO_ERROR))
> throw new IOException (JvNewStringLatin1 (winerr ()));
> }
> return;
> }
>
> // seek to the new end of file
> if (SetFilePointer((HANDLE)fd, (LONG)pos, &liNewFilePointer, FILE_BEGIN) != (BOOL)0
> && (GetLastError() != NO_ERROR))
> throw new IOException (JvNewStringLatin1 (winerr ()));
>
> // truncate the file at this point
> if (SetEndOfFile((HANDLE)fd) != (BOOL)0 && (GetLastError() != NO_ERROR))
> throw new IOException (JvNewStringLatin1 (winerr ()));
>
> if (liOrigFilePointer < liNewFilePointer) {
> // restore the file pointer
> if (SetFilePointer((HANDLE)fd, liOrigFilePointer, &liNewFilePointer, FILE_BEGIN) != (BOOL)0
> && (GetLastError() != NO_ERROR))
> throw new IOException (JvNewStringLatin1 (winerr ()));
> }
>
> return;
> }
>
cvs server: Diffing java/net
Index: java/net/DatagramSocket.java
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/net/DatagramSocket.java,v
retrieving revision 1.10
diff -r1.10 DatagramSocket.java
27a28,29
> InetAddress remoteAddr = null;
> int remotePort = -1;
131,134c133,140
< SecurityManager s = System.getSecurityManager();
< if (s != null)
< s.checkAccept(p.getAddress().getHostAddress(), p.getPort());
<
---
> if (p == null) {
> SecurityManager s = System.getSecurityManager();
> if (s != null)
> s.checkAccept(p.getAddress().getHostAddress(), p.getPort());
> } else if ((p.getPort() != remotePort || !p.getAddress().equals(remoteAddr))) {
> throw new IllegalArgumentException("Inconsistent packet address for connection to "
> +remoteAddr+" port "+remotePort);
> }
141,142c147,149
< SecurityManager s = System.getSecurityManager();
< if (s != null)
---
> if (p == null) {
> SecurityManager s = System.getSecurityManager();
> if (s != null)
148c155
< s.checkConnect(addr.getHostAddress(), p.getPort());
---
> s.checkConnect(addr.getHostAddress(), p.getPort());
150c157,160
<
---
> } else if ((p.getPort() != remotePort || !p.getAddress().equals(remoteAddr))) {
> throw new IllegalArgumentException("Inconsistent packet address for connection to "
> +remoteAddr+" port "+remotePort);
> }
163,191c173,219
< // JDK1.2
< // public void connect(InetAddress address, int port)
< // {
< // }
<
< // JDK1.2
< // public void disconnect()
< // {
< // }
<
< // JDK1.2
< // public InetAddress getInetAddress()
< // {
< // }
<
< // JDK1.2
< // public int getPort()
< // {
< // }
<
< /**
< * This method returns the value of the system level socket option
< * SO_RCVBUF, which is used by the operating system to tune buffer
< * sizes for data transfers.
< *
< * @return The receive buffer size.
< *
< * @exception SocketException If an error occurs.
< *
---
> public void connect(InetAddress address, int port) {
> synchronized (this) {
> SecurityManager s = System.getSecurityManager();
> if (s != null)
> {
> if (address.isMulticastAddress())
> s.checkMulticast(address);
> else
> s.checkConnect(address.getHostAddress(), port);
>
> remoteAddr = address;
> remotePort = port;
> if (remotePort < -1 || remotePort > 65535) {
> throw new IllegalArgumentException("bad remote parameters for local port "+
> impl.localPort);
> }
> }
> }
> }
>
> public void disconnect()
> {
> synchronized (this) {
> remotePort = -1;
> remoteAddr = null;
> }
> }
>
> public InetAddress getInetAddress()
> {
> return remoteAddr;
> }
>
> public int getPort()
> {
> return remotePort;
> }
>
> /**
> * This method returns the value of the system level socket option
> SO_RCVBUF, which is used by the operating system to tune buffer
> * sizes for data transfers.
> *
> @return The receive buffer size.
> *
> * @exception SocketException If an error occurs.
> *
Index: java/net/PlainSocketImpl.java
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/net/PlainSocketImpl.java,v
retrieving revision 1.10
diff -r1.10 PlainSocketImpl.java
51a52,53
> int shutdownMask = 0;
>
80a83,108
> /**
> * Closes the input side of the socket stream.
> *
> * @exception IOException If an error occurs.
> */
> public void shutdownInput() throws IOException
> {
> if (fd.valid())
> fd.shutdownInput();
> if (in != null)
> in.skip((long)in.available());
> shutdownMask = shutdownMask | SHUTDOWN_INPUT;
> }
>
> /**
> * Closes the output side of the socket stream.
> *
> * @exception IOException If an error occurs.
> */
> public void shutdownOutput() throws IOException
> {
> if (fd.valid())
> fd.shutdownOutput();
> shutdownMask = shutdownMask | SHUTDOWN_OUTPUT;
> }
>
126a155,156
> if ((shutdownMask & SHUTDOWN_INPUT) != 0)
> throw new IOException("Socket input stream is shut down");
135a166,167
> if ((shutdownMask & SHUTDOWN_OUTPUT) != 0)
> throw new IOException("Socket input stream is shut down");
Index: java/net/Socket.java
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/net/Socket.java,v
retrieving revision 1.9
diff -r1.9 Socket.java
631a632,654
> * Closes the input side of the socket stream.
> *
> * @exception IOException If an error occurs.
> */
> public void shutdownInput() throws IOException
> {
> if (impl != null)
> impl.shutdownInput();
> }
>
> /**
> * Closes the output side of the socket stream.
> *
> * @exception IOException If an error occurs.
> */
> public void shutdownOutput() throws IOException
> {
> if (impl != null)
> impl.shutdownOutput();
> }
>
>
> /**
Index: java/net/SocketImpl.java
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/net/SocketImpl.java,v
retrieving revision 1.8
diff -r1.8 SocketImpl.java
63a64,66
> final public static int SHUTDOWN_INPUT = 1;
> final public static int SHUTDOWN_OUTPUT = 2;
>
266a270,284
>
> /**
> * Closes the input side of the socket stream.
> *
> * @exception IOException If an error occurs.
> */
> protected abstract void shutdownInput() throws IOException;
>
> /**
> * Closes the output side of the socket stream.
> *
> * @exception IOException If an error occurs.
> */
> protected abstract void shutdownOutput() throws IOException;
>
Index: java/net/URL.java
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/net/URL.java,v
retrieving revision 1.10
diff -r1.10 URL.java
33a34,35
> private String query = null;
> private String path;
95a98,109
>
> int queryAt = file.lastIndexOf('?');
> if (queryAt < 0)
> {
> this.path = file;
> }
> else
> {
> this.path = file.substring(0, queryAt);
> this.query = file.substring(++queryAt);
> }
>
188a203,213
> int queryAt = file.lastIndexOf('?');
> if (queryAt < 0)
> {
> this.path = file;
> }
> else
> {
> this.path = file.substring(0, queryAt);
> this.query = file.substring(++queryAt);
> }
>
224,225c249,254
< int quest = file.indexOf('?');
< return quest < 0 ? file : file.substring(0, quest);
---
> return path;
> }
>
> public String getQuery()
> {
> return query;
Index: java/net/natPlainDatagramSocketImpl.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/net/natPlainDatagramSocketImpl.cc,v
retrieving revision 1.39
diff -r1.39 natPlainDatagramSocketImpl.cc
13a14
> #define NATIVE_CLOSE(s) closesocket(s);
19,25d19
<
< static inline int
< close(int s)
< {
< return closesocket(s);
< }
<
26a21
> #define NATIVE_CLOSE(s) close(s);
306c301
< ::close (fnum);
---
> (void)NATIVE_CLOSE(fnum);
412a408
> #ifdef IP_MULTICAST_TTL
420a417,419
> #else
> throw new java::io::IOException (JvNewStringUTF ("IP_MULTICAST_TTL unimplemented"));
> #endif
425a425
> #ifdef IP_MULTICAST_TTL
433a434,436
> #else
> throw new java::io::IOException (JvNewStringUTF ("IP_MULTICAST_TTL unimplemented"));
> #endif
560a564
> #ifdef IP_MULTICAST_IF
586c590,593
<
---
> #else
> throw
> new java::net::SocketException (JvNewStringUTF ("IP_MULTICAST_IF unimplemented"));
> #endif
676a684
> #ifdef IP_MULTICAST_IF
684a693,696
> #else
> throw new java::net::SocketException (
> JvNewStringUTF ("IP_MULTICAST_IF unimplemented"));
> #endif
Index: java/net/natPlainSocketImpl.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/net/natPlainSocketImpl.cc,v
retrieving revision 1.42
diff -r1.42 natPlainSocketImpl.cc
13a14
> #define NATIVE_CLOSE(s) closesocket(s);
23,29d23
< // These functions make the Win32 socket API look more POSIXy
< static inline int
< close(int s)
< {
< return closesocket(s);
< }
<
49c43
<
---
> #define NATIVE_CLOSE(s) close(s);
432c426
< int res = ::close (fnum);
---
> int res = NATIVE_CLOSE(fnum);