cvs commit: jakarta-tomcat-connectors/jk/src/native/common jk_ajp13_worker.c jk_ajp13_worker.h

2001-06-07 Thread hgomez

hgomez  01/06/07 07:33:07

  Modified:jk/src/native/common jk_ajp13_worker.c jk_ajp13_worker.h
  Log:
  ajp13_worker also on the Diet.
  code is shared with ajp14 and live in ajp_common :=)
  
  Revision  ChangesPath
  1.4   +25 -683   jakarta-tomcat-connectors/jk/src/native/common/jk_ajp13_worker.c
  
  Index: jk_ajp13_worker.c
  ===
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/jk/src/native/common/jk_ajp13_worker.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- jk_ajp13_worker.c 2001/06/01 09:59:47 1.3
  +++ jk_ajp13_worker.c 2001/06/07 14:33:02 1.4
  @@ -58,288 +58,18 @@
* Author:  Henri Gomez <[EMAIL PROTECTED]>   *
* Author:  Costin <[EMAIL PROTECTED]>  *
* Author:  Gal Shachor <[EMAIL PROTECTED]>   *
  - * Version: $Revision: 1.3 $   *
  + * Version: $Revision: 1.4 $   *
***/
   
   #include "jk_ajp13_worker.h"
   
   
  -static void reset_endpoint(ajp13_endpoint_t *ep)
  -{
  -ep->reuse = JK_FALSE; 
  -jk_reset_pool(&(ep->pool));
  -}
  -
  -static void close_endpoint(ajp13_endpoint_t *ep)
  -{
  -reset_endpoint(ep);
  - jk_close_pool(&(ep->pool));
  -
  -if(ep->sd > 0) {
  -jk_close_socket(ep->sd);
  -} 
  -free(ep);
  -}
  -
  -
  -static void reuse_connection(ajp13_endpoint_t *ep,
  - jk_logger_t *l)
  -{
  -ajp13_worker_t *w = ep->worker;
  -
  -if(w->ep_cache_sz) {
  -int rc;
  -JK_ENTER_CS(&w->cs, rc);
  -if(rc) {
  -unsigned i;
  -
  -for(i = 0 ; i < w->ep_cache_sz ; i++) {
  -if(w->ep_cache[i]) {
  -ep->sd = w->ep_cache[i]->sd;
  -w->ep_cache[i]->sd = -1;
  -close_endpoint(w->ep_cache[i]);
  -w->ep_cache[i] = NULL;
  -break;
  - }
  -}
  -JK_LEAVE_CS(&w->cs, rc);
  -}
  -}
  -}
  -
  -static void connect_to_tomcat(ajp13_endpoint_t *ep,
  -  jk_logger_t *l)
  -{
  -unsigned attempt;
  -
  -for(attempt = 0 ; attempt < ep->worker->connect_retry_attempts ; attempt++) {
  -ep->sd = jk_open_socket(&ep->worker->worker_inet_addr, JK_TRUE, l);
  -if(ep->sd >= 0) {
  -jk_log(l, JK_LOG_DEBUG, "In jk_endpoint_t::connect_to_tomcat, connected 
sd = %d\n", ep->sd);
  -return;
  -}
  -}
  -
  -jk_log(l, JK_LOG_ERROR, "In jk_endpoint_t::connect_to_tomcat, failed errno = 
%d\n", errno);
  -}
  -
  -static int connection_tcp_send_message(ajp13_endpoint_t *ep, 
  -   jk_msg_buf_t *msg, 
  -   jk_logger_t *l ) 
  -{
  -jk_b_end(msg);
  -
  -jk_dump_buff(l, JK_LOG_DEBUG, "sending to ajp13", msg);
  -
  -if(0 > jk_tcp_socket_sendfull(ep->sd, jk_b_get_buff(msg), jk_b_get_len(msg))) {
  -return JK_FALSE;
  -}
  -
  -return JK_TRUE;
  -}
  -
  -static int connection_tcp_get_message(ajp13_endpoint_t *ep, 
  -  jk_msg_buf_t *msg, 
  -  jk_logger_t *l) 
  -{
  -unsigned char head[AJP13_HEADER_LEN];
  -int rc;
  -int msglen;
  -
  -rc = jk_tcp_socket_recvfull(ep->sd, head, AJP13_HEADER_LEN);
  -
  -if(rc < 0) {
  -jk_log(l, JK_LOG_ERROR, "connection_tcp_get_message: Error - 
jk_tcp_socket_recvfull failed\n");
  -return JK_FALSE;
  -}
  -
  -if((head[0] != 'A') || (head[1] != 'B' )) {
  -jk_log(l, JK_LOG_ERROR, "connection_tcp_get_message: Error - Wrong message 
format\n");
  - return JK_FALSE;
  -}
  -
  -msglen  = ((head[2]&0xff)<<8);
  -msglen += (head[3] & 0xFF);
  -
  -if(msglen > jk_b_get_size(msg)) {
  -jk_log(l, JK_LOG_ERROR, "connection_tcp_get_message: Error - Wrong message 
size\n");
  - return JK_FALSE;
  -}
  -
  -jk_b_set_len(msg, msglen);
  -jk_b_set_pos(msg, 0); 
  -
  -rc = jk_tcp_socket_recvfull(ep->sd, jk_b_get_buff(msg), msglen);
  -if(rc < 0) {
  -jk_log(l, JK_LOG_ERROR, "connection_tcp_get_message: Error - 
jk_tcp_socket_recvfull failed\n");
  -return JK_FALSE;
  -}
  -
  -jk_dump_buff(l, JK_LOG_DEBUG, "received from ajp13", msg);
  -return JK_TRUE;
  -}
  -
  -static int read_fully_from_server(jk_ws_service_t *s, 
  -  unsigned char *buf, 
  -  unsigned len)
  -{
  -unsigned rdlen = 0;
  -
  -while(rdlen < len) {
  -  

cvs commit: jakarta-tomcat-connectors/jk/src/native/common jk_ajp13_worker.c

2001-06-01 Thread hgomez

hgomez  01/06/01 02:59:47

  Modified:jk/src/native/common jk_ajp13_worker.c
  Log:
  Memory leaks fixes from Mike Anderson
  Code cleanup (who still use 80 cols today ?)
  
  Revision  ChangesPath
  1.3   +32 -68jakarta-tomcat-connectors/jk/src/native/common/jk_ajp13_worker.c
  
  Index: jk_ajp13_worker.c
  ===
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/jk/src/native/common/jk_ajp13_worker.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- jk_ajp13_worker.c 2001/05/18 16:45:04 1.2
  +++ jk_ajp13_worker.c 2001/06/01 09:59:47 1.3
  @@ -58,7 +58,7 @@
* Author:  Henri Gomez <[EMAIL PROTECTED]>   *
* Author:  Costin <[EMAIL PROTECTED]>  *
* Author:  Gal Shachor <[EMAIL PROTECTED]>   *
  - * Version: $Revision: 1.2 $   *
  + * Version: $Revision: 1.3 $   *
***/
   
   #include "jk_ajp13_worker.h"
  @@ -73,6 +73,8 @@
   static void close_endpoint(ajp13_endpoint_t *ep)
   {
   reset_endpoint(ep);
  + jk_close_pool(&(ep->pool));
  +
   if(ep->sd > 0) {
   jk_close_socket(ep->sd);
   } 
  @@ -111,20 +113,14 @@
   unsigned attempt;
   
   for(attempt = 0 ; attempt < ep->worker->connect_retry_attempts ; attempt++) {
  -ep->sd = jk_open_socket(&ep->worker->worker_inet_addr, 
  -   JK_TRUE, 
  -   l);
  +ep->sd = jk_open_socket(&ep->worker->worker_inet_addr, JK_TRUE, l);
   if(ep->sd >= 0) {
  -jk_log(l, 
  -   JK_LOG_DEBUG, 
  -   "In jk_endpoint_t::connect_to_tomcat, connected sd = %d\n", 
ep->sd);
  +jk_log(l, JK_LOG_DEBUG, "In jk_endpoint_t::connect_to_tomcat, connected 
sd = %d\n", ep->sd);
   return;
   }
   }
   
  -jk_log(l, 
  -   JK_LOG_ERROR, 
  -   "In jk_endpoint_t::connect_to_tomcat, failed errno = %d\n", errno);
  +jk_log(l, JK_LOG_ERROR, "In jk_endpoint_t::connect_to_tomcat, failed errno = 
%d\n", errno);
   }
   
   static int connection_tcp_send_message(ajp13_endpoint_t *ep, 
  @@ -135,9 +131,7 @@
   
   jk_dump_buff(l, JK_LOG_DEBUG, "sending to ajp13", msg);
   
  -if(0 > jk_tcp_socket_sendfull(ep->sd, 
  -  jk_b_get_buff(msg),
  -  jk_b_get_len(msg))) {
  +if(0 > jk_tcp_socket_sendfull(ep->sd, jk_b_get_buff(msg), jk_b_get_len(msg))) {
   return JK_FALSE;
   }
   
  @@ -155,14 +149,12 @@
   rc = jk_tcp_socket_recvfull(ep->sd, head, AJP13_HEADER_LEN);
   
   if(rc < 0) {
  -jk_log(l, JK_LOG_ERROR, 
  -   "connection_tcp_get_message: Error - jk_tcp_socket_recvfull 
failed\n");
  +jk_log(l, JK_LOG_ERROR, "connection_tcp_get_message: Error - 
jk_tcp_socket_recvfull failed\n");
   return JK_FALSE;
   }
   
   if((head[0] != 'A') || (head[1] != 'B' )) {
  -jk_log(l, JK_LOG_ERROR, 
  -   "connection_tcp_get_message: Error - Wrong message format\n");
  +jk_log(l, JK_LOG_ERROR, "connection_tcp_get_message: Error - Wrong message 
format\n");
return JK_FALSE;
   }
   
  @@ -170,8 +162,7 @@
   msglen += (head[3] & 0xFF);
   
   if(msglen > jk_b_get_size(msg)) {
  -jk_log(l, JK_LOG_ERROR, 
  -   "connection_tcp_get_message: Error - Wrong message size\n");
  +jk_log(l, JK_LOG_ERROR, "connection_tcp_get_message: Error - Wrong message 
size\n");
return JK_FALSE;
   }
   
  @@ -180,8 +171,7 @@
   
   rc = jk_tcp_socket_recvfull(ep->sd, jk_b_get_buff(msg), msglen);
   if(rc < 0) {
  -jk_log(l, JK_LOG_ERROR, 
  -   "connection_tcp_get_message: Error - jk_tcp_socket_recvfull 
failed\n");
  +jk_log(l, JK_LOG_ERROR, "connection_tcp_get_message: Error - 
jk_tcp_socket_recvfull failed\n");
   return JK_FALSE;
   }
   
  @@ -224,16 +214,14 @@
   read_buf += AJP13_HEADER_SZ_LEN; /* leave some space for the read length */
   
   if(read_fully_from_server(r, read_buf, len) < 0) {
  -jk_log(l, JK_LOG_ERROR, 
  -   "read_into_msg_buff: Error - read_fully_from_server failed\n");
  +jk_log(l, JK_LOG_ERROR, "read_into_msg_buff: Error - read_fully_from_server 
failed\n");
   return JK_FALSE;
   } 
   
   ep->left_bytes_to_send -= len;
   
   if(0 != jk_b_append_int(msg, (unsigned short)len)) {
  -jk_log(l, JK_LOG_ERROR, 
  -   "read_into_msg_buff: Error - jk_b_append_int failed\n");
  +jk_log(l, JK_LOG_ERROR, "read_in

cvs commit: jakarta-tomcat-connectors/jk/src/native/common jk_ajp13_worker.c jk_ajp13_worker.h

2001-05-14 Thread hgomez

hgomez  01/05/14 02:33:13

  Added:   jk/src/native/common jk_ajp13_worker.c jk_ajp13_worker.h
  Log:
  ajp13 worker stuff
  
  Revision  ChangesPath
  1.1  jakarta-tomcat-connectors/jk/src/native/common/jk_ajp13_worker.c
  
  Index: jk_ajp13_worker.c
  ===
  /*
   * Copyright (c) 1997-2001 The Java Apache Project.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *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. All advertising materials mentioning features or use of this
   *software must display the following acknowledgment:
   *"This product includes software developed by the Java Apache 
   *Project for use in the Apache JServ servlet engine project
   *."
   *
   * 4. The names "Apache JServ", "Apache JServ Servlet Engine" and 
   *"Java Apache Project" must not be used to endorse or promote products 
   *derived from this software without prior written permission.
   *
   * 5. Products derived from this software may not be called "Apache JServ"
   *nor may "Apache" nor "Apache JServ" appear in their names without 
   *prior written permission of the Java Apache Project.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *acknowledgment:
   *"This product includes software developed by the Java Apache 
   *Project for use in the Apache JServ servlet engine project
   *."
   *
   * THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "AS IS" AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE JAVA APACHE PROJECT 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
   * individuals on behalf of the Java Apache Group. For more information
   * on the Java Apache Project and the Apache JServ Servlet Engine project,
   * please see .
   *
   */
  
  /***
   * Description: Bi-directional protocol.   *
   * Author:  Henri Gomez <[EMAIL PROTECTED]>   *
   * Author:  Costin <[EMAIL PROTECTED]>  *
   * Author:  Gal Shachor <[EMAIL PROTECTED]>   *
   * Version: $Revision: 1.1 $   *
   ***/
  
  #include "jk_pool.h"
  #include "jk_connect.h"
  #include "jk_util.h"
  #include "jk_msg_buff.h"
  #include "jk_ajp13.h"
  #include "jk_mt.h"
  
  #define AJP_DEF_HOST("localhost")
  #define AJP_DEF_PORT(8008)
  #define READ_BUF_SIZE   (8*1024)
  #define DEF_RETRY_ATTEMPTS  (1)
  #define DEF_CACHE_SZ(1)
  #define JK_INTERNAL_ERROR   (-2)
  #define MAX_SEND_BODY_SZ(DEF_BUFFER_SZ - 6)
  #define AJP13_HEADER_LEN  (4)
  #define AJP13_HEADER_SZ_LEN   (2)
  
  struct ajp13_operation;
  typedef struct ajp13_operation ajp13_operation_t;
  
  struct ajp13_endpoint;
  typedef struct ajp13_endpoint ajp13_endpoint_t;
  
  struct ajp13_worker {
  struct sockaddr_in worker_inet_addr; /* Contains host and port */
  unsigned connect_retry_attempts;
  char *name; 
  
  /*
   * Open connections cache...
   *
   * 1. Critical section object to protect the cache.
   * 2. Cache size.
   * 3. An array of "open" endpoints.
   */
  JK_CRIT_SEC cs;
  unsigned ep_cache_sz;
  ajp13_endpoint_t **ep_cache;
  
  jk_worker_t worker; 
  };
  typedef struct ajp13_worker ajp13_worker_t;
  
  struct ajp13_endpoint { 
  ajp13_worker_t *worker;
  
  jk_pool_t pool;
  jk_pool_atom_t buf[BIG_POOL_SIZE];
  
  int sd;