Changeset 5196

Show
Ignore:
Timestamp:
01/21/08 15:49:10 (6 months ago)
Author:
morris
Message:

Broadcast new server info message after indexing to update clients with file count/size

Store file count/size last in index, and read it into the server if the index is skipped when starting up

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • wired/trunk/wired/commands.c

    r4806 r5196  
    895895static void wd_cmd_hello(wi_array_t *arguments) { 
    896896        wd_user_t               *user = wd_users_user_for_thread(); 
    897         wi_string_t             *ip, *start_date
     897        wi_string_t             *ip
    898898 
    899899        if(wd_user_state(user) != WD_USER_CONNECTED) 
     
    911911                return; 
    912912        } 
    913  
    914         start_date = wi_date_iso8601_string(wd_start_date); 
    915  
    916         wd_reply(200, WI_STR("%#@%c%#@%c%#@%c%#@%c%#@%c%u%c%llu"), 
    917                          wd_server_version_string,              WD_FIELD_SEPARATOR, 
    918                          wd_protocol_version_string,    WD_FIELD_SEPARATOR, 
    919                          wd_settings.name,                              WD_FIELD_SEPARATOR, 
    920                          wd_settings.description,               WD_FIELD_SEPARATOR, 
    921                          start_date,                                    WD_FIELD_SEPARATOR, 
    922                          wd_files_unique_count,                 WD_FIELD_SEPARATOR, 
    923                          wd_files_unique_size); 
     913         
     914        wd_server_send_server_info(false); 
    924915         
    925916        wd_user_set_state(user, WD_USER_SAID_HELLO); 
  • wired/trunk/wired/files.c

    r5191 r5196  
    6969 
    7070static void                                                                     wd_files_update_index(wi_timer_t *); 
     71static void                                                                     wd_files_update_index_size(void); 
    7172static void                                                                     wd_files_index_thread(wi_runtime_instance_t *); 
    7273static void                                                                     wd_files_index_path(wi_string_t *, wi_file_t *, const char *); 
     
    681682 
    682683static void wd_files_search_index(wi_string_t *query) { 
    683         wd_user_t               *user = wd_users_user_for_thread(); 
    684         wi_pool_t               *pool; 
    685         wi_file_t               *file; 
    686         wi_string_t             *string; 
    687         wd_account_t    *account; 
    688         wi_range_t              range, pathrange; 
    689         wi_uinteger_t   i = 0, pathlength, index; 
     684        wd_user_t                       *user = wd_users_user_for_thread(); 
     685        wi_pool_t                       *pool; 
     686        wi_file_t                       *file; 
     687        wi_string_t                     *string; 
     688        wd_account_t            *account; 
     689        wi_range_t                      range, pathrange; 
     690        wi_uinteger_t           i = 0, pathlength, index; 
     691        wi_file_offset_t        length; 
     692        struct stat                     sb; 
    690693         
    691694        wi_rwlock_rdlock(wd_files_index_lock); 
     
    699702                goto end; 
    700703        } 
     704         
     705        if(wi_file_stat(wd_settings.index, &sb)) 
     706                length = sb.st_size; 
     707        else 
     708                length = 0; 
    701709         
    702710        account = wd_user_account(user); 
     
    717725                        break; 
    718726                 
    719                 if(wd_files_name_matches_query(string, query, true)) { 
     727                if(length < wi_file_offset(file) && wd_files_name_matches_query(string, query, true)) { 
    720728                        index = wi_string_index_of_char(string, WD_FIELD_SEPARATOR, 0); 
    721729                         
     
    778786                if(!wi_thread_create_thread_with_priority(wd_files_index_thread, NULL, 0.0)) 
    779787                        wi_log_warn(WI_STR("Could not create a thread for index: %m")); 
     788        } else { 
     789                wd_files_update_index_size(); 
     790        } 
     791} 
     792 
     793 
     794 
     795static void wd_files_update_index_size(void) { 
     796        wi_file_t                       *file; 
     797        wi_array_t                      *array; 
     798        wi_string_t                     *string; 
     799        wi_file_offset_t        offset; 
     800         
     801        file = wi_file_for_reading(wd_settings.index); 
     802         
     803        if(!file) 
     804                return; 
     805         
     806        offset = wi_file_seek_to_end_of_file(file); 
     807        wi_file_seek(file, offset - 1024); 
     808                 
     809        while((string = wi_file_read_line(file))) { 
     810                if(wi_string_has_prefix(string, WI_STR("/"))) { 
     811                        array = wi_string_components_separated_by_string(string, WI_STR(WD_FIELD_SEPARATOR_STR)); 
     812                         
     813                        if(wi_array_count(array) == 3) { 
     814                                wd_files_unique_count = wi_string_uint32(WI_ARRAY(array, 1)); 
     815                                wd_files_unique_size = wi_string_uint32(WI_ARRAY(array, 2)); 
     816                        } 
     817                } 
    780818        } 
    781819} 
     
    810848                 
    811849                wd_files_index_level    = 0; 
    812                 wd_files_index_set              = wi_set_init_with_capacity(wi_set_alloc(), capacity); 
     850                wd_files_index_set              = wi_autorelease(wi_set_init_with_capacity(wi_set_alloc(), capacity)); 
    813851 
    814852                path = wi_string_with_format(WI_STR("%@~"), wd_settings.index); 
     
    827865 
    828866                if(wi_file_rename(path, wd_settings.index)) { 
     867                        wi_file_write(file, WI_STR("%s%c%u%c%llu"), 
     868                                "/",                                    WD_FIELD_SEPARATOR, 
     869                                wd_files_unique_count,  WD_FIELD_SEPARATOR, 
     870                                wd_files_unique_size); 
     871                         
    829872                        wi_log_info(WI_STR("Indexed %u %s (%u unique) and %u %s (%u unique) for a total of %llu %s (%llu unique) in %.2f seconds"), 
    830873                                wd_files_count, 
     
    851894                wi_rwlock_unlock(wd_files_index_lock); 
    852895                 
     896                wd_server_send_server_info(true); 
     897                 
    853898end: 
    854                 wi_release(wd_files_index_set); 
    855  
    856899                wi_lock_unlock(wd_files_indexer_lock); 
    857900        } 
  • wired/trunk/wired/server.c

    r5162 r5196  
    173173 
    174174void wd_server_apply_settings(void) { 
    175         wi_string_t             *string; 
    176175        wi_data_t               *data; 
    177176 
     
    196195 
    197196        /* reload server name/description */ 
    198         if(wd_settings.name_changed || wd_settings.description_changed) { 
    199                 string = wi_date_iso8601_string(wd_start_date); 
    200                  
    201                 wd_broadcast(wd_public_chat, 200, WI_STR("%#@%c%#@%c%#@%c%#@%c%#@%c%u%c%llu"), 
    202                                          wd_server_version_string,              WD_FIELD_SEPARATOR, 
    203                                          wd_protocol_version_string,    WD_FIELD_SEPARATOR, 
    204                                          wd_settings.name,                              WD_FIELD_SEPARATOR, 
    205                                          wd_settings.description,               WD_FIELD_SEPARATOR, 
    206                                          string,                                                WD_FIELD_SEPARATOR, 
    207                                          wd_files_unique_count,                 WD_FIELD_SEPARATOR, 
    208                                          wd_files_unique_size); 
    209         } 
     197        if(wd_settings.name_changed || wd_settings.description_changed) 
     198                wd_server_send_server_info(true); 
    210199 
    211200        /* set SSL cipher list */ 
     
    233222        } 
    234223} 
     224 
     225 
     226 
     227void wd_server_send_server_info(wi_boolean_t broadcast) { 
     228        wi_string_t             *string, *start_date; 
     229         
     230        start_date = wi_date_iso8601_string(wd_start_date); 
     231        string = wi_string_with_format(WI_STR("%#@%c%#@%c%#@%c%#@%c%#@%c%u%c%llu"), 
     232                wd_server_version_string,               WD_FIELD_SEPARATOR, 
     233                wd_protocol_version_string,             WD_FIELD_SEPARATOR, 
     234                wd_settings.name,                               WD_FIELD_SEPARATOR, 
     235                wd_settings.description,                WD_FIELD_SEPARATOR, 
     236                start_date,                                             WD_FIELD_SEPARATOR, 
     237                wd_files_unique_count,                  WD_FIELD_SEPARATOR, 
     238                wd_files_unique_size); 
     239         
     240        if(broadcast) 
     241                wd_broadcast(wd_public_chat, 200, WI_STR("%#@"), string); 
     242        else 
     243                wd_reply(200, WI_STR("%#@"), string); 
     244} 
     245 
    235246 
    236247 
  • wired/trunk/wired/server.h

    r5066 r5196  
    4949void                                                            wd_server_create_threads(void); 
    5050void                                                            wd_server_apply_settings(void); 
     51void                                                            wd_server_send_server_info(wi_boolean_t); 
    5152 
    5253void                                                            wd_ssl_init(void);