Ignore:
Timestamp:
01/17/09 18:28:53 (3 years ago)
Author:
Tomash Brechko <tomash.brechko@…>
Branches:
master-v0.7, master-v0.6, memcached_hash, upstream_count_limit
Children:
12bc79
Parents:
9ceabd
git-author:
Tomash Brechko <tomash.brechko@…> (01/17/09 15:49:50)
git-committer:
Tomash Brechko <tomash.brechko@…> (01/17/09 18:28:53)
Message:

Do not change callback and data pointers after module initialization.

This commit should ease the review. Next one will transpose
functions to eliminate forward declaration.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • memcached_hash/ngx_http_upstream_memcached_hash_module.c

    r9ceabd r38354f  
    11/* 
    2   Copyright (C) 2007-2008 Tomash Brechko.  All rights reserved. 
     2  Copyright (C) 2007-2009 Tomash Brechko.  All rights reserved. 
    33 
    44  Development of this module was sponsored by Monashev Co. Ltd. 
     
    5555  ngx_http_upstream_server_t *server; 
    5656  ngx_http_request_t *request; 
     57  struct memcached_hash_peer *peer; 
    5758}; 
    5859 
     
    9798 
    9899static 
     100unsigned int 
     101memcached_hash_find_peer(struct memcached_hash_find_ctx *find_ctx); 
     102 
     103 
     104static 
    99105ngx_int_t 
    100106memcached_hash_get_peer(ngx_peer_connection_t *pc, void *data) 
    101107{ 
    102   struct memcached_hash_peer *peer = data; 
     108  struct memcached_hash_find_ctx *find_ctx = data; 
     109  struct memcached_hash_peer *peer = find_ctx->peer; 
    103110  ngx_peer_addr_t *addr; 
     111 
     112  if (! peer) 
     113    { 
     114      unsigned int index; 
     115 
     116      index = memcached_hash_find_peer(find_ctx); 
     117 
     118      peer = find_ctx->peer; 
     119      pc->tries = find_ctx->server[index].naddrs; 
     120    } 
    104121 
    105122  if (peer->server->down) 
     
    132149 
    133150static 
    134 ngx_int_t 
    135 memcached_hash_find_peer(ngx_peer_connection_t *pc, void *data) 
    136 { 
    137   struct memcached_hash_find_ctx *find_ctx = data; 
     151unsigned int 
     152memcached_hash_find_peer(struct memcached_hash_find_ctx *find_ctx) 
     153{ 
    138154  struct memcached_hash *memd = find_ctx->memd; 
    139155  u_char *key; 
     
    185201    } 
    186202 
    187   pc->data = &memd->peers[index]; 
    188   pc->get = memcached_hash_get_peer; 
    189   pc->tries = find_ctx->server[index].naddrs; 
    190  
    191   return memcached_hash_get_peer(pc, pc->data); 
     203  find_ctx->peer = &memd->peers[index]; 
     204 
     205  return index; 
    192206} 
    193207 
     
    198212                         ngx_uint_t state) 
    199213{ 
    200   struct memcached_hash_peer *peer = data; 
     214  struct memcached_hash_find_ctx *find_ctx = data; 
     215  struct memcached_hash_peer *peer = find_ctx->peer; 
    201216 
    202217  if (state & NGX_PEER_FAILED) 
     
    243258  find_ctx->request = r; 
    244259  find_ctx->server = us->servers->elts; 
     260  find_ctx->peer = NULL; 
    245261 
    246262  r->upstream->peer.free = memcached_hash_free_peer; 
     
    250266    memcached_hash_find_peer(). 
    251267  */ 
    252   r->upstream->peer.get = memcached_hash_find_peer; 
     268  r->upstream->peer.get = memcached_hash_get_peer; 
    253269  r->upstream->peer.data = find_ctx; 
    254270  r->upstream->peer.tries = 1; 
Note: See TracChangeset for help on using the changeset viewer.