stx.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef _STX_H_
  2. #define _STX_H_
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6. #include <unistd.h>
  7. #include <sys/types.h>
  8. #include <sys/socket.h>
  9. #include <netinet/in.h>
  10. #include <arpa/nameser.h>
  11. #include <resolv.h>
  12. #include <netdb.h>
  13. #include <errno.h>
  14. #include "st.h"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. /*****************************************
  19. * Basic types definitions
  20. */
  21. typedef struct _stx_centry stx_cache_entry_t;
  22. typedef struct _stx_cache stx_cache_t;
  23. /* This is public type */
  24. typedef struct _stx_cache_info {
  25. size_t max_size;
  26. size_t max_weight;
  27. size_t hash_size;
  28. size_t cur_size;
  29. size_t cur_weight;
  30. unsigned long hits;
  31. unsigned long lookups;
  32. unsigned long inserts;
  33. unsigned long deletes;
  34. } stx_cache_info_t;
  35. /*****************************************
  36. * Cache and cache entry methods
  37. */
  38. stx_cache_t *stx_cache_create(size_t max_size, size_t max_weight,
  39. size_t hash_size,
  40. unsigned long (*key_hash_fn)(const void *key),
  41. long (*key_cmp_fn)(const void *key1,
  42. const void *key2),
  43. void (*cleanup_fn)(void *key, void *data));
  44. void stx_cache_empty(stx_cache_t *cache);
  45. void stx_cache_traverse(stx_cache_t *cache,
  46. void (*callback)(void *key, void *data));
  47. void stx_cache_traverse_lru(stx_cache_t *, void (*)(void *, void *),
  48. unsigned int);
  49. void stx_cache_traverse_mru(stx_cache_t *, void (*)(void *, void *),
  50. unsigned int);
  51. void stx_cache_getinfo(stx_cache_t *cache, stx_cache_info_t *info);
  52. size_t stx_cache_getsize(stx_cache_t *cache);
  53. size_t stx_cache_getweight(stx_cache_t *cache);
  54. stx_cache_entry_t *stx_cache_entry_create(void *key, void *data,
  55. size_t weight);
  56. void stx_cache_entry_delete(stx_cache_t *cache, stx_cache_entry_t *entry);
  57. stx_cache_entry_t *stx_cache_entry_lookup(stx_cache_t *cache, const void *key);
  58. void stx_cache_entry_release(stx_cache_t *, stx_cache_entry_t *);
  59. int stx_cache_entry_insert(stx_cache_t *cache, stx_cache_entry_t *entry);
  60. stx_cache_entry_t *stx_cache_entry_getlru(stx_cache_t *cache);
  61. int stx_cache_entry_sizeof(void);
  62. void *stx_cache_entry_getdata(stx_cache_entry_t *entry);
  63. void *stx_cache_entry_getkey(stx_cache_entry_t *entry);
  64. size_t stx_cache_entry_getweight(stx_cache_entry_t *entry);
  65. int stx_dns_cache_init(size_t max_size, size_t max_bytes, size_t hash_size);
  66. void stx_dns_cache_getinfo(stx_cache_info_t *info);
  67. int stx_dns_getaddrlist(const char *hostname, struct in_addr *addrs,
  68. int *num_addrs, st_utime_t timeout);
  69. int stx_dns_getaddr(const char *hostname, struct in_addr *addr,
  70. st_utime_t timeout);
  71. #ifdef __cplusplus
  72. }
  73. #endif
  74. #endif /* !_STX_H_ */