Author: mturk Date: Thu Aug 11 11:58:24 2011 New Revision: 1156582 URL: http://svn.apache.org/viewvc?rev=1156582&view=rev Log: Do not alloc separate overlapped struct
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h commons/sandbox/runtime/trunk/src/main/native/os/win32/sendfile.c commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestLocalEndpoint.java Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h?rev=1156582&r1=1156581&r2=1156582&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h Thu Aug 11 11:58:24 2011 @@ -98,7 +98,7 @@ struct acr_sf_t { #else acr_off_t off; acr_off_t size; - LPOVERLAPPED pob; /**< For TransmitFile */ + OVERLAPPED ob; #endif }; Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/sendfile.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/sendfile.c?rev=1156582&r1=1156581&r2=1156582&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/sendfile.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/sendfile.c Thu Aug 11 11:58:24 2011 @@ -27,7 +27,7 @@ #include "arch_opts.h" #include "arch_sync.h" -ACR_NET_EXPORT(jlong, SendFile, open0)(JNI_STDARGS, jstring fname) +ACR_NET_EXPORT(jlong, Sendfile, open0)(JNI_STDARGS, jstring fname) { int rc = 0; acr_sf_t *sf; @@ -58,26 +58,17 @@ ACR_NET_EXPORT(jlong, SendFile, open0)(J ACR_THROW_NET_ERROR(rc); return 0; } - sf->pob = ACR_TALLOC(OVERLAPPED); - if (sf->pob != 0) { - sf->pob->hEvent = CreateEvent(0, FALSE, FALSE, 0); - return P2J(sf); - } - else { - CloseHandle(sf->fh); - AcrFree(sf); - return 0; - } + sf->ob.hEvent = CreateEvent(0, FALSE, FALSE, 0); + return P2J(sf); } -ACR_NET_EXPORT(jint, SendFile, close0)(JNI_STDARGS, jlong fp) +ACR_NET_EXPORT(jint, Senfile, close0)(JNI_STDARGS, jlong fp) { int rc = 0; acr_sf_t *sf = J2P(fp, acr_sf_t *); CloseHandle(sf->fh); - CloseHandle(sf->pob->hEvent); - AcrFree(sf->pob); + CloseHandle(sf->ob.hEvent); AcrFree(sf); return rc; } @@ -132,30 +123,30 @@ ACR_NET_EXPORT(jint, Sendfile, send0)(JN AcrSdRelease(sd); return -1; } - sf->pob->Offset = (DWORD)(sf->off); - sf->pob->OffsetHigh = (DWORD)(sf->off >> 32); + sf->ob.Offset = (DWORD)(sf->off); + sf->ob.OffsetHigh = (DWORD)(sf->off >> 32); while (tosend > 0) { if (tosend > MAX_SEGMENT_SIZE) cnt = MAX_SEGMENT_SIZE; else - cnt = (DWORD)tosend; /* Last call to TransmitFile() */ - /* XXX: MSDN says that it should be obtained by WSAIoctl - * but it seems this works just fine as it is. + cnt = (DWORD)tosend; + /* XXX: MSDN says that TransmitFile should be obtained via WSAIoctl, + * but it seems this works just fine without it. */ if (!(*winsock->TransmitFile)(sock, /* socket */ sf->fh, /* file descriptor of the file to be sent */ cnt, /* number of bytes to send. 0=send all */ 0, /* Number of bytes per send. 0=use default */ - sf->pob, /* OVERLAPPED structure */ + &sf->ob, /* OVERLAPPED structure */ 0, /* header and trailer buffers */ dwFlags)) { /* flags to control various aspects of TransmitFile */ rc = WSAGetLastError(); if (rc == ERROR_IO_PENDING || rc == WSA_IO_PENDING) { - DWORD ws = WaitForSingleObject(sf->pob->hEvent, sd->timeout); + DWORD ws = WaitForSingleObject(sf->ob.hEvent, sd->timeout); if (ws == WAIT_OBJECT_0) { rc = 0; if (!WSAGetOverlappedResult(sock, - sf->pob->hEvent, + &sf->ob, &cnt, FALSE, &dwFlags)) @@ -174,7 +165,7 @@ ACR_NET_EXPORT(jint, Sendfile, send0)(JN xmitted += cnt; } finally: - if (rc != 0) { + if (rc != 0 && xmitted == 0) { xmitted = -1; ACR_THROW_NET_ERROR(rc); } Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestLocalEndpoint.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestLocalEndpoint.java?rev=1156582&r1=1156581&r2=1156582&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestLocalEndpoint.java (original) +++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestLocalEndpoint.java Thu Aug 11 11:58:24 2011 @@ -21,6 +21,7 @@ import java.io.FileDescriptor; import java.io.FileOutputStream; import java.io.IOException; import java.util.List; +import org.apache.commons.runtime.io.Stream; import org.testng.annotations.*; import org.testng.Assert; @@ -85,6 +86,9 @@ public class TestLocalEndpoint extends A // Another select with zero timeout set = ps.select(0); assertEquals(set.size(), 0); + e.configureBlocking(true); + Stream s = e.getStream(); + s.read(); } catch (Exception x) { fail("Accept failed " + x.toString()); break;