Author: mturk
Date: Wed Aug 10 17:48:36 2011
New Revision: 1156273
URL: http://svn.apache.org/viewvc?rev=1156273&view=rev
Log:
Do not reference socket
Modified:
commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h
commons/sandbox/runtime/trunk/src/main/native/os/linux/sendfile.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/sendfile.c
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=1156273&r1=1156272&r2=1156273&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 Wed
Aug 10 17:48:36 2011
@@ -92,7 +92,6 @@ struct acr_sf_t {
#else
HANDLE fh;
#endif
- acr_sd_t *sd;
off_t off;
#if !defined(WINDOWS)
struct_stat_t info;
Modified: commons/sandbox/runtime/trunk/src/main/native/os/linux/sendfile.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/linux/sendfile.c?rev=1156273&r1=1156272&r2=1156273&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/linux/sendfile.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/linux/sendfile.c Wed Aug
10 17:48:36 2011
@@ -29,42 +29,59 @@
#include <poll.h>
#include <sys/sendfile.h>
-ACR_NET_EXPORT(jint, SendFile, send0)(JNI_STDARGS, jlong fp)
+/**
+ * Used for files that report st_size == 0
+ * like /proc/ file system
+ */
+#define ZERO_FILE_LINE_CHUNK 4096
+
+ACR_NET_EXPORT(jint, Sendfile, send0)(JNI_STDARGS, jlong sp, jlong fp)
{
int rc = 0;
ssize_t wr = 0;
- size_t cnt;
+ size_t cnt = ZERO_FILE_LINE_CHUNK;
+ acr_sd_t *sd = J2P(sp, acr_sd_t *);
acr_sf_t *sf = J2P(fp, acr_sf_t *);
+ int sock;
- if ((sf->info.st_size - sf->off) > INT_MAX)
- cnt = INT_MAX;
- else
- cnt = sf->info.st_size - sf->off;
- if (ACR_HASFLAG(sf->sd, ACR_SO_WPART)) {
- ACR_CLRFLAG(sf->sd, ACR_SO_WPART);
- rc = AcrWaitIO(sf->sd->s, sf->sd->timeout, POLLOUT);
+ if ((sock = AcrSdRetain(sd)) == -1) {
+ ACR_THROW_NET_ERROR(ACR_EBADF);
+ return -1;
+ }
+ if (sf->info.st_size != 0) {
+ if ((sf->info.st_size - sf->off) > INT_MAX)
+ cnt = INT_MAX;
+ else
+ cnt = sf->info.st_size - sf->off;
+ }
+ if (ACR_HASFLAG(sd, ACR_SO_WPART)) {
+ ACR_CLRFLAG(sd, ACR_SO_WPART);
+ rc = AcrWaitIO(sock, sd->timeout, POLLOUT);
}
while (rc == 0) {
if (cnt == 0)
break;
- wr = sendfile(sf->sd->s, /* socket */
- sf->fd, /* open file descriptor of the file to be
sent */
- &sf->off, /* where in the file to start */
- cnt); /* number of bytes to send */
+ wr = sendfile(sock, /* socket */
+ sf->fd, /* file descriptor of the file to be sent */
+ &sf->off, /* where in the file to start */
+ cnt); /* number of bytes to send */
if (wr == -1) {
- if ((errno == EAGAIN || errno == EWOULDBLOCK) && (sf->sd->timeout
> 0))
- rc = AcrWaitIO(sf->sd->s, sf->sd->timeout, POLLOUT);
+ if ((errno == EAGAIN || errno == EWOULDBLOCK) && (sd->timeout > 0))
+ rc = AcrWaitIO(sock, sd->timeout, POLLOUT);
else if (errno != EINTR)
rc = errno;
}
- else
+ else {
+ /* Send something */
break;
+ }
}
if (rc != 0) {
wr = -1;
ACR_THROW_NET_ERROR(rc);
}
- else if (sf->sd->timeout > 0 && wr < cnt)
- sf->sd->flags |= ACR_SO_WPART;
+ else if (sd->timeout > 0 && wr < cnt)
+ sd->flags |= ACR_SO_WPART;
+ AcrSdRelease(sd);
return (jint)wr;
}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/sendfile.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/sendfile.c?rev=1156273&r1=1156272&r2=1156273&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/sendfile.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/sendfile.c Wed Aug 10
17:48:36 2011
@@ -27,20 +27,13 @@
#include "arch_sync.h"
#include <poll.h>
-ACR_NET_EXPORT(jlong, SendFile, open0)(JNI_STDARGS, jlong sp, jstring fname)
+ACR_NET_EXPORT(jlong, Sendfile, open0)(JNI_STDARGS, jstring fname)
{
int rc = 0;
acr_sf_t *sf;
- acr_sd_t *sd = J2P(sp, acr_sd_t *);
-
- if (sd == 0 || sd->s == -1) {
- ACR_THROW_NET_ERROR(ACR_EBADF);
- return 0;
- }
if ((sf = ACR_TALLOC(acr_sf_t)) == 0)
return 0;
- sf->sd = sd;
sf->fd = -1;
WITH_CSTR(fname) {
int flags = O_RDONLY;
@@ -67,18 +60,16 @@ ACR_NET_EXPORT(jlong, SendFile, open0)(J
ACR_THROW_NET_ERROR(rc);
return 0;
}
- AcrSdRetain(sd);
return P2J(sf);
}
-ACR_NET_EXPORT(jlong, SendFile, open1)(JNI_STDARGS, jlong sp, jobject fd)
+ACR_NET_EXPORT(jlong, Sendfile, open1)(JNI_STDARGS, jobject fd)
{
int rc = 0;
int nd;
acr_sf_t *sf;
- acr_sd_t *sd = J2P(sp, acr_sd_t *);
- if (sd == 0 || fd == 0 || sd->s == -1) {
+ if (fd == 0) {
ACR_THROW_NET_ERROR(ACR_EBADF);
return 0;
}
@@ -89,7 +80,6 @@ ACR_NET_EXPORT(jlong, SendFile, open1)(J
}
if ((sf = ACR_TALLOC(acr_sf_t)) == 0)
return 0;
- sf->sd = sd;
/* Duplicate FileDescriptor so
* we don't have to reference it
*/
@@ -113,21 +103,34 @@ ACR_NET_EXPORT(jlong, SendFile, open1)(J
}
if (fstat(sf->fd, &sf->info) != 0) {
rc = ACR_GET_OS_ERROR();
+ r_close(sf->fd);
AcrFree(sf);
ACR_THROW_NET_ERROR(rc);
return 0;
}
- AcrSdRetain(sd);
return P2J(sf);
}
-ACR_NET_EXPORT(jint, SendFile, close0)(JNI_STDARGS, jlong fp)
+ACR_NET_EXPORT(jint, Sendfile, close0)(JNI_STDARGS, jlong fp)
{
int rc = 0;
acr_sf_t *sf = J2P(fp, acr_sf_t *);
rc = s_close(sf->fd);
- AcrSdRelease(sf->sd);
AcrFree(sf);
return rc;
}
+
+ACR_NET_EXPORT(jlong, Sendfile, size0)(JNI_STDARGS, jlong fp)
+{
+ acr_sf_t *sf = J2P(fp, acr_sf_t *);
+
+ return (jlong)sf->info.st_size;
+}
+
+ACR_NET_EXPORT(jlong, Sendfile, size1)(JNI_STDARGS, jlong fp)
+{
+ acr_sf_t *sf = J2P(fp, acr_sf_t *);
+
+ return (jlong)sf->off;
+}