Author: qiuxx
Date: Wed Apr 8 05:58:58 2009
New Revision: 763114
URL: http://svn.apache.org/viewvc?rev=763114&view=rev
Log:
Merge updates from classlib trunk@761593 since r755805
Added:
harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainServerSocketImpl.java
- copied unchanged from r761593, harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainServerSocketImpl.java
Modified:
harmony/enhanced/classlib/branches/java6/modules/archive/src/main/java/java/util/jar/Manifest.java
harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/net/ServerSocket.java
harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamExposer.java
harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/OSNetworkSystem.c
harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/OSNetworkSystem.h
harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/exports.txt
harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c
harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/ServerSocketTest.java
harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/windows/hyfile.c
Modified: harmony/enhanced/classlib/branches/java6/modules/archive/src/main/java/java/util/jar/Manifest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/archive/src/main/java/java/util/jar/Manifest.java?rev=763114&r1=763113&r2=763114&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/archive/src/main/java/java/util/jar/Manifest.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/archive/src/main/java/java/util/jar/Manifest.java
Wed Apr 8 05:58:58 2009
@@ -17,6 +17,7 @@
package java.util.jar;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -204,10 +205,15 @@
*/
public void read(InputStream is) throws IOException {
byte[] buf;
+ // Try to read get a reference to the bytes directly
try {
buf = InputStreamExposer.expose(is);
- } catch (OutOfMemoryError oome) {
- throw new IOException(Messages.getString("archive.2E")); //$NON-NLS-1$
+ } catch (UnsupportedOperationException uoe) {
+ buf = readFully(is);
+ }
+
+ if (buf.length == 0) {
+ return;
}
// a workaround for HARMONY-5662
@@ -226,7 +232,45 @@
im.initEntries(entries, chunks);
im = null;
}
+
+ /*
+ * Helper to read the entire contents of the manifest from the
+ * given input stream. Usually we can do this in a single read
+ * but we need to account for 'infinite' streams, by ensuring we
+ * have a line feed within a reasonable number of characters.
+ */
+ private byte[] readFully(InputStream is) throws IOException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ byte[] buffer = new byte[8192];
+ while (true) {
+ int count = is.read(buffer);
+ if (count == -1) {
+ // TODO: Do we need to copy this, or can we live with junk at the end?
+ return baos.toByteArray();
+ }
+ baos.write(buffer, 0, count);
+
+ if (!containsLine(buffer, count)) {
+ throw new IOException(Messages.getString("archive.2E")); //$NON-NLS-1$
+ }
+ }
+ }
+
+ /*
+ * Check to see if the buffer contains a newline or carriage
+ * return character within the first 'length' bytes. Used to
+ * check the validity of the manifest input stream.
+ */
+ private boolean containsLine(byte[] buffer, int length) {
+ for (int i = 0; i < length; i++) {
+ if (buffer[i] == 0x0A || buffer[i] == 0x0D) {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* Returns the hashCode for this instance.
*
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/net/ServerSocket.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/net/ServerSocket.java?rev=763114&r1=763113&r2=763114&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/net/ServerSocket.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/net/ServerSocket.java
Wed Apr 8 05:58:58 2009
@@ -20,7 +20,7 @@
import java.io.IOException;
import java.nio.channels.ServerSocketChannel;
-import org.apache.harmony.luni.net.PlainSocketImpl;
+import org.apache.harmony.luni.net.PlainServerSocketImpl;
import org.apache.harmony.luni.platform.Platform;
import org.apache.harmony.luni.util.Msg;
@@ -56,7 +56,7 @@
*/
public ServerSocket() throws IOException {
impl = factory != null ? factory.createSocketImpl()
- : new PlainSocketImpl();
+ : new PlainServerSocketImpl();
}
protected ServerSocket(SocketImpl impl) {
@@ -109,7 +109,7 @@
super();
checkListen(aport);
impl = factory != null ? factory.createSocketImpl()
- : new PlainSocketImpl();
+ : new PlainServerSocketImpl();
InetAddress addr = localAddr == null ? InetAddress.ANY : localAddr;
synchronized (this) {
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java?rev=763114&r1=763113&r2=763114&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
Wed Apr 8 05:58:58 2009
@@ -134,9 +134,12 @@
SocketImpl newSocket, FileDescriptor fdnewSocket, int timeout)
throws IOException;
- public void createStreamSocket(FileDescriptor aFD, boolean preferIPv4Stack)
- throws SocketException;
+ public void createServerStreamSocket(FileDescriptor aFD, boolean preferIPv4Stack)
+ throws SocketException;
+ public void createStreamSocket(FileDescriptor aFD, boolean preferIPv4Stack)
+ throws SocketException;
+
public void listenStreamSocket(FileDescriptor aFD, int backlog)
throws SocketException;
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java?rev=763114&r1=763113&r2=763114&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
Wed Apr 8 05:58:58 2009
@@ -94,6 +94,9 @@
public native void createDatagramSocket(FileDescriptor fd,
boolean preferIPv4Stack) throws SocketException;
+ public native void createServerStreamSocket(FileDescriptor fd,
+ boolean preferIPv4Stack) throws SocketException;
+
public native void createStreamSocket(FileDescriptor fd,
boolean preferIPv4Stack) throws SocketException;
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamExposer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamExposer.java?rev=763114&r1=763113&r2=763114&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamExposer.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamExposer.java
Wed Apr 8 05:58:58 2009
@@ -99,8 +99,9 @@
* @param is
* the stream to be read.
* @return the snapshot wrapping the buffer where the bytes are read to.
+ * @throws UnsupportedOperationException if the input stream data cannot be exposed
*/
- public static byte[] expose(InputStream is) throws IOException {
+ public static byte[] expose(InputStream is) throws IOException, UnsupportedOperationException
{
if (is instanceof ExposedByteArrayInputStream) {
return ((ExposedByteArrayInputStream) is).expose();
}
@@ -109,17 +110,7 @@
return expose((ByteArrayInputStream) is);
}
- // this may be slow, put optimizations suitable for your stream
- // before trying this
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- byte[] buffer = new byte[8192];
-
- while (true) {
- int count = is.read(buffer);
- if (count == -1) {
- return baos.toByteArray();
- }
- baos.write(buffer, 0, count);
- }
+ // We don't know how to do this
+ throw new UnsupportedOperationException();
}
}
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/OSNetworkSystem.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/OSNetworkSystem.c?rev=763114&r1=763113&r2=763114&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/OSNetworkSystem.c
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/OSNetworkSystem.c
Wed Apr 8 05:58:58 2009
@@ -371,6 +371,10 @@
I_32 result, localCount;
hysocketP = getJavaIoFileDescriptorContentsAsAPointer(env, fd);
+ if (!hysock_socketIsValid(hysocketP)) {
+ throwJavaNetSocketException(env, HYPORT_ERROR_SOCKET_BADSOCKET);
+ return (jint) 0;
+ }
/* A non-zero timeout will first check, and potentially wait, to see if any
* bytes are available
@@ -448,6 +452,10 @@
I_32 result;
hysocket_t socketP = getJavaIoFileDescriptorContentsAsAPointer(env, fd);
+ if (!hysock_socketIsValid(socketP)) {
+ throwJavaNetSocketException(env, HYPORT_ERROR_SOCKET_BADSOCKET);
+ return (jint) 0;
+ }
result = hysock_write(socketP, (U_8 *) message, (I_32) count, HYSOCK_NOFLAGS);
if (0 > result) {
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/OSNetworkSystem.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/OSNetworkSystem.h?rev=763114&r1=763113&r2=763114&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/OSNetworkSystem.h
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/OSNetworkSystem.h
Wed Apr 8 05:58:58 2009
@@ -145,6 +145,15 @@
/*
* Class: org.apache.harmony.luni.platform.OSNetworkSystem
+ * Method: createServerStreamSocket
+ * Signature: (Ljava/io/FileDescriptor;Z)V
+ * Throws: java.net.SocketException
+ */
+JNIEXPORT void JNICALL Java_org_apache_harmony_luni_platform_OSNetworkSystem_createServerStreamSocket
+ (JNIEnv *, jobject, jobject, jboolean);
+
+/*
+ * Class: org.apache.harmony.luni.platform.OSNetworkSystem
* Method: createStreamSocket
* Signature: (Ljava/io/FileDescriptor;Z)V
* Throws: java.net.SocketException
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c?rev=763114&r1=763113&r2=763114&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
Wed Apr 8 05:58:58 2009
@@ -39,7 +39,9 @@
#include "nethelp.h"
#include "harmonyglob.h"
+#include "helpers.h"
#include "hysock.h"
+#include "socket.h"
#include "hyport.h"
#include "jni.h"
#include "OSNetworkSystem.h"
@@ -69,7 +71,9 @@
my_pollfd.fd = hysocketP->sock;
my_pollfd.events = POLLIN | POLLPRI;
my_pollfd.revents = 0;
- result = poll (&my_pollfd, 1, timeout);
+ do {
+ result = poll (&my_pollfd, 1, timeout);
+ } while (result == -1 && errno == EINTR);
if (result == 0)
return HYPORT_ERROR_SOCKET_TIMEOUT;
@@ -80,6 +84,29 @@
return result;
}
+
+/*
+ * Class: org_apache_harmony_luni_platform_OSNetworkSystem
+ * Method: createServerStreamSocket
+ * Signature: (Ljava/io/FileDescriptor;Z)V
+ */
+JNIEXPORT void JNICALL
+Java_org_apache_harmony_luni_platform_OSNetworkSystem_createServerStreamSocket
+ (JNIEnv * env, jobject thiz, jobject thisObjFD, jboolean preferIPv4Stack)
+{
+ PORT_ACCESS_FROM_ENV (env);
+ hysocket_t socketP;
+ BOOLEAN value = TRUE;
+
+ createSocket(env, thisObjFD, HYSOCK_STREAM, preferIPv4Stack);
+
+ /* Also sets HY_SO_REUSEADDR = TRUE on Linux only */
+ socketP =
+ (hysocket_t) getJavaIoFileDescriptorContentsAsAPointer(env, thisObjFD);
+ hysock_setopt_bool (socketP, HY_SOL_SOCKET, HY_SO_REUSEADDR, &value);
+}
+
+
JNIEXPORT jint JNICALL
Java_org_apache_harmony_luni_platform_OSNetworkSystem_isReachableByICMPImpl
(JNIEnv * env, jobject thiz, jobject address, jobject localaddr, jint ttl, jint timeout)
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/exports.txt
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/exports.txt?rev=763114&r1=763113&r2=763114&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/exports.txt
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/exports.txt
Wed Apr 8 05:58:58 2009
@@ -231,6 +231,7 @@
Java_org_apache_harmony_luni_platform_OSNetworkSystem_shutdownInput
Java_org_apache_harmony_luni_platform_OSNetworkSystem_shutdownOutput
Java_org_apache_harmony_luni_platform_OSNetworkSystem_acceptStreamSocket
+Java_org_apache_harmony_luni_platform_OSNetworkSystem_createServerStreamSocket
Java_org_apache_harmony_luni_platform_OSNetworkSystem_createStreamSocket
Java_org_apache_harmony_luni_platform_OSNetworkSystem_sendDatagram2
Java_org_apache_harmony_luni_platform_OSNetworkSystem_selectImpl
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c?rev=763114&r1=763113&r2=763114&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c
Wed Apr 8 05:58:58 2009
@@ -32,6 +32,19 @@
/*
* Class: org_apache_harmony_luni_platform_OSNetworkSystem
+ * Method: createServerStreamSocket
+ * Signature: (Ljava/io/FileDescriptor;Z)V
+ */
+JNIEXPORT void JNICALL
+Java_org_apache_harmony_luni_platform_OSNetworkSystem_createServerStreamSocket
+ (JNIEnv * env, jobject thiz, jobject thisObjFD, jboolean preferIPv4Stack)
+{
+ createSocket(env, thisObjFD, HYSOCK_STREAM, preferIPv4Stack);
+}
+
+
+/*
+ * Class: org_apache_harmony_luni_platform_OSNetworkSystem
* Method: selectImpl
* Signature: ([Ljava/io/FileDescriptor;[Ljava/io/FileDescriptor;II[IJ)I
*/
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/ServerSocketTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/ServerSocketTest.java?rev=763114&r1=763113&r2=763114&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/ServerSocketTest.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/ServerSocketTest.java
Wed Apr 8 05:58:58 2009
@@ -35,7 +35,7 @@
import java.util.Date;
import java.util.Properties;
-import org.apache.harmony.luni.net.PlainSocketImpl;
+import org.apache.harmony.luni.net.PlainServerSocketImpl;
import tests.support.Support_Configuration;
import tests.support.Support_Exec;
@@ -333,7 +333,7 @@
private static class MockSocketImplFactory implements SocketImplFactory {
public SocketImpl createSocketImpl() {
- return new PlainSocketImpl();
+ return new PlainServerSocketImpl();
}
}
Modified: harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/windows/hyfile.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/windows/hyfile.c?rev=763114&r1=763113&r2=763114&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/windows/hyfile.c
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/windows/hyfile.c
Wed Apr 8 05:58:58 2009
@@ -405,7 +405,6 @@
{
int len;
int wlen;
- int absLen;
char *canonicalpath;
int srcArrayCount=0;
int destArrayCount=0;
@@ -414,10 +413,8 @@
int *slashStack; //record position of every separator.
// Buffer to store absolute path name.
- wchar_t *absPath = 0;
- wchar_t *temp = 0;
- int i = 0;
-
+ char absPath[ABS_PATH_BUF_LEN];
+
if (!path) {
*pathW = (void*) 0;
return;
@@ -431,7 +428,15 @@
return;
}
- len = strlen(path);
+ // calculate an absolute path first
+ if (!GetFullPathNameA(path, ABS_PATH_BUF_LEN, absPath, (void*) 0))
+ {
+ // error occurred
+ *pathW = (void*) 0;
+ return;
+ }
+
+ len = strlen(absPath);
slashStack = portLibrary->mem_allocate_memory(portLibrary, len*sizeof(int));
canonicalpath = portLibrary->mem_allocate_memory(portLibrary, len+5);
@@ -440,15 +445,15 @@
for(srcArrayCount=0,destArrayCount=4;srcArrayCount<len;srcArrayCount++){
// we have an absolute path already.
- if(path[srcArrayCount]=='.'){
+ if(absPath[srcArrayCount]=='.'){
// count the dots following last separator.
- if(dotsCount>0 || path[srcArrayCount-1]=='\\'){
+ if(dotsCount>0 || absPath[srcArrayCount-1]=='\\'){
dotsCount++;
continue;
}
}
// deal with the dots when we meet next separator.
- if(path[srcArrayCount]=='\\'){
+ if(absPath[srcArrayCount]=='\\'){
if(dotsCount == 1){
dotsCount = 0;
continue;
@@ -471,40 +476,17 @@
canonicalpath[destArrayCount++]='.';
dotsCount--;
}
- canonicalpath[destArrayCount++]=path[srcArrayCount];
+ canonicalpath[destArrayCount++]=absPath[srcArrayCount];
}
while(canonicalpath[destArrayCount-1] == '.'){
destArrayCount--;
}
canonicalpath[destArrayCount]='\0';
-
wlen = MultiByteToWideChar(CP_UTF8, 0, canonicalpath, -1, *pathW, 0);
*pathW = portLibrary->mem_allocate_memory(portLibrary, wlen*sizeof(wchar_t));
MultiByteToWideChar(CP_UTF8, 0, canonicalpath, -1, *pathW, wlen);
portLibrary->mem_free_memory(portLibrary, canonicalpath);
portLibrary->mem_free_memory(portLibrary, slashStack);
-
- // calculate an absolute path
- // call unicode version explicitly, should not include "\\?\" prefix
- absLen = GetFullPathNameW(*pathW + 4, 0, absPath, (void*) 0);
- absPath = portLibrary->mem_allocate_memory(portLibrary, (absLen + 4)*sizeof(wchar_t));
- absLen = GetFullPathNameW(*pathW + 4, absLen, absPath + 4, (void*) 0);
-
- if (absLen == 0)
- {
- // error occurred
- *pathW = (void*) 0;
- return;
- }
- // add prefix "\\?\"
- for (i = 0; i < 4; ++i) {
- absPath[i] = (*pathW)[i];
- }
-
- temp = *pathW;
- *pathW = absPath;
- absPath = temp;
- portLibrary->mem_free_memory(portLibrary, absPath);
}
#undef ABS_PATH_BUF_LEN
@@ -526,6 +508,7 @@
{
int returnVar=0;
wchar_t *pathW;
+
convert_path_to_unicode(portLibrary, path, &pathW);
returnVar = CreateDirectoryW (pathW, 0);
portLibrary->mem_free_memory(portLibrary, pathW);
|