bjh 99/10/21 02:03:11
Modified: src/os/os2 iol_socket.c
Log:
Apply iol_socket errno changes to OS/2 version.
Revision Changes Path
1.3 +51 -32 apache-2.0/src/os/os2/iol_socket.c
Index: iol_socket.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/os/os2/iol_socket.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- iol_socket.c 1999/07/12 08:47:47 1.2
+++ iol_socket.c 1999/10/21 09:03:09 1.3
@@ -58,6 +58,7 @@
#include "httpd.h"
#include "ap_iol.h"
+#include "iol_socket.h"
#include <errno.h>
#include <sys/types.h>
@@ -72,7 +73,8 @@
int timeout;
} iol_socket;
-static int os2_setopt(ap_iol *viol, ap_iol_option opt, const void *value)
+static ap_status_t os2_setopt(ap_iol *viol, ap_iol_option opt,
+ const void *value)
{
iol_socket *iol = (iol_socket *)viol;
@@ -81,13 +83,12 @@
iol->timeout = *(const int *)value;
break;
default:
- errno = EINVAL;
- return -1;
+ return APR_EINVAL;
}
- return 0;
+ return APR_SUCCESS;
}
-static int os2_getopt(ap_iol *viol, ap_iol_option opt, void *value)
+static ap_status_t os2_getopt(ap_iol *viol, ap_iol_option opt, void *value)
{
iol_socket *iol = (iol_socket *)viol;
@@ -96,29 +97,33 @@
*(int *)value = iol->timeout;
break;
default:
- errno = EINVAL;
- return -1;
+ return APR_EINVAL;
}
- return 0;
+ return APR_SUCCESS;
}
-static int set_nonblock(int fd)
+static ap_status_t set_nonblock(int fd)
{
int fd_flags;
+ int rv;
fd_flags = fcntl(fd, F_GETFL, 0);
#if defined(O_NONBLOCK)
fd_flags |= O_NONBLOCK;
- return fcntl(fd, F_SETFL, fd_flags);
+ rv = fcntl(fd, F_SETFL, fd_flags);
#elif defined(O_NDELAY)
fd_flags |= O_NDELAY;
- return fcntl(fd, F_SETFL, fd_flags);
+ rv = fcntl(fd, F_SETFL, fd_flags);
#elif defined(FNDELAY)
fd_flags |= O_FNDELAY;
- return fcntl(fd, F_SETFL, fd_flags);
+ rv = fcntl(fd, F_SETFL, fd_flags);
#else
#error "your unix lacks non-blocking i/o, you lose"
#endif
+ if (rv == 0) {
+ return APR_SUCCESS;
+ }
+ return errno;
}
/* the timeout code is a separate routine because it requires
@@ -128,7 +133,7 @@
/* this macro expands into the four basic i/o methods */
#define method(name, args, syscall, selread, selwrite) \
- static int os2_##name##_timeout args \
+ static ap_status_t os2_##name##_timeout args \
{ \
iol_socket *iol = (iol_socket *)viol; \
fd_set fdset; \
@@ -143,27 +148,38 @@
rv = ap_select(iol->fd + 1, selread, selwrite, NULL, iol->timeout <
0 ? NULL : &tv); \
} while (rv == -1 && errno == EINTR); \
if (!FD_ISSET(iol->fd, &fdset)) { \
- errno = ETIMEDOUT; \
- return -1; \
+ return APR_ETIMEDOUT; \
} \
do { \
rv = syscall(iol->fd, arg1, arg2); \
} while (rv == -1 && errno == EINTR); \
- return rv; \
+ if (rv >= 0) { \
+ *nbytes = rv; \
+ return APR_SUCCESS; \
+ } \
+ return errno; \
+ \
} \
\
- static int os2_##name args \
+ static ap_status_t os2_##name args \
{ \
iol_socket *iol = (iol_socket *)viol; \
int rv; \
\
+ /* Present to zero until some bytes are actually written */ \
+ *nbytes = 0; \
if (!(iol->flags & FD_NONBLOCKING_SET)) { \
if (iol->timeout < 0) { \
- return syscall(iol->fd, arg1, arg2); \
+ rv = syscall(iol->fd, arg1, arg2); \
+ if (rv >= 0) { \
+ *nbytes = rv; \
+ return APR_SUCCESS; \
+ } \
+ return errno; \
} \
/* must shift descriptor to blocking mode now */ \
- if (set_nonblock(iol->fd)) { \
- return -1; \
+ if ((rv = set_nonblock(iol->fd)) != APR_SUCCESS) { \
+ return rv; \
} \
iol->flags |= FD_NONBLOCKING_SET; \
} \
@@ -173,20 +189,21 @@
do { \
rv = syscall(iol->fd, arg1, arg2); \
} while (rv == -1 && errno == EINTR); \
- if (rv >= 0) { \
- return rv; \
+ if ((errno == EWOULDBLOCK || errno == EAGAIN) && iol->timeout != 0) { \
+ return os2_##name##_timeout(viol, arg1, arg2, nbytes); \
} \
- if (errno == EWOULDBLOCK && iol->timeout != 0) { \
- return os2_##name##_timeout(viol, arg1, arg2); \
+ if (rv >= 0) { \
+ *nbytes = rv; \
+ return APR_SUCCESS; \
} \
- return -1; \
- } \
+ return errno; \
+ }
-method(write, (ap_iol *viol, const char *arg1, int arg2), write, NULL,
&fdset)
-method(writev, (ap_iol *viol, const struct iovec *arg1, int arg2), writev,
NULL, &fdset)
-method(read, (ap_iol *viol, char *arg1, int arg2), read, &fdset, NULL)
+method(write, (ap_iol *viol, const char *arg1, ap_size_t arg2, ap_ssize_t
*nbytes), write, NULL, &fdset)
+method(writev, (ap_iol *viol, const struct iovec *arg1, int arg2, ap_ssize_t
*nbytes), writev, NULL, &fdset)
+method(read, (ap_iol *viol, char *arg1, ap_size_t arg2, ap_ssize_t *nbytes),
read, &fdset, NULL)
-static int os2_close(ap_iol *viol)
+static ap_status_t os2_close(ap_iol *viol)
{
iol_socket *iol = (iol_socket *)viol;
int rv;
@@ -195,8 +212,10 @@
rv = close(iol->fd);
saved_errno = errno;
free(iol);
- errno = saved_errno;
- return rv;
+ if (rv == 0) {
+ return APR_SUCCESS;
+ }
+ return saved_errno;
}
static const ap_iol_methods socket_methods = {