You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by st...@locus.apache.org on 2000/04/19 19:42:08 UTC
cvs commit: apache-2.0/src/lib/apr/file_io/win32 open.c readwrite.c
stoddard 00/04/19 10:42:08
Modified: src/lib/apr/file_io/win32 open.c readwrite.c
Log:
Reimplement ap_writev, et. al. using ap_write.
Revision Changes Path
1.32 +3 -1 apache-2.0/src/lib/apr/file_io/win32/open.c
Index: open.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/win32/open.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- open.c 2000/04/18 13:57:29 1.31
+++ open.c 2000/04/19 17:42:07 1.32
@@ -223,8 +223,10 @@
return APR_ENOMEM;
}
(*thefile)->filehand = GetStdHandle(STD_ERROR_HANDLE);
+ if ((*thefile)->filehand == INVALID_HANDLE_VALUE)
+ return GetLastError();
(*thefile)->cntxt = cont;
- (*thefile)->fname = NULL;
+ (*thefile)->fname = "STD_ERROR_HANDLE";
(*thefile)->stated = 0;
(*thefile)->eof_hit = 0;
1.26 +22 -22 apache-2.0/src/lib/apr/file_io/win32/readwrite.c
Index: readwrite.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/win32/readwrite.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- readwrite.c 2000/04/18 14:03:54 1.25
+++ readwrite.c 2000/04/19 17:42:07 1.26
@@ -88,14 +88,19 @@
ap_status_t ap_write(ap_file_t *thefile, void *buf, ap_ssize_t *nbytes)
{
+ ap_status_t rv;
DWORD bwrote;
-
+
if (WriteFile(thefile->filehand, buf, *nbytes, &bwrote, NULL)) {
*nbytes = bwrote;
- return APR_SUCCESS;
+ rv = APR_SUCCESS;
+ }
+ else {
+ (*nbytes) = 0;
+ rv = GetLastError();
}
- (*nbytes) = 0;
- return GetLastError();
+
+ return rv;
}
/*
* Too bad WriteFileGather() is not supported on 95&98 (or NT prior to SP2)
@@ -103,28 +108,29 @@
ap_status_t ap_writev(ap_file_t *thefile, const struct iovec *vec, ap_size_t nvec,
ap_ssize_t *nbytes)
{
+ ap_status_t rv = APR_SUCCESS;
int i;
DWORD bwrote = 0;
+ char *buf;
*nbytes = 0;
for (i = 0; i < nvec; i++) {
- if (!WriteFile(thefile->filehand,
- vec[i].iov_base, vec[i].iov_len, &bwrote, NULL)) {
- return GetLastError();
- }
+ buf = vec[i].iov_base;
+ bwrote = vec[i].iov_len;
+ rv = ap_write(thefile, buf, &bwrote);
*nbytes += bwrote;
+ if (rv != APR_SUCCESS) {
+ break;
+ }
}
- return APR_SUCCESS;
+ return rv;
}
ap_status_t ap_putc(char ch, ap_file_t *thefile)
{
- DWORD bwrote;
+ DWORD len = 1;
- if (!WriteFile(thefile->filehand, &ch, 1, &bwrote, NULL)) {
- return GetLastError();
- }
- return APR_SUCCESS;
+ return ap_write(thefile, &ch, &len);
}
ap_status_t ap_ungetc(char ch, ap_file_t *thefile)
@@ -174,15 +180,9 @@
ap_status_t ap_puts(char *str, ap_file_t *thefile)
{
- DWORD bwrote;
- int len;
+ DWORD len = strlen(str);
- len = strlen(str);
- if (!WriteFile(thefile->filehand, str, len, &bwrote, NULL)) {
- return GetLastError();
- }
-
- return APR_SUCCESS;
+ return ap_write(thefile, str, &len);
}
ap_status_t ap_fgets(char *str, int len, ap_file_t *thefile)
Re: cvs commit: apache-2.0/src/lib/apr/file_io/win32 open.c readwrite.c
Posted by dean gaudet <dg...@arctic.org>.
On Thu, 20 Apr 2000, Greg Stein wrote:
> On Thu, 20 Apr 2000, dean gaudet wrote:
> > On Wed, 19 Apr 2000, Greg Stein wrote:
> >
> > > Dean had an excellent point here. ap_writev() callers already know that
> > > only a portion of the bytes may be written, and they will compensate.
> > > Therefore, the ap_writev() can be simplified to:
> > >
> > > {
> > > if (nvec == 0) {
> > > *nbytes = 0;
> > > reutrn APR_SUCCESS;
> > > }
> >
> > i think even that is redundant... ap_write() should handle a 0-byte write
> > anyhow.
> >
> > -dean
> >
> > > *nbytes = vec[0].iov_len;
> > > return ap_write(thefile, vec[0].iov_base, nbytes);
> > > }
>
>
> That check is to ensure that vec[0] can be done safely.
good point, the unix version needs fixing then.
-dean
Re: cvs commit: apache-2.0/src/lib/apr/file_io/win32 open.c readwrite.c
Posted by Greg Stein <gs...@lyra.org>.
On Thu, 20 Apr 2000, dean gaudet wrote:
> On Wed, 19 Apr 2000, Greg Stein wrote:
>
> > Dean had an excellent point here. ap_writev() callers already know that
> > only a portion of the bytes may be written, and they will compensate.
> > Therefore, the ap_writev() can be simplified to:
> >
> > {
> > if (nvec == 0) {
> > *nbytes = 0;
> > reutrn APR_SUCCESS;
> > }
>
> i think even that is redundant... ap_write() should handle a 0-byte write
> anyhow.
>
> -dean
>
> > *nbytes = vec[0].iov_len;
> > return ap_write(thefile, vec[0].iov_base, nbytes);
> > }
That check is to ensure that vec[0] can be done safely.
Cheers,
-g
--
Greg Stein, http://www.lyra.org/
Re: cvs commit: apache-2.0/src/lib/apr/file_io/win32 open.c readwrite.c
Posted by dean gaudet <dg...@arctic.org>.
On Wed, 19 Apr 2000, Greg Stein wrote:
> Dean had an excellent point here. ap_writev() callers already know that
> only a portion of the bytes may be written, and they will compensate.
> Therefore, the ap_writev() can be simplified to:
>
> {
> if (nvec == 0) {
> *nbytes = 0;
> reutrn APR_SUCCESS;
> }
i think even that is redundant... ap_write() should handle a 0-byte write
anyhow.
-dean
> *nbytes = vec[0].iov_len;
> return ap_write(thefile, vec[0].iov_base, nbytes);
> }
>
> Cheers,
> -g
>
> --
> Greg Stein, http://www.lyra.org/
>
>
Re: cvs commit: apache-2.0/src/lib/apr/file_io/win32 open.c readwrite.c
Posted by Greg Stein <gs...@lyra.org>.
On 19 Apr 2000 stoddard@locus.apache.org wrote:
>...
> ap_status_t ap_writev(ap_file_t *thefile, const struct iovec *vec, ap_size_t nvec,
> ap_ssize_t *nbytes)
> {
> + ap_status_t rv = APR_SUCCESS;
> int i;
> DWORD bwrote = 0;
> + char *buf;
>
> *nbytes = 0;
> for (i = 0; i < nvec; i++) {
> - if (!WriteFile(thefile->filehand,
> - vec[i].iov_base, vec[i].iov_len, &bwrote, NULL)) {
> - return GetLastError();
> - }
> + buf = vec[i].iov_base;
> + bwrote = vec[i].iov_len;
> + rv = ap_write(thefile, buf, &bwrote);
> *nbytes += bwrote;
> + if (rv != APR_SUCCESS) {
> + break;
> + }
> }
> - return APR_SUCCESS;
> + return rv;
> }
Dean had an excellent point here. ap_writev() callers already know that
only a portion of the bytes may be written, and they will compensate.
Therefore, the ap_writev() can be simplified to:
{
if (nvec == 0) {
*nbytes = 0;
reutrn APR_SUCCESS;
}
*nbytes = vec[0].iov_len;
return ap_write(thefile, vec[0].iov_base, nbytes);
}
Cheers,
-g
--
Greg Stein, http://www.lyra.org/