/[hyperestraier]/upstream/0.5.3/estnode.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /upstream/0.5.3/estnode.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

upstream/0.5.2/estnode.c revision 9 by dpavlin, Wed Aug 3 15:21:15 2005 UTC upstream/0.5.3/estnode.c revision 10 by dpavlin, Wed Aug 3 15:25:48 2005 UTC
# Line 68  static void est_parse_search_body(ESTNOD Line 68  static void est_parse_search_body(ESTNOD
68    
69  /* Cache of host addresses */  /* Cache of host addresses */
70  CBMAP *est_host_addrs = NULL;  CBMAP *est_host_addrs = NULL;
71    int est_host_attrs_cnt = 0;
72    pthread_mutex_t est_host_addrs_mutex = PTHREAD_MUTEX_INITIALIZER;
73    
74    
75  /* Initialize the networking environment. */  /* Initialize the networking environment. */
76  int est_init_net_env(void){  int est_init_net_env(void){
77  #if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)  #if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
78    WSADATA wsaData;    WSADATA wsaData;
79    if(est_host_addrs) return TRUE;    if(pthread_mutex_lock(&est_host_addrs_mutex) != 0) return FALSE;
80    est_host_addrs = cbmapopenex(ESTDNHOLDNUM + 1);    if(WSAStartup(MAKEWORD(2,0), &wsaData) != 0){
81    return WSAStartup(MAKEWORD(2,0), &wsaData) == 0;      pthread_mutex_unlock(&est_host_addrs_mutex);
82        return FALSE;
83      }
84      if(est_host_attrs_cnt < 1) est_host_addrs = cbmapopenex(ESTDNHOLDNUM + 1);
85      est_host_attrs_cnt++;
86      pthread_mutex_unlock(&est_host_addrs_mutex);
87      return TRUE;
88  #else  #else
89    if(est_host_addrs) return TRUE;    if(pthread_mutex_lock(&est_host_addrs_mutex) != 0) return FALSE;
90    est_host_addrs = cbmapopenex(ESTDNHOLDNUM + 1);    if(est_host_attrs_cnt < 1) est_host_addrs = cbmapopenex(ESTDNHOLDNUM + 1);
91      est_host_attrs_cnt++;
92      pthread_mutex_unlock(&est_host_addrs_mutex);
93    return TRUE;    return TRUE;
94  #endif  #endif
95  }  }
# Line 88  int est_init_net_env(void){ Line 98  int est_init_net_env(void){
98  /* Free the networking environment. */  /* Free the networking environment. */
99  void est_free_net_env(void){  void est_free_net_env(void){
100  #if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)  #if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
101    if(!est_host_addrs) return;    if(pthread_mutex_lock(&est_host_addrs_mutex) != 0) return;
102    cbmapclose(est_host_addrs);    if(est_host_attrs_cnt < 1){
103        pthread_mutex_unlock(&est_host_addrs_mutex);
104        return;
105      }
106      est_host_attrs_cnt--;
107      if(est_host_attrs_cnt < 1){
108        cbmapclose(est_host_addrs);
109        est_host_addrs = NULL;
110      }
111    WSACleanup();    WSACleanup();
112      pthread_mutex_unlock(&est_host_addrs_mutex);
113  #else  #else
114    if(!est_host_addrs) return;    if(pthread_mutex_lock(&est_host_addrs_mutex) != 0) return;
115    cbmapclose(est_host_addrs);    if(est_host_attrs_cnt < 1){
116        pthread_mutex_unlock(&est_host_addrs_mutex);
117        return;
118      }
119      est_host_attrs_cnt--;
120      if(est_host_attrs_cnt < 1){
121        cbmapclose(est_host_addrs);
122        est_host_addrs = NULL;
123      }
124      pthread_mutex_unlock(&est_host_addrs_mutex);
125  #endif  #endif
126  }  }
127    
# Line 210  void est_node_delete(ESTNODE *node){ Line 238  void est_node_delete(ESTNODE *node){
238  }  }
239    
240    
 /* Get the status code of the last request of a node. */  
 int est_node_status(ESTNODE *node){  
   assert(node);  
   return node->status;  
 }  
   
   
