rbb 99/09/02 13:33:43
Modified: src/lib/apr/include apr_network_io.h src/lib/apr/network_io/unix sendrecv.c sockets.c Log: Add some network API's to APR. Revision Changes Path 1.2 +2 -0 apache-2.0/src/lib/apr/include/apr_network_io.h Index: apr_network_io.h =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_network_io.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- apr_network_io.h 1999/08/17 15:59:37 1.1 +++ apr_network_io.h 1999/09/02 20:33:32 1.2 @@ -117,6 +117,8 @@ ap_status_t ap_setsocketopt(ap_socket_t *, ap_int32_t, ap_int32_t); ap_status_t ap_setport(ap_socket_t *, ap_uint32_t); +ap_status_t ap_setipaddr(ap_socket_t *, const char *); +ap_status_t ap_getport(ap_socket_t *, ap_uint32_t *); ap_status_t ap_setup_poll(ap_context_t *, ap_int32_t, ap_pollfd_t **); ap_status_t ap_poll(ap_pollfd_t *, ap_int32_t *, ap_int32_t); 1.2 +24 -17 apache-2.0/src/lib/apr/network_io/unix/sendrecv.c Index: sendrecv.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/sendrecv.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- sendrecv.c 1999/08/17 15:59:43 1.1 +++ sendrecv.c 1999/09/02 20:33:36 1.2 @@ -68,10 +68,8 @@ * arg 2) The buffer which contains the data to be sent. * arg 3) The maximum number of bytes to send * arg 4) The amount of time in seconds to try sending this data. - * NOTE: The number of bytes actually sent is stored in argument 3. It is - * not currently possible to have this behave like a blocking write. - * If the timeout is zero, it will try to send the data, and return - * immediately. + * NOTE: The number of bytes actually sent is stored in argument 3. To have + * this behave like a non-blocking write, us a timeout of -1. */ ap_status_t ap_send(struct socket_t *sock, const char *buf, ap_ssize_t *len, time_t sec) { @@ -82,17 +80,22 @@ } while (rv == -1 && errno == EINTR); if (rv == -1 && errno == EAGAIN && sec > 0) { - struct timeval tv; + struct timeval *tv; fd_set fdset; int srv; do { FD_ZERO(&fdset); FD_SET(sock->socketdes, &fdset); - tv.tv_sec = sec; - tv.tv_usec = 0; - - srv = select(FD_SETSIZE, NULL, &fdset, NULL, &tv); + if (sec == -1) { + tv = NULL; + } + else { + tv = ap_palloc(sock->cntxt, sizeof(struct timeval)); + tv->tv_sec = sec; + tv->tv_usec = 0; + } + srv = select(FD_SETSIZE, NULL, &fdset, NULL, tv); } while (srv == -1 && errno == EINTR); if (srv == 0) { @@ -120,10 +123,8 @@ * arg 2) The buffer to store the data in. * arg 3) The maximum number of bytes to read * arg 4) The amount of time in seconds to try reading data. - * NOTE: The number of bytes actually read is stored in argument 3. It is - * not currently possible to have this behave like a blocking read. - * If the timeout is zero, it will try to read data, and return - * immediately. + * NOTE: The number of bytes actually sent is stored in argument 3. To have + * this behave like a non-blocking write, us a timeout of -1. */ ap_status_t ap_recv(struct socket_t *sock, char *buf, ap_ssize_t *len, time_t sec) { @@ -134,17 +135,23 @@ } while (rv == -1 && errno == EINTR); if (rv == -1 && errno == EAGAIN && sec > 0) { - struct timeval tv; + struct timeval *tv; fd_set fdset; int srv; do { FD_ZERO(&fdset); FD_SET(sock->socketdes, &fdset); - tv.tv_sec = sec; - tv.tv_usec = 0; + if (sec == -1) { + tv = NULL; + } + else { + tv = ap_palloc(sock->cntxt, sizeof(struct timeval)); + tv->tv_sec = sec; + tv->tv_usec = 0; + } - srv = select(FD_SETSIZE, &fdset, NULL, NULL, &tv); + srv = select(FD_SETSIZE, &fdset, NULL, NULL, tv); } while (srv == -1 && errno == EINTR); if (srv == 0) { 1.2 +44 -14 apache-2.0/src/lib/apr/network_io/unix/sockets.c Index: sockets.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/sockets.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- sockets.c 1999/08/17 15:59:43 1.1 +++ sockets.c 1999/09/02 20:33:36 1.2 @@ -161,6 +161,34 @@ } /* ***APRDOC******************************************************** + * ap_status_t ap_getport(ap_socket_t *, ap_uint32_t *) + * Return the port with a socket. + * arg 1) The socket use + * arg 2) The port this socket will be dealing with. + */ +ap_status_t ap_getport(struct socket_t *sock, ap_uint32_t *port) +{ + *port = ntohs(sock->addr->sin_port); + return APR_SUCCESS; +} + +/* ***APRDOC******************************************************** + * ap_status_t ap_setipaddr(ap_socket_t *, apr_uint32_t addr) + * Assocaite a socket addr with an apr socket. + * arg 1) The socket to use + * arg 2) The IP address to attach to the socket. + * NOTE: This does not bind the two together, it is just telling apr + * that this socket is going to use this address if possible. + */ +ap_status_t ap_setipaddr(struct socket_t *sock, const char *addr) +{ + if (inet_aton(addr, &sock->addr->sin_addr.s_addr) == 0) { + return errno; + } + return APR_SUCCESS; +} + +/* ***APRDOC******************************************************** * ap_status_t ap_bind(ap_socket_t *) * Bind the socket to it's assocaited port * arg 1) The socket to bind @@ -235,29 +263,31 @@ * Issue a connection request to a socket either on the same machine * or a different one. * arg 1) The socket we wish to use for our side of the connection - * arg 2) The hostname of the machine we wish to connect to. + * arg 2) The hostname of the machine we wish to connect to. If NULL, + * APR assumes that the sockaddr_in in the apr_socket is completely + * filled out. */ ap_status_t ap_connect(struct socket_t *sock, char *hostname) { struct hostent *hp; - hp = gethostbyname(hostname); + if (hostname == NULL) { + hp = gethostbyname(hostname); - if ((sock->socketdes < 0) || (!sock->addr)) { - return APR_ENOTSOCK; - } - if (!hp) { - if (h_errno == TRY_AGAIN) { - return EAGAIN; + if ((sock->socketdes < 0) || (!sock->addr)) { + return APR_ENOTSOCK; } - return h_errno; - } + if (!hp) { + if (h_errno == TRY_AGAIN) { + return EAGAIN; + } + return h_errno; + } - memcpy((char *)&sock->addr->sin_addr, hp->h_addr_list[0], hp->h_length); + memcpy((char *)&sock->addr->sin_addr, hp->h_addr_list[0], hp->h_length); - sock->addr->sin_family = AF_INET; - - sock->addr_len = sizeof(*sock->addr); + sock->addr_len = sizeof(*sock->addr); + } if ((connect(sock->socketdes, (const struct sockaddr *)sock->addr, sock->addr_len) < 0) && (errno != EINPROGRESS)) {