jfclere 02/04/26 06:12:35
Modified: webapp/include wa.h
webapp/lib Makefile.in Makefile.win pr_warp.c pr_warp.h
pr_warp_config.c pr_warp_network.c wa_main.c
Added: webapp/lib pr_warp_socketpool.c
Log:
Add socketpool for win32 and thread Apaches.
Submitted by: Simon Keary, simonkeary at eircom.net
Revision Changes Path
1.14 +5 -1 jakarta-tomcat-connectors/webapp/include/wa.h
Index: wa.h
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/include/wa.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- wa.h 1 Nov 2001 22:20:51 -0000 1.13
+++ wa.h 26 Apr 2002 13:12:35 -0000 1.14
@@ -57,7 +57,7 @@
/**
* @author Pier Fumagalli <mailto:[EMAIL PROTECTED]>
- * @version $Id: wa.h,v 1.13 2001/11/01 22:20:51 pier Exp $
+ * @version $Id: wa.h,v 1.14 2002/04/26 13:12:35 jfclere Exp $
*/
#ifndef _WA_H_
#define _WA_H_
@@ -82,6 +82,10 @@
#include <apr_time.h>
#include <apr_network_io.h>
#include <apr_file_info.h>
+#if APR_HAS_THREAD
+#include <apr_thread_mutex.h>
+#include <apr_atomic.h>
+#endif
/* WebApp Library type definitions. */
typedef enum {
1.23 +5 -3 jakarta-tomcat-connectors/webapp/lib/Makefile.in
Index: Makefile.in
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/lib/Makefile.in,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- Makefile.in 30 Jan 2002 09:21:29 -0000 1.22
+++ Makefile.in 26 Apr 2002 13:12:35 -0000 1.23
@@ -56,7 +56,7 @@
# ========================================================================= #
# @author Pier Fumagalli <mailto:[EMAIL PROTECTED]>
-# @version $Id: Makefile.in,v 1.22 2002/01/30 09:21:29 jfclere Exp $
+# @version $Id: Makefile.in,v 1.23 2002/04/26 13:12:35 jfclere Exp $
include @TGTDIR@/Makedefs
@@ -68,7 +68,8 @@
pr_warp_packet.c \
wa_config.c \
wa_main.c \
- wa_request.c
+ wa_request.c \
+ pr_warp_socketpool.c
OBJS = wa_main.lo \
wa_config.lo \
@@ -78,7 +79,8 @@
pr_warp.lo \
pr_warp_packet.lo \
pr_warp_network.lo \
- pr_warp_config.lo
+ pr_warp_config.lo \
+ pr_warp_socketpool.lo
LIB = $(TGTDIR)/lib/libwebapp.a
1.4 +3 -2 jakarta-tomcat-connectors/webapp/lib/Makefile.win
Index: Makefile.win
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/lib/Makefile.win,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Makefile.win 1 Nov 2001 22:20:51 -0000 1.3
+++ Makefile.win 26 Apr 2002 13:12:35 -0000 1.4
@@ -56,7 +56,7 @@
# ========================================================================= #
# @author Pier Fumagalli <mailto:[EMAIL PROTECTED]>
-# @version $Id: Makefile.win,v 1.3 2001/11/01 22:20:51 pier Exp $
+# @version $Id: Makefile.win,v 1.4 2002/04/26 13:12:35 jfclere Exp $
# All our object files
OBJS = wa_config.obj \
@@ -66,7 +66,8 @@
pr_warp.obj \
pr_warp_config.obj \
pr_warp_network.obj \
- pr_warp_packet.obj
+ pr_warp_packet.obj \
+ pr_warp_socketpool.obj
# Files created by this script (for removal only)
GENS = webapp.idb \
1.21 +96 -54 jakarta-tomcat-connectors/webapp/lib/pr_warp.c
Index: pr_warp.c
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/lib/pr_warp.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- pr_warp.c 29 Oct 2001 14:45:21 -0000 1.20
+++ pr_warp.c 26 Apr 2002 13:12:35 -0000 1.21
@@ -54,7 +54,7 @@
* *
* ========================================================================= */
-/* @version $Id: pr_warp.c,v 1.20 2001/10/29 14:45:21 jfclere Exp $ */
+/* @version $Id: pr_warp.c,v 1.21 2002/04/26 13:12:35 jfclere Exp $ */
#include "pr_warp.h"
/* Initialize this provider. */
@@ -70,11 +70,18 @@
/* Open all connections having deployed applications */
while (elem!=NULL) {
wa_connection *curr=(wa_connection *)elem->curr;
+ warp_config *conf=(warp_config *)curr->conf;
+ apr_socket_t * sock = 0;
wa_debug(WA_MARK,"Opening connection \"%s\"",curr->name);
- if (n_connect(curr)==wa_true) {
+
+ sock=n_connect(curr);
+ if (sock!=NULL) {
wa_debug(WA_MARK,"Connection \"%s\" opened",curr->name);
- if (c_configure(curr)==wa_true) {
+ if (c_configure(curr,sock)==wa_true) {
wa_debug(WA_MARK,"Connection \"%s\" configured",curr->name);
+
+ warp_sockpool_release(conf->socket_pool, curr, sock);
+
} else {
wa_log(WA_MARK,"Cannot configure connection \"%s\"",curr->name);
}
@@ -116,9 +123,19 @@
if (r!=APR_SUCCESS) return("Cannot get socket address information");
/* Done */
- conf->sock=NULL;
- conf->serv=0;
+#if APR_HAS_THREADS
+ apr_atomic_set(&conf->serv, (unsigned) 0);
+ apr_atomic_set(&conf->open_socket_count, (unsigned) 0);
+#else
+ conf->serv = 0;
+ conf->open_socket_count = 0;
+#endif
conn->conf=conf;
+
+ /* Create the socket pool */
+ conf->socket_pool = warp_sockpool_create();
+ if (conf->socket_pool == NULL) return("Cannot create socket pool");
+
return(NULL);
}
@@ -166,20 +183,23 @@
apr_port_t port=0;
char *addr=NULL;
char *name=NULL;
- char *mesg=NULL;
char *buff=NULL;
+#if APR_HAS_THREADS
+ apr_uint32_t socket_count = apr_atomic_read(&conf->open_socket_count);
+ apr_uint32_t server_id = apr_atomic_read(&conf->serv);
+#else
+ apr_uint32_t socket_count = conf->open_socket_count;
+ apr_uint32_t server_id = conf->serv;
+#endif
if (conf==NULL) return("Invalid configuration member");
apr_sockaddr_port_get(&port,conf->addr);
apr_sockaddr_ip_get(&addr,conf->addr);
apr_getnameinfo(&name,conf->addr,0);
- if (conf->sock==NULL) mesg="Not Connected";
- else mesg="Connected";
-
- buff=apr_psprintf(pool,"Host: %s Port:%d Address:%s (%s) Server ID: %d",
- name,port,addr,mesg,conf->serv);
+ buff=apr_psprintf(pool,"Host: %s Port:%d Address:%s Socket Count: %d Server ID:
%d",
+ name,port,addr,socket_count,server_id);
return(buff);
}
@@ -198,7 +218,7 @@
pack->type=TYPE_REQ_HEADER;
p_write_string(pack,(char *)n);
p_write_string(pack,(char *)v);
- if (n_send(conf->sock,pack)!=wa_true) {
+ if (n_send(data->sock,pack)!=wa_true) {
data->fail=wa_true;
return(FALSE);
}
@@ -212,6 +232,9 @@
wa_connection *conn=appl->conn;
warp_config *conf=(warp_config *)conn->conf;
warp_packet *pack=p_create(r->pool);
+
+ apr_socket_t * sock = NULL;
+
int status=0;
/* Check packet */
@@ -222,11 +245,14 @@
if (((int)(appl->conf))==-1)
return(wa_rerror(WA_MARK,r,404,"Application not deployed"));
+ sock = warp_sockpool_acquire(conf->socket_pool);
+
/* Attempt to reconnect if disconnected */
- if (conf->sock==NULL) {
- if (n_connect(conn)==wa_true) {
+ if (sock==NULL) {
+ sock=n_connect(conn);
+ if (sock!=NULL) {
wa_debug(WA_MARK,"Connection \"%s\" opened",conn->name);
- if (c_configure(conn)==wa_true) {
+ if (c_configure(conn,sock)==wa_true) {
wa_debug(WA_MARK,"Connection \"%s\" configured",conn->name);
} else {
wa_log(WA_MARK,"Cannot configure connection %s",conn->name);
@@ -248,11 +274,12 @@
p_write_string(pack,r->ruri);
p_write_string(pack,r->args);
p_write_string(pack,r->prot);
- if (n_send(conf->sock,pack)!=wa_true) {
- n_disconnect(conn);
- if (n_connect(conn)==wa_true) {
+ if (n_send(sock,pack)!=wa_true) {
+ n_disconnect(conn, sock);
+ sock=n_connect(conn);
+ if (sock!=NULL) {
wa_debug(WA_MARK,"Connection \"%s\" reopened",conn->name);
- if (c_configure(conn)==wa_true) {
+ if (c_configure(conn,sock)==wa_true) {
wa_debug(WA_MARK,"Connection \"%s\" reconfigured",conn->name);
} else {
wa_log(WA_MARK,"Cannot reconfigure connection %s",conn->name);
@@ -260,9 +287,10 @@
"Cannot reconfigure connection \"%s\"",
conn->name));
}
- if (n_send(conf->sock,pack)!=wa_true) {
+ if (n_send(sock,pack)!=wa_true) {
+ n_disconnect(conn, sock);
return(wa_rerror(WA_MARK,r,500,
- "Communitcation broken while reconnecting"));
+ "Communication broken while reconnecting"));
} else {
wa_debug(WA_MARK,"Re-Req. %s %s %s",r->meth,r->ruri,r->prot);
}
@@ -279,9 +307,9 @@
pack->type=TYPE_REQ_CONTENT;
p_write_string(pack,r->ctyp);
p_write_int(pack,r->clen);
- if (n_send(conf->sock,pack)!=wa_true) {
- n_disconnect(conn);
- return(wa_rerror(WA_MARK,r,500,"Communitcation interrupted"));
+ if (n_send(sock,pack)!=wa_true) {
+ n_disconnect(conn, sock);
+ return(wa_rerror(WA_MARK,r,500,"Communication interrupted"));
} else {
wa_debug(WA_MARK,"Req. content typ=%s len=%d",r->ctyp,r->clen);
}
@@ -290,9 +318,9 @@
p_reset(pack);
pack->type=TYPE_REQ_SCHEME;
p_write_string(pack,r->schm);
- if (n_send(conf->sock,pack)!=wa_true) {
- n_disconnect(conn);
- return(wa_rerror(WA_MARK,r,500,"Communitcation interrupted"));
+ if (n_send(sock,pack)!=wa_true) {
+ n_disconnect(conn,sock);
+ return(wa_rerror(WA_MARK,r,500,"Communication interrupted"));
} else {
wa_debug(WA_MARK,"Req. scheme %s",r->schm);
}
@@ -305,9 +333,9 @@
if (r->auth==NULL) r->auth="\0";
p_write_string(pack,r->user);
p_write_string(pack,r->auth);
- if (n_send(conf->sock,pack)!=wa_true) {
- n_disconnect(conn);
- return(wa_rerror(WA_MARK,r,500,"Communitcation interrupted"));
+ if (n_send(sock,pack)!=wa_true) {
+ n_disconnect(conn,sock);
+ return(wa_rerror(WA_MARK,r,500,"Communication interrupted"));
} else {
wa_debug(WA_MARK,"Req. user %s auth %s",r->user,r->auth);
}
@@ -317,10 +345,11 @@
h->conn=conn;
h->pack=pack;
h->fail=wa_false;
+ h->sock=sock;
apr_table_do(headers,h,r->hdrs,NULL);
if (h->fail==wa_true) {
- n_disconnect(conn);
- return(wa_rerror(WA_MARK,r,500,"Communitcation interrupted"));
+ n_disconnect(conn,sock);
+ return(wa_rerror(WA_MARK,r,500,"Communication interrupted"));
}
/* The request client data */
@@ -330,9 +359,9 @@
p_write_string(pack,r->clnt->host);
p_write_string(pack,r->clnt->addr);
p_write_ushort(pack,r->clnt->port);
- if (n_send(conf->sock,pack)!=wa_true) {
- n_disconnect(conn);
- return(wa_rerror(WA_MARK,r,500,"Communitcation interrupted"));
+ if (n_send(sock,pack)!=wa_true) {
+ n_disconnect(conn,sock);
+ return(wa_rerror(WA_MARK,r,500,"Communication interrupted"));
} else {
wa_debug(WA_MARK,"Req. server %s:%d (%s)",r->clnt->host,
r->clnt->port,r->clnt->addr);
@@ -346,9 +375,9 @@
p_write_string(pack,r->serv->host);
p_write_string(pack,r->serv->addr);
p_write_ushort(pack,r->serv->port);
- if (n_send(conf->sock,pack)!=wa_true) {
- n_disconnect(conn);
- return(wa_rerror(WA_MARK,r,500,"Communitcation interrupted"));
+ if (n_send(sock,pack)!=wa_true) {
+ n_disconnect(conn,sock);
+ return(wa_rerror(WA_MARK,r,500,"Communication interrupted"));
} else {
wa_debug(WA_MARK,"Req. client %s:%d (%s)",r->serv->host,
r->serv->port,r->serv->addr);
@@ -357,16 +386,16 @@
p_reset(pack);
pack->type=TYPE_REQ_PROCEED;
- if (n_send(conf->sock,pack)!=wa_true) {
- n_disconnect(conn);
- return(wa_rerror(WA_MARK,r,500,"Communitcation interrupted"));
+ if (n_send(sock,pack)!=wa_true) {
+ n_disconnect(conn,sock);
+ return(wa_rerror(WA_MARK,r,500,"Communication interrupted"));
}
while (1) {
- if (n_recv(conf->sock,pack)!=wa_true) {
- n_disconnect(conn);
- return(wa_rerror(WA_MARK,r,500,"Communitcation interrupted"));
+ if (n_recv(sock,pack)!=wa_true) {
+ n_disconnect(conn,sock);
+ return(wa_rerror(WA_MARK,r,500,"Communication interrupted"));
}
switch (pack->type) {
case TYPE_RES_STATUS: {
@@ -402,6 +431,9 @@
}
case TYPE_RES_DONE: {
wa_debug(WA_MARK,"=== DONE ===");
+ if (sock != NULL) {
+ warp_sockpool_release(conf->socket_pool, conn, sock);
+ }
return(status);
break;
}
@@ -422,9 +454,9 @@
p_write_string(pack,"Transfer interrupted");
}
wa_debug(WA_MARK,"Request body bytes: (Sent=%d)",pack->size);
- if (n_send(conf->sock,pack)!=wa_true) {
- n_disconnect(conn);
- return(wa_rerror(WA_MARK,r,500,"Communitcation interrupted"));
+ if (n_send(sock,pack)!=wa_true) {
+ n_disconnect(conn,sock);
+ return(wa_rerror(WA_MARK,r,500,"Communication interrupted"));
}
break;
}
@@ -441,9 +473,9 @@
p_write_int(pack,r->ssld->size);
}
wa_debug(WA_MARK,"CC bytes: (Sent=%d)",pack->size);
- if (n_send(conf->sock,pack)!=wa_true) {
- n_disconnect(conn);
- return(wa_rerror(WA_MARK,r,500,"Communitcation interrupted"));
+ if (n_send(sock,pack)!=wa_true) {
+ n_disconnect(conn,sock);
+ return(wa_rerror(WA_MARK,r,500,"Communication interrupted"));
}
break;
}
@@ -458,23 +490,33 @@
p_write_string(pack,r->ssld->cert);
}
wa_debug(WA_MARK,"CC bytes: (Sent=%d)",pack->size);
- if (n_send(conf->sock,pack)!=wa_true) {
- n_disconnect(conn);
- return(wa_rerror(WA_MARK,r,500,"Communitcation interrupted"));
+ if (n_send(sock,pack)!=wa_true) {
+ n_disconnect(conn,sock);
+ return(wa_rerror(WA_MARK,r,500,"Communication interrupted"));
}
break;
}
case TYPE_ERROR: {
char *mesg=NULL;
p_read_string(pack,&mesg);
+ if (sock != NULL) {
+ warp_sockpool_release(conf->socket_pool,
+ conn, sock);
+ }
return(wa_rerror(WA_MARK,r,500,"%s",mesg));
}
default: {
- n_disconnect(conn);
+ n_disconnect(conn,sock);
return(wa_rerror(WA_MARK,r,500,"Invalid packet %d",pack->type));
}
}
}
+
+ if (sock != NULL) {
+ warp_sockpool_release(conf->socket_pool, conn, sock);
+ }
+
+ return status;
}
/* The list of all configured connections */
1.9 +40 -7 jakarta-tomcat-connectors/webapp/lib/pr_warp.h
Index: pr_warp.h
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/lib/pr_warp.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- pr_warp.h 8 Aug 2001 21:04:18 -0000 1.8
+++ pr_warp.h 26 Apr 2002 13:12:35 -0000 1.9
@@ -54,7 +54,7 @@
* *
* ========================================================================= */
-/* @version $Id: pr_warp.h,v 1.8 2001/08/08 21:04:18 pier Exp $ */
+/* @version $Id: pr_warp.h,v 1.9 2002/04/26 13:12:35 jfclere Exp $ */
#ifndef _PR_WARP_H_
#define _PR_WARP_H_
@@ -74,11 +74,31 @@
/* STRUCTURES */
/* ************************************************************************* */
+/* Structure to maintain a pool of sockets to be used for a given
+ WARP connection */
+typedef struct warp_socket_pool {
+ wa_chain * available_socket_list;
+#if APR_HAS_THREADS
+ apr_thread_mutex_t * pool_mutex;
+#endif
+ int available_socket_list_size;
+ wa_chain * available_elem_blocks;
+} warp_socket_pool;
+
+
/* The WARP connection configuration structure */
typedef struct warp_config {
+ warp_socket_pool * socket_pool;
apr_sockaddr_t *addr;
- apr_socket_t *sock;
- int serv;
+
+#if APR_HAS_THREADS
+ apr_atomic_t open_socket_count;
+ apr_atomic_t serv;
+#else
+ unsigned int open_socket_count;
+ unsigned int serv;
+#endif
+
} warp_config;
/* The WARP packet structure */
@@ -95,6 +115,7 @@
wa_connection *conn;
warp_packet *pack;
wa_boolean fail;
+ apr_socket_t *sock;
} warp_header;
/* ************************************************************************* */
@@ -123,13 +144,25 @@
/* ************************************************************************* */
wa_boolean n_recv(apr_socket_t *sock, warp_packet *pack);
wa_boolean n_send(apr_socket_t *sock, warp_packet *pack);
-wa_boolean n_connect(wa_connection *conn);
-void n_disconnect(wa_connection *conn);
+apr_socket_t *n_connect(wa_connection *conn);
+void n_disconnect(wa_connection *conn, apr_socket_t * sock);
/* ************************************************************************* */
/* CONFIGURATION FUNCTIONS FROM PR_WARP_CONFIG.C */
/* ************************************************************************* */
-wa_boolean c_check(wa_connection *conn, warp_packet *pack);
-wa_boolean c_configure(wa_connection *conn);
+wa_boolean c_check(wa_connection *conn, warp_packet *pack, apr_socket_t * sock);
+wa_boolean c_configure(wa_connection *conn, apr_socket_t *sock);
+
+
+/* ************************************************************************* */
+/* SOCKET POOL FUNCTIONS FROM PR_WARP_SOCKETPOOL.C */
+/* ************************************************************************* */
+
+warp_socket_pool * warp_sockpool_create();
+void warp_sockpool_destroy(warp_socket_pool * pool);
+apr_socket_t * warp_sockpool_acquire(warp_socket_pool * pool);
+void warp_sockpool_release(warp_socket_pool * pool,
+ wa_connection *conn,
+ apr_socket_t * sock);
#endif /* ifndef _PR_WARP_H_ */
1.9 +26 -22 jakarta-tomcat-connectors/webapp/lib/pr_warp_config.c
Index: pr_warp_config.c
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/lib/pr_warp_config.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- pr_warp_config.c 9 Jan 2002 17:36:01 -0000 1.8
+++ pr_warp_config.c 26 Apr 2002 13:12:35 -0000 1.9
@@ -54,16 +54,16 @@
* *
* ========================================================================= */
-/* @version $Id: pr_warp_config.c,v 1.8 2002/01/09 17:36:01 jfclere Exp $ */
+/* @version $Id: pr_warp_config.c,v 1.9 2002/04/26 13:12:35 jfclere Exp $ */
#include "pr_warp.h"
-wa_boolean c_check(wa_connection *conn, warp_packet *pack) {
+wa_boolean c_check(wa_connection *conn, warp_packet *pack, apr_socket_t * sock) {
warp_config *conf=(warp_config *)conn->conf;
int maj=-1;
int min=-1;
int sid=-1;
- if (n_recv(conf->sock,pack)!=wa_true) {
+ if (n_recv(sock,pack)!=wa_true) {
wa_log(WA_MARK,"Cannot receive handshake WARP packet");
return(wa_false);
}
@@ -93,14 +93,18 @@
return(wa_false);
}
- conf->serv=sid;
+#if APR_HAS_THREADS
+ apr_atomic_set(&conf->serv, (unsigned) sid);
+#else
+ conf->serv = (unsigned) sid;
+#endif
+
wa_debug(WA_MARK,"Connection \"%s\" checked WARP/%d.%d (SERVER ID=%d)",
conn->name,maj,min,conf->serv);
return(wa_true);
}
-wa_boolean c_configure(wa_connection *conn) {
- warp_config *conf=(warp_config *)conn->conf;
+wa_boolean c_configure(wa_connection *conn, apr_socket_t * sock) {
wa_chain *elem=warp_applications;
apr_pool_t *pool=NULL;
wa_boolean ret=wa_false;
@@ -109,18 +113,18 @@
if (apr_pool_create(&pool,wa_pool)!=APR_SUCCESS) {
wa_log(WA_MARK,"Cannot create WARP temporary configuration pool");
- n_disconnect(conn);
+ n_disconnect(conn, sock);
return(wa_false);
}
if ((pack=p_create(wa_pool))==NULL) {
wa_log(WA_MARK,"Cannot create WARP configuration packet");
- n_disconnect(conn);
+ n_disconnect(conn, sock);
apr_pool_destroy(pool);
return(wa_false);
}
- if ((ret=c_check(conn,pack))==wa_false) n_disconnect(conn);
+ if ((ret=c_check(conn,pack, sock))==wa_false) n_disconnect(conn, sock);
while (elem!=NULL) {
wa_application *appl=(wa_application *)elem->curr;
@@ -140,11 +144,11 @@
p_write_string(pack,appl->host->name);
p_write_ushort(pack,appl->host->port);
p_write_string(pack,appl->rpth);
- n_send(conf->sock,pack);
+ n_send(sock,pack);
- if (n_recv(conf->sock,pack)!=wa_true) {
+ if (n_recv(sock,pack)!=wa_true) {
wa_log(WA_MARK,"Cannot read packet (%s:%d)",WA_MARK);
- n_disconnect(conn);
+ n_disconnect(conn, sock);
return(wa_false);
}
if (pack->type==TYPE_ERROR) {
@@ -157,8 +161,8 @@
p_reset(pack);
pack->type=TYPE_FATAL;
p_write_string(pack,"Invalid packet received");
- n_send(conf->sock,pack);
- n_disconnect(conn);
+ n_send(sock,pack);
+ n_disconnect(conn, sock);
}
p_read_int(pack,(int *)&appl->conf);
p_read_string(pack,&temp);
@@ -183,12 +187,12 @@
p_reset(pack);
pack->type=TYPE_CONF_MAP;
p_write_int(pack,(int)appl->conf);
- n_send(conf->sock,pack);
+ n_send(sock,pack);
while(1) {
- if (n_recv(conf->sock,pack)!=wa_true) {
+ if (n_recv(sock,pack)!=wa_true) {
wa_log(WA_MARK,"Cannot read packet (%s:%d)",WA_MARK);
- n_disconnect(conn);
+ n_disconnect(conn,sock);
return(wa_false);
}
if (pack->type==TYPE_CONF_MAP_DONE) {
@@ -220,11 +224,11 @@
p_reset(pack);
pack->type=TYPE_CONF_DONE;
- n_send(conf->sock,pack);
+ n_send(sock,pack);
- if (n_recv(conf->sock,pack)!=wa_true) {
+ if (n_recv(sock,pack)!=wa_true) {
wa_log(WA_MARK,"Cannot read packet (%s:%d)",WA_MARK);
- n_disconnect(conn);
+ n_disconnect(conn,sock);
return(wa_false);
}
if (pack->type!=TYPE_CONF_PROCEED) {
@@ -232,8 +236,8 @@
p_reset(pack);
pack->type=TYPE_FATAL;
p_write_string(pack,"Expected PROCEED packet not received");
- n_send(conf->sock,pack);
- n_disconnect(conn);
+ n_send(sock,pack);
+ n_disconnect(conn,sock);
return(wa_false);
}
1.6 +26 -22 jakarta-tomcat-connectors/webapp/lib/pr_warp_network.c
Index: pr_warp_network.c
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/lib/pr_warp_network.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- pr_warp_network.c 26 Jul 2001 15:39:37 -0000 1.5
+++ pr_warp_network.c 26 Apr 2002 13:12:35 -0000 1.6
@@ -54,7 +54,7 @@
* *
* ========================================================================= */
-/* @version $Id: pr_warp_network.c,v 1.5 2001/07/26 15:39:37 pier Exp $ */
+/* @version $Id: pr_warp_network.c,v 1.6 2002/04/26 13:12:35 jfclere Exp $ */
#include "pr_warp.h"
wa_boolean n_recv(apr_socket_t *sock, warp_packet *pack) {
@@ -137,54 +137,58 @@
/* Attempt to connect to the remote endpoint of the WARP connection (if not
done already). */
-wa_boolean n_connect(wa_connection *conn) {
+apr_socket_t *n_connect(wa_connection *conn) {
warp_config *conf=(warp_config *)conn->conf;
apr_status_t ret=APR_SUCCESS;
+ apr_socket_t *sock=NULL;
- /* Create the APR socket if that has not been yet created */
- if (conf->sock!=NULL) {
- wa_debug(WA_MARK,"Connection \"%s\" already opened",conn->conf);
- return(wa_true);
- }
-
- ret=apr_socket_create(&conf->sock,AF_INET,SOCK_STREAM,wa_pool);
+ ret=apr_socket_create(&sock,AF_INET,SOCK_STREAM,wa_pool);
if (ret!=APR_SUCCESS) {
- conf->sock=NULL;
+ sock=NULL;
wa_log(WA_MARK,"Cannot create socket for conn. \"%s\"",conn->name);
- return(wa_false);
+ return(sock);
}
/* Attempt to connect to the remote endpoint */
- ret=apr_connect(conf->sock, conf->addr);
+ ret=apr_connect(sock, conf->addr);
if (ret!=APR_SUCCESS) {
- apr_shutdown(conf->sock,APR_SHUTDOWN_READWRITE);
- conf->sock=NULL;
+ apr_shutdown(sock,APR_SHUTDOWN_READWRITE);
+ sock=NULL;
wa_log(WA_MARK,"Connection \"%s\" cannot connect",conn->name);
- return(wa_false);
+ return(sock);
}
- return(wa_true);
+#if APR_HAS_THREADS
+ apr_atomic_inc(&conf->open_socket_count);
+#else
+ conf->open_socket_count++;
+#endif
+
+ return(sock);
}
/* Attempt to disconnect a connection if connected. */
-void n_disconnect(wa_connection *conn) {
+void n_disconnect(wa_connection *conn, apr_socket_t * sock) {
warp_config *conf=(warp_config *)conn->conf;
apr_status_t ret=APR_SUCCESS;
wa_debug(WA_MARK,"Disconnecting \"%s\"",conn->name);
/* Create the APR socket if that has not been yet created */
- if (conf->sock==NULL) return;
+ if (sock==NULL) return;
/* Shutdown and close the socket (ignoring errors) */
- ret=apr_shutdown(conf->sock,APR_SHUTDOWN_READWRITE);
+ ret=apr_shutdown(sock,APR_SHUTDOWN_READWRITE);
if (ret!=APR_SUCCESS)
wa_log(WA_MARK,"Cannot shutdown \"%s\"",conn->name);
- ret=apr_socket_close(conf->sock);
+ ret=apr_socket_close(sock);
if (ret!=APR_SUCCESS)
wa_log(WA_MARK,"Cannot close \"%s\"",conn->name);
- /* Reset the state */
- conf->sock=NULL;
+#if APR_HAS_THREADS
+ apr_atomic_dec(&conf->open_socket_count);
+#else
+ conf->open_socket_count--;
+#endif
}
1.11 +5 -1 jakarta-tomcat-connectors/webapp/lib/wa_main.c
Index: wa_main.c
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/lib/wa_main.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- wa_main.c 4 Aug 2001 18:25:57 -0000 1.10
+++ wa_main.c 26 Apr 2002 13:12:35 -0000 1.11
@@ -55,7 +55,7 @@
* *
* ========================================================================= */
-/* @version $Id: wa_main.c,v 1.10 2001/08/04 18:25:57 pier Exp $ */
+/* @version $Id: wa_main.c,v 1.11 2002/04/26 13:12:35 jfclere Exp $ */
#include <wa.h>
/* The current APR memory pool. */
@@ -85,6 +85,10 @@
return("Cannot create WebApp Library memory pool");
if (wa_pool==NULL)
return("Invalid WebApp Library memory pool created");
+#if APR_HAS_THREADS
+ if (apr_atomic_init(wa_pool)!=APR_SUCCESS)
+ return("Cannot initialize atomic integer library");
+#endif
}
/* Initialize providers */
1.1 jakarta-tomcat-connectors/webapp/lib/pr_warp_socketpool.c
Index: pr_warp_socketpool.c
===================================================================
/* ========================================================================= *
* *
* The Apache Software License, Version 1.1 *
* *
* Copyright (c) 1999-2001 The Apache Software Foundation. *
* All rights reserved. *
* *
* ========================================================================= *
* *
* Redistribution and use in source and binary forms, with or without modi- *
* fication, are permitted provided that the following conditions are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice *
* notice, this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. The end-user documentation included with the redistribution, if any, *
* must include the following acknowlegement: *
* *
* "This product includes software developed by the Apache Software *
* Foundation <http://www.apache.org/>." *
* *
* Alternately, this acknowlegement may appear in the software itself, if *
* and wherever such third-party acknowlegements normally appear. *
* *
* 4. The names "The Jakarta Project", "WebApp", and "Apache Software *
* Foundation" must not be used to endorse or promote products derived *
* from this software without prior written permission. For written *
* permission, please contact <[EMAIL PROTECTED]>. *
* *
* 5. Products derived from this software may not be called "Apache" nor may *
* "Apache" appear in their names without prior written permission of the *
* Apache Software Foundation. *
* *
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY *
* THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY *
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS *
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, *
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
* ========================================================================= *
* *
* This software consists of voluntary contributions made by many indivi- *
* duals on behalf of the Apache Software Foundation. For more information *
* on the Apache Software Foundation, please see <http://www.apache.org/>. *
* *
* ========================================================================= */
#include "pr_warp.h"
/* Define the maximum number of idle sockets to leave aside for a connection */
#if APR_HAS_THREADS
#define MAX_SOCKET_POOL_SIZE 25
#else
#define MAX_SOCKET_POOL_SIZE 1
#endif
/* Create a warp socket pool. A warp socket pool is a pool of connected, free
sockets for a given warp connection. */
warp_socket_pool * warp_sockpool_create()
{
int idx;
warp_socket_pool * pool =
(warp_socket_pool*)apr_palloc(wa_pool,sizeof(warp_socket_pool));
/* Start the pool with no available sockets. */
pool->available_socket_list = NULL;
pool->available_socket_list_size = 0;
/* Create mutex to provide thread-safe access to socket pool. */
#if APR_HAS_THREADS
if (apr_thread_mutex_create(&pool->pool_mutex,
APR_THREAD_MUTEX_DEFAULT,
wa_pool) !=APR_SUCCESS)
return 0;
#endif
/* Set up array of wa_chain elements to be used later for elements in the
available socket list. By allocating them up front we avoid the use
of malloc and free during normal operation. */
pool->available_elem_blocks =
(wa_chain*)apr_palloc(wa_pool,sizeof(wa_chain)*MAX_SOCKET_POOL_SIZE);
/* From the array create a linked-list. */
for (idx = 0; idx < MAX_SOCKET_POOL_SIZE - 1; idx++) {
pool->available_elem_blocks[idx].next =
& pool->available_elem_blocks[idx+1];
}
pool->available_elem_blocks[idx-1].next = NULL;
return pool;
}
/* Destroy the socket pool specified. */
void warp_sockpool_destroy(warp_socket_pool * pool)
{
apr_status_t ret = APR_SUCCESS;
apr_socket_t * sock = NULL;
wa_chain *elem = pool->available_socket_list;
/* Destroy mutex associated with the pool */
#if APR_HAS_THREADS
ret = apr_thread_mutex_destroy(pool->pool_mutex);
pool->pool_mutex = NULL;
#endif
if (ret!=APR_SUCCESS)
wa_log(WA_MARK,"Cannot destroy socket pool mutex");
/* Destroy all the sockets in the pool */
while (elem != NULL) {
sock = (apr_socket_t*) elem->curr;
if (sock != NULL) {
ret = apr_shutdown(sock, APR_SHUTDOWN_READWRITE);
ret = apr_socket_close(sock);
}
elem->curr = NULL;
elem = elem->next;
}
pool->available_socket_list_size = 0;
pool->available_socket_list = NULL;
}
/* Acquire a socket from the socket pool specified. If there
are no available sockets in the pool then NULL is returned. */
apr_socket_t * warp_sockpool_acquire(warp_socket_pool * pool)
{
apr_socket_t * sock = NULL;
wa_chain * first_elem = 0;
if (pool->available_socket_list_size > 0)
{
/* Preliminary check of available_socket_list_size suggests
that there is an available socket in the pool. Lock the
pool and then check again. */
#if APR_HAS_THREADS
if (apr_thread_mutex_lock(pool->pool_mutex) != APR_SUCCESS)
return NULL;
#endif
if (pool->available_socket_list_size > 0)
{
/* There is an available socket in the pool. Get
one from the pool. */
first_elem = pool->available_socket_list;
/* Update the available socket list. */
pool->available_socket_list_size--;
pool->available_socket_list = first_elem->next;
/* Extract the socket from first_elem. */
sock = (apr_socket_t*) first_elem->curr;
/* Put the now unused first_elem block in the
available elem list so it can be later reused. */
first_elem->curr = 0;
first_elem->next = pool->available_elem_blocks;
pool->available_elem_blocks = first_elem;
}
#if APR_HAS_THREADS
apr_thread_mutex_unlock(pool->pool_mutex);
#endif
}
return sock;
}
/* Returns the socket specified to socket pool. If the pool already contains
the maximum allowable number of sockets for a pool (MAX_SOCKET_POOL_SIZE)
then the socket is simply disconnected. */
void warp_sockpool_release(warp_socket_pool * pool,
wa_connection *conn,
apr_socket_t * sock)
{
wa_chain * new_elem = NULL;
#if APR_HAS_THREADS
if (apr_thread_mutex_lock(pool->pool_mutex) != APR_SUCCESS)
return;
#endif
/* If we already have the maximum number of available sockets in
the pool then just disconnect the socket and return */
if (pool->available_socket_list_size==MAX_SOCKET_POOL_SIZE) {
#if APR_HAS_THREADS
apr_thread_mutex_unlock(pool->pool_mutex);
#endif
n_disconnect(conn, sock);
return;
}
/* Add the socket given to the pool...*/
pool->available_socket_list_size++;
/* Get a new pool element from the available list. */
new_elem = pool->available_elem_blocks;
pool->available_elem_blocks = new_elem->next;
/* Initialise the new pool element. */
new_elem->curr = sock;
new_elem->next = pool->available_socket_list;
/* Add the element to the head of the available
socket list. */
pool->available_socket_list = new_elem;
#if APR_HAS_THREADS
apr_thread_mutex_unlock(pool->pool_mutex);
#endif
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>