Index: jk_channel_apr_socket.c
===================================================================
RCS file: /home/cvspublic/jakarta-tomcat-connectors/jk/native2/common/jk_channel_apr_socket.c,v
retrieving revision 1.22
diff -u -3 -r1.22 jk_channel_apr_socket.c
--- jk_channel_apr_socket.c	10 Jun 2002 21:55:06 -0000	1.22
+++ jk_channel_apr_socket.c	27 Jun 2002 12:39:42 -0000
@@ -88,6 +88,8 @@
     apr_sockaddr_t *addr;
     char *host;
     short port;
+    int keepalive;
+    int timeout;
 };
 
 typedef struct jk_channel_apr_private jk_channel_apr_private_t;
@@ -121,6 +123,13 @@
         socketInfo->host=value;
     } else if( strcmp( "port", name ) == 0 ) {
         socketInfo->port=atoi( value );
+    } else if( strcmp( "keepalive", name ) == 0 ) {
+        if (!strcasecmp(value, "on"))
+            socketInfo->keepalive=JK_TRUE;
+        else
+            socketInfo->keepalive=JK_FALSE;
+    } else if( strcmp( "timeout", name ) == 0 ) {
+        socketInfo->timeout=atoi( value );
     } else {
         return jk2_channel_setAttribute( env, mbean, name, valueP );
     }
@@ -206,10 +215,11 @@
 
     apr_sockaddr_t *remote_sa=socketInfo->addr;
     int ndelay=socketInfo->ndelay;
+    int keepalive=socketInfo->keepalive;
 
     apr_socket_t *sock=endpoint->channelData;
     apr_status_t ret;
-    apr_interval_time_t timeout = 2 * APR_USEC_PER_SEC;
+    apr_int32_t timeout = socketInfo->timeout * APR_USEC_PER_SEC;
     char msg[128];
 
     if (apr_socket_create(&sock, remote_sa->family, SOCK_STREAM,
@@ -250,6 +260,16 @@
         return JK_ERR;
     }
 
+    if(keepalive) {
+        int set = 1;
+        if((ret = apr_setsocketopt(sock, APR_SO_KEEPALIVE, set)) != APR_SUCCESS ) {
+            apr_socket_close(sock);
+            env->l->jkLog(env, env->l, JK_LOG_ERROR,
+                          "channelApr.connect() keepalive failed %d %s\n",
+                          ret, apr_strerror( ret, msg, sizeof(msg) ) );
+            return JK_ERR;                        
+        }
+    }
     /* XXX needed?
     if(ndelay) {
         int set = 1;
@@ -421,11 +441,13 @@
                                              const char *type, const char *name)
 {
     jk_channel_t *ch;
-    
+    jk_channel_apr_private_t *priv;
+
     ch=(jk_channel_t *)pool->calloc(env, pool, sizeof( jk_channel_t));
     
-    ch->_privatePtr= (jk_channel_apr_private_t *)
+    priv= (jk_channel_apr_private_t *)
         pool->calloc( env, pool, sizeof( jk_channel_apr_private_t));
+    priv->timeout = 2;
 
     ch->recv= jk2_channel_apr_recv; 
     ch->send= jk2_channel_apr_send; 
@@ -440,7 +462,7 @@
 
     ch->workerEnv=env->getByName( env, "workerEnv" );
     ch->workerEnv->addChannel( env, ch->workerEnv, ch );
-
+    ch->_privatePtr = priv;
     return JK_OK;
 }
 #else /* HAS_APR */