241  /* Set the proxy information of a node connection object. */  /* Set the proxy information of a node connection object. */
242  void est_node_set_proxy(ESTNODE *node, const char *host, int port){  void est_node_set_proxy(ESTNODE *node, const char *host, int port){
243    assert(node && host && port >= 0);    assert(node && host && port >= 0);
# Line 241  void est_node_set_auth(ESTNODE *node, co Line 262  void est_node_set_auth(ESTNODE *node, co
262  }  }
263    
264    
265    /* Get the status code of the last request of a node. */
266    int est_node_status(ESTNODE *node){
267      assert(node);
268      return node->status;
269    }
270    
271    
272  /* Add a document to a node. */  /* Add a document to a node. */
273  int est_node_put_doc(ESTNODE *node, ESTDOC *doc){  int est_node_put_doc(ESTNODE *node, ESTDOC *doc){
274    CBLIST *reqheads;    CBLIST *reqheads;
# Line 820  const char *est_get_host_name(void){ Line 848  const char *est_get_host_name(void){
848    
849  /* Get the address of a host. */  /* Get the address of a host. */
850  char *est_get_host_addr(const char *name){  char *est_get_host_addr(const char *name){
   static pthread_mutex_t mymutex = PTHREAD_MUTEX_INITIALIZER;  
851    struct hostent *info;    struct hostent *info;
852    const char *addr;    const char *addr;
853    char *buf, *pv, vbuf[64];    char *buf, *pv, vbuf[64];
854    int i, ost, nsiz, asiz, vsiz;    int i, ost, nsiz, asiz, vsiz;
855    assert(name);    assert(name);
   if(!est_host_addrs) return NULL;  
856    if(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &ost) != 0) return NULL;    if(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &ost) != 0) return NULL;
857    if(pthread_mutex_lock(&mymutex) != 0){    if(pthread_mutex_lock(&est_host_addrs_mutex) != 0){
858        pthread_setcancelstate(ost, NULL);
859        return NULL;
860      }
861      if(!est_host_addrs){
862        pthread_mutex_unlock(&est_host_addrs_mutex);
863      pthread_setcancelstate(ost, NULL);      pthread_setcancelstate(ost, NULL);
864      return NULL;      return NULL;
865    }    }
# Line 845  char *est_get_host_addr(const char *name Line 876  char *est_get_host_addr(const char *name
876      }      }
877      cbmapmove(est_host_addrs, name, nsiz, FALSE);      cbmapmove(est_host_addrs, name, nsiz, FALSE);
878    }    }
879    pthread_mutex_unlock(&mymutex);    pthread_mutex_unlock(&est_host_addrs_mutex);
880    pthread_setcancelstate(ost, NULL);    pthread_setcancelstate(ost, NULL);
881    if(buf){    if(buf){
882      if(buf[0] != '\0') return buf;      if(buf[0] != '\0') return buf;
# Line 859  char *est_get_host_addr(const char *name Line 890  char *est_get_host_addr(const char *name
890    }    }
891    buf = addr ? cbmemdup(addr, -1) : NULL;    buf = addr ? cbmemdup(addr, -1) : NULL;
892    if(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &ost) == 0){    if(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &ost) == 0){
893      if(pthread_mutex_lock(&mymutex) == 0){      if(pthread_mutex_lock(&est_host_addrs_mutex) == 0){
894        vsiz = sprintf(vbuf, "%s\t%d", addr ? addr : "", (int)time(NULL));        vsiz = sprintf(vbuf, "%s\t%d", addr ? addr : "", (int)time(NULL));
895        cbmapput(est_host_addrs, name, nsiz, vbuf, vsiz, TRUE);        cbmapput(est_host_addrs, name, nsiz, vbuf, vsiz, TRUE);
896        if(cbmaprnum(est_host_addrs) > ESTDNHOLDNUM){        if(cbmaprnum(est_host_addrs) > ESTDNHOLDNUM){
# Line 869  char *est_get_host_addr(const char *name Line 900  char *est_get_host_addr(const char *name
900            cbmapout(est_host_addrs, addr, asiz);            cbmapout(est_host_addrs, addr, asiz);
901          }          }
902        }        }
903        pthread_mutex_unlock(&mymutex);        pthread_mutex_unlock(&est_host_addrs_mutex);
904      }      }
905      pthread_setcancelstate(ost, NULL);      pthread_setcancelstate(ost, NULL);
906    }    }

Legend:
Removed from v.9  
changed lines
  Added in v.10

  ViewVC Help
Powered by ViewVC 1.1.26