/[LeafOK_CVS]/lbbs/src/file_loader.c
ViewVC logotype

Diff of /lbbs/src/file_loader.c

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

Revision 1.6 by sysadm, Sun May 18 06:56:08 2025 UTC Revision 1.10 by sysadm, Fri May 23 14:11:38 2025 UTC
# Line 31  Line 31 
31    
32  #define MAX_SPLIT_FILE_LINES 65536  #define MAX_SPLIT_FILE_LINES 65536
33    
34    struct shm_header_t
35    {
36            int shmid;
37            size_t data_len;
38            long line_total;
39    };
40    
41  static TRIE_NODE *p_trie_file_dict = NULL;  static TRIE_NODE *p_trie_file_dict = NULL;
42    
43  int file_loader_init()  int file_loader_init()
# Line 138  int load_file_shm(const char *filename) Line 145  int load_file_shm(const char *filename)
145                  return -2;                  return -2;
146          }          }
147    
148          size = sizeof(shmid) + sizeof(data_len) + sizeof(line_total) + data_len + 1 + sizeof(long) * (size_t)(line_total + 1);          size = sizeof(struct shm_header_t) + data_len + 1 + sizeof(long) * (size_t)(line_total + 1);
149          shmid = shmget(key, size, IPC_CREAT | IPC_EXCL | 0600);          shmid = shmget(key, size, IPC_CREAT | IPC_EXCL | 0600);
150          if (shmid == -1)          if (shmid == -1)
151          {          {
# Line 152  int load_file_shm(const char *filename) Line 159  int load_file_shm(const char *filename)
159                  return -3;                  return -3;
160          }          }
161    
162          *((int *)p_shm) = shmid;          ((struct shm_header_t *)p_shm)->shmid = shmid;
163          *((size_t *)(p_shm + sizeof(shmid))) = data_len;          ((struct shm_header_t *)p_shm)->data_len = data_len;
164          *((long *)(p_shm + sizeof(shmid) + sizeof(data_len))) = line_total;          ((struct shm_header_t *)p_shm)->line_total = line_total;
165          memcpy(p_shm + sizeof(shmid) + sizeof(data_len) + sizeof(line_total), p_data, data_len);          memcpy(p_shm + sizeof(struct shm_header_t), p_data, data_len);
166    
167          if (munmap(p_data, data_len) < 0)          if (munmap(p_data, data_len) < 0)
168          {          {
# Line 163  int load_file_shm(const char *filename) Line 170  int load_file_shm(const char *filename)
170                  return -2;                  return -2;
171          }          }
172    
173          p_data = p_shm + sizeof(data_len) + sizeof(line_total);          p_data = p_shm + sizeof(struct shm_header_t);
174          p_line_offsets = p_data + data_len + 1;          p_line_offsets = p_data + data_len + 1;
175          memcpy(p_line_offsets, line_offsets, sizeof(long) * (size_t)(line_total + 1));          memcpy(p_line_offsets, line_offsets, sizeof(long) * (size_t)(line_total + 1));
176    
177            // Remap shared memory in read-only mode
178            p_shm = shmat(shmid, p_shm, SHM_RDONLY | SHM_REMAP);
179            if (p_shm == (void *)-1)
180            {
181                    log_error("shmat(shmid=%d) error (%d)\n", shmid, errno);
182                    return -3;
183            }
184    
185          if (trie_dict_get(p_trie_file_dict, filename, (int64_t *)&p_shm_old) == 1)          if (trie_dict_get(p_trie_file_dict, filename, (int64_t *)&p_shm_old) == 1)
186          {          {
187                  shmid_old = *((int *)p_shm_old);                  shmid_old = *((int *)p_shm_old);
# Line 247  const void *get_file_shm(const char *fil Line 262  const void *get_file_shm(const char *fil
262                  return NULL;                  return NULL;
263          }          }
264    
265          *p_data_len = *((size_t *)(p_shm + sizeof(int)));          *p_data_len = ((struct shm_header_t *)p_shm)->data_len;
266          *p_line_total = *((long *)(p_shm + sizeof(int) + sizeof(size_t)));          *p_line_total = ((struct shm_header_t *)p_shm)->line_total;
267          *pp_data = p_shm + sizeof(int) + sizeof(size_t) + sizeof(long);          *pp_data = p_shm + sizeof(struct shm_header_t);
268          *pp_line_offsets = *pp_data + *p_data_len + 1;          *pp_line_offsets = *pp_data + *p_data_len + 1;
269    
270          return p_shm;          return p_shm;


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1