Most RPC requests do not need a full fragment, start smaller
authorVolker Lendecke <vl@samba.org>
Sat, 7 Feb 2009 22:36:23 +0000 (23:36 +0100)
committerVolker Lendecke <vl@samba.org>
Sun, 8 Feb 2009 12:53:49 +0000 (13:53 +0100)
source3/rpc_parse/parse_prs.c
source3/rpc_server/srv_pipe_hnd.c

index e8103ad866b85cae7e16daa780571c8ff40703b9..bc9202ccccfd605317e33ec2cda6f8886b44f555 100644 (file)
@@ -267,12 +267,12 @@ bool prs_grow(prs_struct *ps, uint32 extra_space)
 
        extra_space -= (ps->buffer_size - ps->data_offset);
        if(ps->buffer_size == 0) {
+
                /*
-                * Ensure we have at least a PDU's length, or extra_space, whichever
-                * is greater.
+                * Start with 128 bytes (arbitrary value), enough for small rpc
+                * requests
                 */
-
-               new_size = MAX(RPC_MAX_PDU_FRAG_LEN,extra_space);
+               new_size = MAX(128, extra_space);
 
                if((ps->data_p = (char *)SMB_MALLOC(new_size)) == NULL) {
                        DEBUG(0,("prs_grow: Malloc failure for size %u.\n", (unsigned int)new_size));
@@ -281,10 +281,13 @@ bool prs_grow(prs_struct *ps, uint32 extra_space)
                memset(ps->data_p, '\0', (size_t)new_size );
        } else {
                /*
-                * If the current buffer size is bigger than the space needed, just 
-                * double it, else add extra_space.
+                * If the current buffer size is bigger than the space needed,
+                * just double it, else add extra_space. Always keep 64 bytes
+                * more, so that after we added a large blob we don't have to
+                * realloc immediately again.
                 */
-               new_size = MAX(ps->buffer_size*2, ps->buffer_size + extra_space);               
+               new_size = MAX(ps->buffer_size*2,
+                              ps->buffer_size + extra_space + 64);
 
                if ((ps->data_p = (char *)SMB_REALLOC(ps->data_p, new_size)) == NULL) {
                        DEBUG(0,("prs_grow: Realloc failure for size %u.\n",
index 56c4a317e559b70383fd8bb3089bb861ba0374f0..313c49a5e191e3b585640df654f931f4f1d991ce 100644 (file)
@@ -77,7 +77,7 @@ static bool pipe_init_outgoing_data(pipes_struct *p)
         * Initialize the outgoing RPC data buffer.
         * we will use this as the raw data area for replying to rpc requests.
         */     
-       if(!prs_init(&o_data->rdata, RPC_MAX_PDU_FRAG_LEN, p->mem_ctx, MARSHALL)) {
+       if(!prs_init(&o_data->rdata, 128, p->mem_ctx, MARSHALL)) {
                DEBUG(0,("pipe_init_outgoing_data: malloc fail.\n"));
                return False;
        }
@@ -128,7 +128,7 @@ static struct pipes_struct *make_internal_rpc_pipe_p(TALLOC_CTX *mem_ctx,
         * change the type to UNMARSALLING before processing the stream.
         */
 
-       if(!prs_init(&p->in_data.data, RPC_MAX_PDU_FRAG_LEN, p->mem_ctx, MARSHALL)) {
+       if(!prs_init(&p->in_data.data, 128, p->mem_ctx, MARSHALL)) {
                DEBUG(0,("open_rpc_pipe_p: malloc fail for in_data struct.\n"));
                talloc_destroy(p->mem_ctx);
                close_policy_by_pipe(p);