/[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.7 by sysadm, Sun May 18 07:41:34 2025 UTC Revision 1.9 by sysadm, Tue May 20 12:29:26 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(int) + 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            // Re-mount shm in read-only mode
178            if (shmdt(p_shm) == -1)
179            {
180                    log_error("shmdt() error (%d)\n", errno);
181                    return -3;
182            }
183    
184            p_shm = shmat(shmid, NULL, SHM_RDONLY);
185            if (p_shm == (void *)-1)
186            {
187                    log_error("shmat(shmid=%d) error (%d)\n", shmid, errno);
188                    return -3;
189            }
190    
191          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)
192          {          {
193                  shmid_old = *((int *)p_shm_old);                  shmid_old = *((int *)p_shm_old);
# Line 247  const void *get_file_shm(const char *fil Line 268  const void *get_file_shm(const char *fil
268                  return NULL;                  return NULL;
269          }          }
270    
271          *p_data_len = *((size_t *)(p_shm + sizeof(int)));          *p_data_len = ((struct shm_header_t *)p_shm)->data_len;
272          *p_line_total = *((long *)(p_shm + sizeof(int) + sizeof(size_t)));          *p_line_total = ((struct shm_header_t *)p_shm)->line_total;
273          *pp_data = p_shm + sizeof(int) + sizeof(size_t) + sizeof(long);          *pp_data = p_shm + sizeof(struct shm_header_t);
274          *pp_line_offsets = *pp_data + *p_data_len + 1;          *pp_line_offsets = *pp_data + *p_data_len + 1;
275    
276          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