tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GOMEZ Henri <hgo...@slib.fr>
Subject [J-T-C] Apache 2.0 code review required
Date Fri, 14 Sep 2001 22:50:27 GMT
Hi to all,

I've just commited updated code for Apache 1.3/2.0
 
I will need a serious code review on Apache 2.0 part
and particulary the ws_read() which was grabbed from
1.3 and works (at least on Apache 2.0.24) but may 
be optimized...

===>

static int JK_METHOD ws_read(jk_ws_service_t *s,
                             void *b,
                             unsigned len,
                             unsigned *actually_read)
{
    if(s && s->ws_private && b && actually_read) {
        apache_private_data_t *p = s->ws_private;
        if(!p->read_body_started) {
           if(ap_should_client_block(p->r)) {
                p->read_body_started = JK_TRUE;
            }
        }

        if(p->read_body_started) {
            long rv;
            if ((rv = ap_get_client_block(p->r, b, len)) < 0) {
                *actually_read = 0;
            } else {
                *actually_read = (unsigned) rv;
            }
            return JK_TRUE;
        }
    }
    return JK_FALSE;
}

also is jk_handler we now use :

    /* Set up r->read_chunked flags for chunked encoding, if present */
    if(rc = ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK)) {
    return rc;
    }

ws_write() could need also a serious cleanup and see if the 
CHUNK_SIZE of 4k is still valid.

/* Works with 4096, fails with 8192 */
#define CHUNK_SIZE 4096

static int JK_METHOD ws_write(jk_ws_service_t *s,
                              const void *b,
                              unsigned l)
{
    if(s && s->ws_private && b) {
        apache_private_data_t *p = s->ws_private;

        if(l) {
            /* BUFF *bf = p->r->connection->client; */
            size_t w = (size_t)l;
            size_t r = 0;
            long ll=l;
            char *bb=(char *)b;
            
            if(!p->response_started) {
                if(!s->start_response(s, 200, NULL, NULL, NULL, 0)) {
                    return JK_FALSE;
                }
            }
            
            /* Debug - try to get around rwrite */
            while( ll > 0 ) {
                long toSend=(ll>CHUNK_SIZE) ? CHUNK_SIZE : ll;
                r = ap_rwrite((const char *)bb, toSend, p->r );
                /* DEBUG */
#ifdef JK_DEBUG
                ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, 
                             NULL, "mod_jk: writing %ld (%ld) out of %ld
\n",
                             toSend, r, ll );
#endif
                ll-=CHUNK_SIZE;
                bb+=CHUNK_SIZE;
                
                if(toSend != r) { 
                    return JK_FALSE; 
                } 
                
                /*
                 * To allow server push.
                 */
                if(ap_rflush(p->r) != APR_SUCCESS) {
                    ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO,
0, 
                                 NULL, "mod_jk: Error flushing \n"  );
                    return JK_FALSE;
                }
            }
        }
        
        return JK_TRUE;
    }
    return JK_FALSE;
}

I'm sure that our residents AP2.0 hackers, Ryan and JF, will
handle the task brillament :)

-
Henri Gomez                 ___[_]____
EMAIL : hgomez@slib.fr        (. .)                     
PGP KEY : 697ECEDD    ...oOOo..(_)..oOOo...
PGP Fingerprint : 9DF8 1EA8 ED53 2F39 DC9B 904A 364F 80E6 

Mime
View raw message