You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by rb...@hyperreal.org on 1999/05/12 21:46:20 UTC
cvs commit: apache-apr/apr/test Makefile server.c testsock.c
rbb 99/05/12 12:46:20
Modified: docs networkio.txt
include apr_network_io.h
apr/network_io/unix networkio.h poll.c sendrecv.c sockets.c
sockopt.c
apr/test Makefile server.c testsock.c
Log:
Changes to make the network code more portable. Now, users just include
apr_network_io.h and the apr layer takes care of the rest.
Revision Changes Path
1.22 +16 -0 apache-apr/docs/networkio.txt
Index: networkio.txt
===================================================================
RCS file: /home/cvs/apache-apr/docs/networkio.txt,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- networkio.txt 1999/05/10 14:36:18 1.21
+++ networkio.txt 1999/05/12 19:46:11 1.22
@@ -86,6 +86,22 @@
Arguments:
arg 1) The ap_sd_set we are clearing.
+ ap_pollfd_t *ap_setup_pool(ap_context_t *, ap_int32_t)
+ Allocate storage for poll variables.
+ Arguments:
+ arg 1) Context to operate on.
+ arg 2) How many sockets to poll on.
+ return) Allocated poll list. NULL on error.
+
+ void ap_add_poll_socket(ap_context_t *, ap_pollfd_t *, ap_socket_t *, ap_int16_t, ap_int32_t)
+ Add a socket to the poll list.
+ Arguments:
+ arg 1) context to operate on.
+ arg 2) poll list to add to
+ arg 3) socket to add
+ arg 4) events to listen for
+ arg 5) position in poll list. (This may go away when I have time to do it.)
+
ap_int32_t ap_poll(ap_pollfd_t *, ap_int32_t, ap_int32_t)
Monitor sockets for specifiedconditions.
Arguments:
1.18 +8 -7 apache-apr/include/apr_network_io.h
Index: apr_network_io.h
===================================================================
RCS file: /home/cvs/apache-apr/include/apr_network_io.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- apr_network_io.h 1999/05/12 12:00:11 1.17
+++ apr_network_io.h 1999/05/12 19:46:14 1.18
@@ -58,7 +58,6 @@
#include "apr_general.h"
#include "apr_errno.h"
-#include "networkio.h"
#ifdef __cplusplus
extern "C" {
@@ -79,12 +78,12 @@
#define APR_SO_NONBLOCK 8
#define APR_SO_REUSEADDR 16
-#define APR_POLLIN APOLLIN
-#define APR_POLLPRI APOLLPRI
-#define APR_POLLOUT APOLLOUT
-#define APR_POLLERR APOLLERR
-#define APR_POLLHUP APOLLHUP
-#define APR_POLLNVAL APOLLNVAL
+#define APR_POLLIN 0x001
+#define APR_POLLPRI 0x002
+#define APR_POLLOUT 0x004
+#define APR_POLLERR 0x010
+#define APR_POLLHUP 0x020
+#define APR_POLLNVAL 0x040
typedef enum {APR_SHUTDOWN_READ, APR_SHUTDOWN_WRITE,
APR_SHUTDOWN_READWRITE} ap_shutdown_how_e;
@@ -112,7 +111,9 @@
ap_status_t ap_setsocketopt(ap_context_t *, ap_socket_t *, ap_int32_t, ap_int32_t);
ap_status_t ap_setport(ap_context_t *, ap_socket_t *, ap_uint32_t);
+ap_pollfd_t *ap_setup_poll(ap_context_t *, ap_int32_t);
ap_int32_t ap_poll(ap_context_t *, ap_pollfd_t *, ap_int32_t, ap_int32_t);
+void ap_add_poll_socket(ap_context_t *, ap_pollfd_t *, ap_socket_t *, ap_int16_t, ap_int32_t);
/* accessor functions */
#ifdef __cplusplus
1.8 +2 -7 apache-apr/apr/network_io/unix/networkio.h
Index: networkio.h
===================================================================
RCS file: /home/cvs/apache-apr/apr/network_io/unix/networkio.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- networkio.h 1999/05/10 14:36:30 1.7
+++ networkio.h 1999/05/12 19:46:16 1.8
@@ -60,13 +60,6 @@
#include "apr_general.h"
#include <poll.h>
-#define APOLLIN POLLIN
-#define APOLLPRI POLLPRI
-#define APOLLOUT POLLOUT
-#define APOLLERR POLLERR
-#define APOLLHUP POLLHUP
-#define APOLLNVAL POLLNVAL
-
struct socket_t {
int socketdes;
char *remote_hostname;
@@ -79,6 +72,8 @@
ap_int16_t events;
ap_int16_t revents;
};
+
+ap_int16_t get_event(ap_int16_t);
#endif /* ! NETWORK_IO_H */
1.4 +38 -2 apache-apr/apr/network_io/unix/poll.c
Index: poll.c
===================================================================
RCS file: /home/cvs/apache-apr/apr/network_io/unix/poll.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- poll.c 1999/05/10 14:36:30 1.3
+++ poll.c 1999/05/12 19:46:17 1.4
@@ -53,13 +53,49 @@
*
*/
-#include "apr_network_io.h"
#include "networkio.h"
+#include "apr_network_io.h"
#include "apr_general.h"
#include <errno.h>
#include <sys/poll.h>
+
+
+ap_pollfd_t *ap_setup_poll(ap_context_t *context, ap_int32_t num)
+{
+ struct pollfd_t *new;
+ new = (struct pollfd_t *)ap_palloc(context->pool, sizeof(struct pollfd_t) * num);
+ return new;
+}
+
+ap_int16_t get_event(ap_int16_t event)
+{
+ ap_int16_t rv = 0;
+
+ if (event & APR_POLLIN)
+ rv |= POLLIN;
+ if (event & APR_POLLPRI)
+ rv |= POLLPRI;
+ if (event & APR_POLLOUT)
+ rv |= POLLOUT;
+ if (event & APR_POLLERR)
+ rv |= POLLERR;
+ if (event & APR_POLLHUP)
+ rv |= POLLHUP;
+ if (event & APR_POLLNVAL)
+ rv |= POLLNVAL;
+
+ return rv;
+}
+
+void ap_add_poll_socket(ap_context_t *cont, struct pollfd_t *aprset,
+ struct socket_t *sock, ap_int16_t event,
+ ap_int32_t pos)
+{
+ aprset[pos].sock = sock;
+ aprset[pos].events = get_event(event);
+}
-ap_int32_t ap_poll(ap_context_t *cont, ap_pollfd_t *aprset, ap_int32_t nsds, ap_int32_t timeout)
+ap_int32_t ap_poll(ap_context_t *cont, struct pollfd_t *aprset, ap_int32_t nsds, ap_int32_t timeout)
{
int i;
struct pollfd *pollset;
1.7 +3 -2 apache-apr/apr/network_io/unix/sendrecv.c
Index: sendrecv.c
===================================================================
RCS file: /home/cvs/apache-apr/apr/network_io/unix/sendrecv.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- sendrecv.c 1999/05/10 14:36:30 1.6
+++ sendrecv.c 1999/05/12 19:46:17 1.7
@@ -55,12 +55,13 @@
*
*/
+#include "networkio.h"
#include "apr_errno.h"
#include "apr_general.h"
#include "apr_network_io.h"
#include <sys/time.h>
-ap_ssize_t ap_send(ap_context_t *cont, ap_socket_t *sock, const char *buf, int len, time_t sec)
+ap_ssize_t ap_send(ap_context_t *cont, struct socket_t *sock, const char *buf, int len, time_t sec)
{
ssize_t rv;
@@ -94,7 +95,7 @@
return (ap_ssize_t) rv;
}
-ap_ssize_t ap_recv(ap_context_t *cont, ap_socket_t *sock, char *buf, int len, time_t sec)
+ap_ssize_t ap_recv(ap_context_t *cont, struct socket_t *sock, char *buf, int len, time_t sec)
{
ssize_t rv;
1.14 +12 -11 apache-apr/apr/network_io/unix/sockets.c
Index: sockets.c
===================================================================
RCS file: /home/cvs/apache-apr/apr/network_io/unix/sockets.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- sockets.c 1999/05/10 14:36:30 1.13
+++ sockets.c 1999/05/12 19:46:17 1.14
@@ -53,6 +53,7 @@
*
*/
+#include "networkio.h"
#include "apr_network_io.h"
#include "apr_general.h"
#include "apr_lib.h"
@@ -65,7 +66,7 @@
ap_status_t socket_cleanup(void *sock)
{
- ap_socket_t *thesocket = sock;
+ struct socket_t *thesocket = sock;
if (close(thesocket->socketdes) == 0) {
thesocket->socketdes = -1;
return APR_SUCCESS;
@@ -75,9 +76,9 @@
}
}
-ap_socket_t *ap_create_tcp_socket(ap_context_t *cont)
+struct socket_t *ap_create_tcp_socket(ap_context_t *cont)
{
- ap_socket_t *thesocket = (ap_socket_t *)ap_palloc(cont->pool, sizeof(ap_socket_t));
+ struct socket_t *thesocket = (struct socket_t *)ap_palloc(cont->pool, sizeof(struct socket_t));
thesocket->socketdes = socket(AF_INET ,SOCK_STREAM, IPPROTO_TCP);
thesocket->remote_hostname = NULL;
@@ -96,7 +97,7 @@
}
}
-ap_status_t ap_shutdown(ap_context_t *cont, ap_socket_t *thesocket, ap_shutdown_how_e how)
+ap_status_t ap_shutdown(ap_context_t *cont, struct socket_t *thesocket, ap_shutdown_how_e how)
{
if (shutdown(thesocket->socketdes, how) == 0) {
return APR_SUCCESS;
@@ -106,19 +107,19 @@
}
}
-ap_status_t ap_close_socket(ap_context_t *cont, ap_socket_t *thesocket)
+ap_status_t ap_close_socket(ap_context_t *cont, struct socket_t *thesocket)
{
socket_cleanup(thesocket);
ap_kill_cleanup(cont->pool, thesocket, socket_cleanup);
}
-ap_status_t ap_setport(ap_context_t *cont, ap_socket_t *sock, ap_uint32_t port)
+ap_status_t ap_setport(ap_context_t *cont, struct socket_t *sock, ap_uint32_t port)
{
sock->addr->sin_port = htons((short)port);
return APR_SUCCESS;
}
-ap_status_t ap_bind(ap_context_t *cont, ap_socket_t *sock)
+ap_status_t ap_bind(ap_context_t *cont, struct socket_t *sock)
{
sock->addr->sin_addr.s_addr = INADDR_ANY;
if (bind(sock->socketdes, (struct sockaddr *)sock->addr, sock->addr_len) == -1)
@@ -127,7 +128,7 @@
return APR_SUCCESS;
}
-ap_status_t ap_listen(ap_context_t *cont, ap_socket_t *sock, ap_int32_t backlog)
+ap_status_t ap_listen(ap_context_t *cont, struct socket_t *sock, ap_int32_t backlog)
{
if (listen(sock->socketdes, backlog) == -1)
return APR_FAILURE;
@@ -135,9 +136,9 @@
return APR_SUCCESS;
}
-ap_socket_t *ap_accept(ap_context_t *cont, const ap_socket_t *sock)
+struct socket_t *ap_accept(ap_context_t *cont, const struct socket_t *sock)
{
- ap_socket_t *new = (ap_socket_t *)ap_palloc(cont->pool, sizeof(ap_socket_t));
+ struct socket_t *new = (struct socket_t *)ap_palloc(cont->pool, sizeof(struct socket_t));
struct hostent *hptr;
new->addr = (struct sockaddr_in *)ap_palloc(cont->pool, sizeof(struct sockaddr_in));
@@ -158,7 +159,7 @@
return new;
}
-ap_status_t ap_connect(ap_context_t *cont, ap_socket_t *sock, char *hostname)
+ap_status_t ap_connect(ap_context_t *cont, struct socket_t *sock, char *hostname)
{
struct hostent *hp;
1.5 +3 -2 apache-apr/apr/network_io/unix/sockopt.c
Index: sockopt.c
===================================================================
RCS file: /home/cvs/apache-apr/apr/network_io/unix/sockopt.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- sockopt.c 1999/05/10 14:36:31 1.4
+++ sockopt.c 1999/05/12 19:46:17 1.5
@@ -53,6 +53,7 @@
*
*/
+#include "networkio.h"
#include "apr_network_io.h"
#include "apr_general.h"
#include <errno.h>
@@ -100,7 +101,7 @@
}
-ap_status_t ap_setsocketopt(ap_context_t *cont, ap_socket_t *sock, ap_int32_t opt, ap_int32_t on)
+ap_status_t ap_setsocketopt(ap_context_t *cont, struct socket_t *sock, ap_int32_t opt, ap_int32_t on)
{
int one;
struct linger li;
@@ -153,7 +154,7 @@
return APR_SUCCESS;
}
-char *ap_get_remote_hostname(ap_context_t *cont, ap_socket_t *sock)
+char *ap_get_remote_hostname(ap_context_t *cont, struct socket_t *sock)
{
return sock->remote_hostname;
}
1.11 +2 -2 apache-apr/apr/test/Makefile
Index: Makefile
===================================================================
RCS file: /home/cvs/apache-apr/apr/test/Makefile,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Makefile 1999/05/10 14:36:32 1.10
+++ Makefile 1999/05/12 19:46:19 1.11
@@ -12,12 +12,12 @@
SRCDIR=..
EXTRA_CFLAGS=-g
EXTRA_LDFLAGS=
-EXTRA_LIBS=-L../threadproc -lthreadproc -L../network_io -lnetwork -L../file_io -lfile -L../misc -laprmisc -L../lib -lapr
+EXTRA_LIBS=-L../threadproc -lthreadproc -L../network_io -lnetwork -L../file_io -lfile -L../misc -lmisc -L../lib -lapr
EXTRA_INCLUDES=
EXTRA_DEPS=
OSDIR=
INCDIR=../../include
-INCLUDES0=-I ../file_io/unix -I ../network_io/unix -I ../threadproc/unix -I $(INCDIR)
+INCLUDES0=-I $(INCDIR) -I../threadproc/unix
SHELL=/bin/sh
CC=gcc
CPP=gcc -E
1.5 +4 -5 apache-apr/apr/test/server.c
Index: server.c
===================================================================
RCS file: /home/cvs/apache-apr/apr/test/server.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- server.c 1999/05/10 14:36:33 1.4
+++ server.c 1999/05/12 19:46:19 1.5
@@ -60,7 +60,6 @@
#include "apr_network_io.h"
#include "apr_errno.h"
#include "apr_general.h"
-#include "errno.h"
#define STRLEN 15
@@ -70,7 +69,7 @@
ap_socket_t *sock;
ap_socket_t *sock2;
ap_int32_t rv;
- ap_pollfd_t sdset;
+ ap_pollfd_t *sdset;
char datasend[STRLEN];
char datarecv[STRLEN] = "Recv data test";
@@ -116,12 +115,12 @@
fprintf(stdout, "OK\n");
fprintf(stdout, "\tServer: Setting up socket for polling.......");
- sdset.sock = sock;
- sdset.events = APR_POLLIN;
+ sdset = ap_setup_poll(context, 1);
+ ap_add_poll_socket(context, sdset, sock, APR_POLLIN, 0);
fprintf(stdout, "OK\n");
fprintf(stdout, "\tServer: Beginning to poll for socket.......");
- rv = ap_poll(context, &sdset, 1, -1);
+ rv = ap_poll(context, sdset, 1, -1);
if (rv == -1) {
ap_close_socket(context, sock);
fprintf(stderr, "Select caused an error\n");
1.5 +0 -1 apache-apr/apr/test/testsock.c
Index: testsock.c
===================================================================
RCS file: /home/cvs/apache-apr/apr/test/testsock.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- testsock.c 1999/05/10 14:36:34 1.4
+++ testsock.c 1999/05/12 19:46:19 1.5
@@ -58,7 +58,6 @@
#include "apr_thread_proc.h"
#include "apr_errno.h"
#include "apr_general.h"
-#include "errno.h"
#define STRLEN 15