|
1 |
| -Developers guide for IP2Location C API's |
2 |
| -====================================== |
| 1 | +Developers' Guide for IP2Location C Library |
| 2 | +=========================================== |
| 3 | + |
| 4 | +This guide explains the usage and the behavior of the below functions in the IP2Location C library |
3 | 5 |
|
4 |
| -This guide explains the usage and the behavior of below functions in IP2Location C library |
5 | 6 | (1) IP2Location_open_mem
|
6 | 7 | (2) IP2Location_close
|
7 | 8 | (3) IP2Location_delete_shm
|
8 | 9 |
|
9 |
| -Important enum, |
10 |
| -enum IP2Location_mem_type |
11 |
| -{ |
| 10 | +Enumeration in IP2Location C Library |
| 11 | +------------------------------------ |
| 12 | +enum IP2Location_mem_type { |
12 | 13 | IP2LOCATION_FILE_IO,
|
13 | 14 | IP2LOCATION_CACHE_MEMORY,
|
14 | 15 | IP2LOCATION_SHARED_MEMORY
|
15 | 16 | };
|
16 | 17 |
|
17 |
| -======== |
18 |
| -(1) int IP2Location_open_mem(IP2Location *loc, enum IP2Location_mem_type); |
| 18 | +Functions in IP2Location C Library |
| 19 | +----------------------------------- |
| 20 | +Function (1) |
| 21 | + |
| 22 | + int IP2Location_open_mem(IP2Location *loc, enum IP2Location_mem_type); |
| 23 | + |
| 24 | +loc - is of type IP2Location pointer, which is returned by function IP2Location_open. |
| 25 | +IP2Location_mem_type - is of type IP2Location_mem_type enum. This argument specifies how the iplocation DB file will be loaded. It may be IP2LOCATION_FILE_IO, IP2LOCATION_CACHE_MEMORY and IP2LOCATION_SHARED_MEMORY. |
| 26 | + |
| 27 | +If IP2LOCATION_FILE_IO is passed as argument, records will be searched directly from the DB file on the hard disk. |
| 28 | +If IP2LOCATION_CACHE_MEMORY is passed as argument, ip2location DB will be loaded into the memory and search will be performed on the DB present in the memory. |
| 29 | +If IP2LOCATION_SHARED_MEMORY is passed as argument, ip2location DB will be loaded into the memory and it will be shared across multiple processes. Please check at the end of this guide to know how this memory is shared and how to release the resource when it's no longer needed. |
| 30 | + |
| 31 | +IP2Location_open_mem call must always be paired with a call to IP2Location_close; if IP2Location_open_mem is called more than once without calling IP2Location_close(), -1 will be returned. |
| 32 | + |
| 33 | +RETURN value: |
| 34 | +For any error IP2Location_open_mem will return -1, and will not set any errno variable. |
| 35 | + |
19 | 36 |
|
20 |
| - loc - is of type IP2Location pointer, which is returned by function IP2Location_open. |
21 |
| - IP2Location_mem_type - is of type IP2Location_mem_type enum. This argument specifies to where the iplocation DB file will be loaded. It may be IP2LOCATION_FILE_IO, IP2LOCATION_CACHE_MEMORY and IP2LOCATION_SHARED_MEMORY. |
| 37 | +Function (2) |
22 | 38 |
|
23 |
| - If IP2LOCATION_FILE_IO is passed as agrument, DB will be in the hard disk file and records will be searched from the hard disk file. |
24 |
| - If IP2LOCATION_CACHE_MEMORY is passed as argument, ip2location DB will be loaded into the memory and search will be performed on the DB present in the memory. |
25 |
| - If IP2LOCATION_SHARED_MEMORY is passed as argument, ip2location DB will be loaded into the memory and it could be shared across multiple processes. Please check at the end of this guide to know how this memory is shared and how to clean it. |
| 39 | + uint32_t IP2Location_close(IP2Location *loc); |
26 | 40 |
|
27 |
| - IP2Location_open_mem call must always be alternated with IP2Location_close, if IP2Location_open_mem is called more than once without calling IP2Location_close(), -1 will be returned. |
| 41 | +loc - is of type IP2Location pointer, which is returned by function IP2Location_open and it must be one used in IP2Location_open_mem. |
28 | 42 |
|
29 |
| - RETURN value: |
30 |
| - For any error IP2Location_open_mem will return -1, and will not set any errno variable. |
| 43 | +Calling this function will close the DB file and free the allocated cache memory or detach from the shared memory. (Shared memory will not be deleted from this call.) |
31 | 44 |
|
32 |
| -========= |
33 |
| - (2) uint32_t IP2Location_close(IP2Location *loc); |
34 |
| - loc - is of type IP2Location pointer, which is returned by function IP2Location_open and it must be one used in IP2Location_open_mem. |
| 45 | +RETURN value: |
| 46 | +This function always return zero. |
35 | 47 |
|
36 |
| - Call to this function will close the DB file and free the allocated cache memory or detach from the shared memory. (Shared memory will not be deleted from this call.) |
37 | 48 |
|
38 |
| - RETURN value: |
39 |
| - This function always return zero. |
| 49 | +Function (3) |
40 | 50 |
|
41 |
| -========= |
42 |
| - (3) void IP2Location_delete_shm(); |
43 |
| - |
44 |
| - This function will delete the shared memory created from IP2Location_open_mem in Linux, Unix and MAC OS. In windows its just a empty function call. Please read the next section. |
45 |
| - RETURN value: |
46 |
| - void |
47 |
| -========= |
48 |
| - Note: Key used for the shared memory is "/IP2location_Shm", please make sure it will not conflict with any other shared memory. |
49 |
| - |
50 |
| - IP2LOCATION_SHARED_MEMORY – If IP2Location_open_mem is called with this as second argument, shared memory will be created if do not exist already or will attached to already existing shared memeoy. |
| 51 | + void IP2Location_delete_shm(); |
| 52 | + |
| 53 | +This function will delete the shared memory created from IP2Location_open_mem in Linux, Unix and MAC OS. In Windows, it's just an empty function call. Please read the next section. |
| 54 | + |
| 55 | +RETURN value: |
| 56 | +void |
| 57 | + |
| 58 | +Note: Key used for the shared memory is "/IP2location_Shm", please make sure it does not conflict with any other shared memory. |
| 59 | + |
| 60 | +IP2LOCATION_SHARED_MEMORY – If IP2Location_open_mem is called with this as the second argument, shared memory will be created if it does not already exists else the existing shared memory will be read instead. |
51 | 61 |
|
52 | 62 | In Windows:
|
53 |
| -If calling process of IP2Location_close function is the only attached process of the shared memory, call to IP2Location_close, along with closing the DB file and detaching from the shared memory it will delete the shared memory. If this is not the last process attached to the shared memory it will just detach from the shared memory. |
54 |
| -Call to IP2Location_delete_shm in windows have not effect. |
| 63 | +Whenever the IP2Location_close() function is called by the sole process attached to the shared memory, then the DB file will be closed and the shared memory will be deleted. |
| 64 | +If there are other processes attached to the shared memory, then the caller process will just detach itself from the shared memory while leaving the shared memory intact. |
| 65 | +Call to IP2Location_delete_shm in Windows have no effect as Windows does not support shared memory. |
| 66 | + |
| 67 | +In Linux, Unix and MacOS: |
| 68 | +Call to IP2Location_close will not deleted the shared memory, it will only detach the process from using that memory. To delete the shared memory IP2Location_delete_shm() must be called. |
| 69 | + |
| 70 | +When IP2Location_delete_shm() function is called, and if any other process(es) is attached to shared memory, it will only delete the name of the shared memory but the other process(es) will continue to use memory and memory will be freed only after last attached process is detached from it. |
55 | 71 |
|
56 |
| -In Linux, Unix and MAC OS: |
57 |
| -Call to IP2Location_close will not deleted the shared memory, it will only detach the process from using that memory. To delete the shared memory IP2Location_delete_shm must be called. |
| 72 | +After calling IP2Location_delete_shm(), the next call to IP2Location_open_mem() with IP2LOCATION_SHARED_MEMORY option will result in a new shared memory and will not reuse the old one if one exists and used by any other process. Please refer shm_open and shm_unlink man pages for more info. |
58 | 73 |
|
59 |
| - When IP2Location_delete_shm function is called, and if any other process(es) is attached to shared memory, it will only delete the name of the shared memory but the other process(es) will continue to use memory and memory will be freed only after last attached process is detached from it. |
60 | 74 |
|
61 |
| - If any process after call to IP2Location_delete_shm, call IP2Location_open_mem again with IP2LOCATION_SHARED_MEMORY option, it will create a new shared memory and will not use the old one if one exists and used by any other process. |
62 |
| - Please refer shm_open and shm_unlink man pages for more info. |
| 75 | +Version 7.0.0 05/08/2014 |
0 commit comments