Changeset 4738
- Timestamp:
- 05/10/07 16:22:34 (2 years ago)
- Files:
-
- wired/trunk/wired/accounts.c (modified) (2 diffs)
- wired/trunk/wired/chats.c (modified) (13 diffs)
- wired/trunk/wired/chats.h (modified) (2 diffs)
- wired/trunk/wired/clients.c (modified) (8 diffs)
- wired/trunk/wired/clients.h (modified) (2 diffs)
- wired/trunk/wired/commands.c (modified) (11 diffs)
- wired/trunk/wired/files.c (modified) (4 diffs)
- wired/trunk/wired/server.c (modified) (2 diffs)
- wired/trunk/wired/trackers.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
wired/trunk/wired/accounts.c
r4508 r4738 604 604 return; 605 605 606 wd_client_wrlock_client(client); 607 606 608 wi_retain(account); 607 609 wi_release(client->account); … … 609 611 client->account = account; 610 612 611 wi_lock_lock(client->flag_lock);612 613 admin = client->admin; 613 614 client->admin = (client->account->kick_users || client->account->ban_users); 614 wi_lock_unlock(client->flag_lock); 615 616 wd_client_unlock_client(client); 615 617 616 618 if(client->admin != admin) wired/trunk/wired/chats.c
r4576 r4738 132 132 wd_chat_t * wd_chat_init(wd_chat_t *chat) { 133 133 chat->clients = wi_array_init(wi_array_alloc()); 134 chat->lock = wi_rwlock_init(wi_rwlock_alloc()); 134 135 135 136 return chat; … … 200 201 #pragma mark - 201 202 203 void wd_chat_wrlock(wd_chat_t *chat) { 204 wi_rwlock_wrlock(chat->lock); 205 } 206 207 208 209 void wd_chat_rdlock(wd_chat_t *chat) { 210 wi_rwlock_rdlock(chat->lock); 211 } 212 213 214 215 void wd_chat_unlock(wd_chat_t *chat) { 216 wi_rwlock_unlock(chat->lock); 217 } 218 219 220 221 #pragma mark - 222 202 223 wi_boolean_t wd_chat_contains_client(wd_chat_t *chat, wd_client_t *client) { 203 wi_enumerator_t *enumerator;204 wd_client_t *each;205 224 wi_boolean_t contains = false; 206 225 207 226 if(chat) { 208 wi_array_rdlock(chat->clients); 209 210 enumerator = wi_array_data_enumerator(chat->clients); 211 212 while((each = wi_enumerator_next_data(enumerator))) { 213 if(each == client) { 214 contains = true; 215 216 break; 217 } 218 } 219 220 wi_array_unlock(chat->clients); 227 wd_chat_rdlock(chat); 228 contains = wi_array_contains_data(chat->clients, client); 229 wd_chat_unlock(chat); 221 230 } 222 231 … … 227 236 228 237 void wd_chat_add_client(wd_chat_t *chat, wd_client_t *client) { 238 wd_client_rdlock_client(client); 229 239 wd_broadcast(chat, 302, WI_STR("%u%c%u%c%u%c%u%c%u%c%#@%c%#@%c%#@%c%#@%c%#@%c%#@"), 230 240 chat->cid, WD_FIELD_SEPARATOR, … … 239 249 client->status, WD_FIELD_SEPARATOR, 240 250 client->image); 241 242 wi_array_wrlock(chat->clients); 251 wd_client_unlock_client(client); 252 253 wd_chat_wrlock(chat); 243 254 wi_array_add_data(chat->clients, client); 244 w i_array_unlock(chat->clients);255 wd_chat_unlock(chat); 245 256 246 257 if(chat->topic.topic) … … 251 262 252 263 void wd_chat_remove_client(wd_chat_t *chat, wd_client_t *client) { 253 w i_array_wrlock(chat->clients);264 wd_chat_wrlock(chat); 254 265 wi_array_remove_data(chat->clients, client); 255 w i_array_unlock(chat->clients);266 wd_chat_unlock(chat); 256 267 257 268 if(chat->cid != WD_PUBLIC_CID && wi_array_count(chat->clients) == 0) { … … 268 279 wd_client_t *client; 269 280 270 w i_array_rdlock(chat->clients);281 wd_chat_rdlock(chat); 271 282 272 283 enumerator = wi_array_data_enumerator(chat->clients); 273 284 274 285 while((client = wi_enumerator_next_data(enumerator))) { 286 wd_client_rdlock_client(client); 287 275 288 if(client->state == WD_CLIENT_STATE_LOGGED_IN) { 276 289 wd_reply(310, WI_STR("%u%c%u%c%u%c%u%c%u%c%#@%c%#@%c%#@%c%#@%c%#@%c%#@"), … … 287 300 client->image); 288 301 } 302 303 wd_client_unlock_client(client); 289 304 } 290 305 291 w i_array_unlock(chat->clients);306 wd_chat_unlock(chat); 292 307 293 308 wd_reply(311, WI_STR("%u"), chat->cid); … … 301 316 wd_client_t *client = wd_client(); 302 317 318 wd_chat_wrlock(chat); 319 303 320 wi_release(chat->topic.topic); 304 321 chat->topic.topic = wi_copy(topic); … … 315 332 wi_release(chat->topic.ip); 316 333 chat->topic.ip = wi_copy(client->ip); 334 335 wd_chat_unlock(chat); 317 336 } 318 337 … … 322 341 wi_string_t *string; 323 342 343 wd_chat_rdlock(chat); 344 324 345 string = wi_date_iso8601_string(chat->topic.date); 325 346 … … 331 352 string, WD_FIELD_SEPARATOR, 332 353 chat->topic.topic); 354 355 wd_chat_unlock(chat); 333 356 } 334 357 … … 338 361 wi_string_t *string; 339 362 363 wd_chat_rdlock(chat); 364 340 365 string = wi_date_iso8601_string(chat->topic.date); 341 366 … … 347 372 string, WD_FIELD_SEPARATOR, 348 373 chat->topic.topic); 374 375 wd_chat_unlock(chat); 349 376 } 350 377 wired/trunk/wired/chats.h
r4508 r4738 57 57 wd_topic_t topic; 58 58 wi_array_t *clients; 59 60 wi_rwlock_t *lock; 59 61 }; 60 62 typedef struct _wd_chat wd_chat_t; … … 74 76 wd_chat_t * wd_chat_init_private_chat(wd_chat_t *); 75 77 78 void wd_chat_wrlock(wd_chat_t *); 79 void wd_chat_rdlock(wd_chat_t *); 80 void wd_chat_unlock(wd_chat_t *); 81 76 82 wi_boolean_t wd_chat_contains_client(wd_chat_t *, wd_client_t *); 77 83 void wd_chat_add_client(wd_chat_t *, wd_client_t *); wired/trunk/wired/clients.c
r4576 r4738 56 56 static wi_timer_t *wd_clients_timer; 57 57 58 static wd_uid_t wd_clients_current_uid; 59 static wi_lock_t *wd_clients_uid_lock; 60 58 61 wi_hash_t *wd_clients; 59 62 … … 73 76 74 77 wd_clients = wi_hash_init(wi_hash_alloc()); 78 79 wd_clients_uid_lock = wi_lock_init(wi_lock_alloc()), 75 80 76 81 wd_clients_timer = wi_timer_init_with_function(wi_timer_alloc(), … … 101 106 102 107 while((client = wi_enumerator_next_data(enumerator))) { 103 if(client->idle || client->state != WD_CLIENT_STATE_LOGGED_IN) 104 continue; 105 106 if(client->idle_time + wd_settings.idletime < interval) { 108 wd_client_wrlock_client(client); 109 110 if(client->state == WD_CLIENT_STATE_LOGGED_IN && 111 !client->idle && 112 client->idle_time + wd_settings.idletime < interval) { 107 113 client->idle = true; 108 114 109 115 wd_client_broadcast_status(client); 110 116 } 117 118 wd_client_unlock_client(client); 111 119 } 112 120 } … … 173 181 client->state = WD_CLIENT_STATE_CONNECTED; 174 182 client->login_time = wi_time_interval(); 175 client->idle_time = client-> idle_time;183 client->idle_time = client->login_time; 176 184 177 185 address = wi_socket_address(socket); … … 180 188 181 189 client->socket_lock = wi_lock_init(wi_lock_alloc()); 182 client-> flag_lock = wi_lock_init(wi_lock_alloc());190 client->client_lock = wi_rwlock_init(wi_rwlock_alloc()); 183 191 184 192 client->transfers_queue = wi_array_init(wi_array_alloc()); … … 192 200 wd_client_t *client = instance; 193 201 202 wi_release(client->client_lock); 203 wi_release(client->socket_lock); 204 194 205 wi_release(client->socket); 195 206 … … 204 215 wi_release(client->image); 205 216 206 wi_release(client->socket_lock);207 wi_release(client->flag_lock);208 209 217 wi_release(client->transfers_queue); 210 218 } … … 228 236 229 237 static wd_uid_t wd_client_uid(void) { 230 static wd_uid_t uid; 231 238 wd_uid_t uid; 239 240 wi_lock_lock(wd_clients_uid_lock); 241 wi_hash_rdlock(wd_clients); 242 232 243 if(wi_hash_count(wd_clients) == 0) 233 uid = 0; 234 235 return ++uid; 236 } 237 238 239 240 #pragma mark - 244 wd_clients_current_uid = 0; 245 246 uid = ++wd_clients_current_uid; 247 248 wi_hash_unlock(wd_clients); 249 wi_lock_unlock(wd_clients_uid_lock); 250 251 return uid; 252 } 253 254 255 256 #pragma mark - 257 258 void wd_client_wrlock_client(wd_client_t *client) { 259 wi_rwlock_wrlock(client->client_lock); 260 } 261 262 263 264 void wd_client_rdlock_client(wd_client_t *client) { 265 wi_rwlock_rdlock(client->client_lock); 266 } 267 268 269 270 void wd_client_unlock_client(wd_client_t *client) { 271 wi_rwlock_unlock(client->client_lock); 272 } 273 274 275 241 276 242 277 void wd_client_lock_socket(wd_client_t *client) { wired/trunk/wired/clients.h
r4508 r4738 55 55 wi_runtime_base_t base; 56 56 57 wi_rwlock_t *client_lock; 57 58 wi_lock_t *socket_lock; 59 58 60 wi_socket_t *socket; 59 61 60 wi_lock_t *flag_lock;61 62 wd_uid_t uid; 62 63 wd_client_state_t state; … … 97 98 wd_client_t * wd_client_init_with_socket(wd_client_t *, wi_socket_t *); 98 99 100 void wd_client_wrlock_client(wd_client_t *); 101 void wd_client_rdlock_client(wd_client_t *); 102 void wd_client_unlock_client(wd_client_t *); 99 103 void wd_client_lock_socket(wd_client_t *); 100 104 void wd_client_unlock_socket(wd_client_t *); wired/trunk/wired/commands.c
r4568 r4738 323 323 324 324 if(wd_commands[index].activate) { 325 wd_client_wrlock_client(client); 326 325 327 client->idle_time = wi_time_interval(); 326 328 … … 330 332 wd_client_broadcast_status(client); 331 333 } 334 335 wd_client_unlock_client(client); 332 336 } 333 337 … … 408 412 wd_tempban(peer->ip); 409 413 410 w i_lock_lock(peer->flag_lock);414 wd_client_wrlock_client(peer); 411 415 peer->state = WD_CLIENT_STATE_DISCONNECTED; 412 w i_lock_unlock(peer->flag_lock);416 wd_client_unlock_client(peer); 413 417 } 414 418 … … 932 936 933 937 icon = wi_string_uint32(WI_ARRAY(arguments, 0)); 938 939 wd_client_wrlock_client(client); 934 940 935 941 /* set icon if changed */ … … 952 958 } 953 959 } 960 961 wd_client_unlock_client(client); 954 962 } 955 963 … … 1147 1155 peer->nick, peer->login, peer->ip); 1148 1156 1149 w i_lock_lock(peer->flag_lock);1157 wd_client_wrlock_client(peer); 1150 1158 peer->state = WD_CLIENT_STATE_DISCONNECTED; 1151 w i_lock_unlock(peer->flag_lock);1159 wd_client_unlock_client(peer); 1152 1160 } 1153 1161 … … 1345 1353 nick = WI_ARRAY(arguments, 0); 1346 1354 1355 wd_client_wrlock_client(client); 1356 1347 1357 if(!wi_is_equal(nick, client->nick)) { 1348 1358 wi_release(client->nick); … … 1352 1362 wd_client_broadcast_status(client); 1353 1363 } 1364 1365 wd_client_unlock_client(client); 1354 1366 } 1355 1367 … … 1393 1405 client->nick, client->login, client->ip); 1394 1406 1395 w i_lock_lock(client->flag_lock);1407 wd_client_wrlock_client(client); 1396 1408 client->admin = (client->account->kick_users || client->account->ban_users); 1397 1409 client->state = WD_CLIENT_STATE_LOGGED_IN; 1398 w i_lock_unlock(client->flag_lock);1410 wd_client_unlock_client(client); 1399 1411 1400 1412 wi_lock_lock(wd_status_lock); … … 1645 1657 1646 1658 status = WI_ARRAY(arguments, 0); 1659 1660 wd_client_wrlock_client(client); 1647 1661 1648 1662 if(!wi_is_equal(status, client->status)) { … … 1653 1667 wd_client_broadcast_status(client); 1654 1668 } 1669 1670 wd_client_unlock_client(client); 1655 1671 } 1656 1672 wired/trunk/wired/files.c
r4621 r4738 1079 1079 wi_file_t *file; 1080 1080 wi_string_t *name, *dirpath, *realdirpath, *commentpath; 1081 wi_string_t *eachname, *eachcomment , *comment = NULL;1081 wi_string_t *eachname, *eachcomment; 1082 1082 1083 1083 name = wi_string_last_path_component(path); … … 1094 1094 1095 1095 while(wd_files_read_comment(file, &eachname, &eachcomment)) { 1096 if(wi_is_equal(name, eachname)) { 1097 comment = wi_retain(eachcomment); 1098 1099 break; 1100 } 1101 } 1102 1103 return wi_autorelease(comment); 1096 if(wi_is_equal(name, eachname)) 1097 return eachcomment; 1098 } 1099 1100 return NULL; 1104 1101 } 1105 1102 … … 1244 1241 wd_file_type_t type; 1245 1242 wi_uinteger_t i, count; 1246 wi_boolean_t result = false;1247 1243 1248 1244 realpath = wd_files_real_path(WI_STR("/")); 1249 1245 wi_string_resolve_aliases_in_path(realpath); 1250 1246 1251 dirpath = wi_ copy(path);1247 dirpath = wi_autorelease(wi_copy(path)); 1252 1248 wi_string_delete_last_path_component(dirpath); 1253 1249 … … 1260 1256 type = wd_files_type(realpath); 1261 1257 1262 if(type == WD_FILE_TYPE_DROPBOX) { 1263 result = true; 1264 1265 break; 1266 } 1267 } 1268 1269 wi_release(dirpath); 1270 1271 return result; 1258 if(wd_files_type(realpath) == WD_FILE_TYPE_DROPBOX) 1259 return true; 1260 } 1261 1262 return false; 1272 1263 } 1273 1264 wired/trunk/wired/server.c
r4632 r4738 482 482 va_end(ap); 483 483 484 w i_array_rdlock(chat->clients);484 wd_chat_rdlock(chat); 485 485 486 486 enumerator = wi_array_data_enumerator(chat->clients); 487 487 488 488 while((client = wi_enumerator_next_data(enumerator))) { 489 wd_client_rdlock_client(client); 490 489 491 if(client->state == WD_CLIENT_STATE_LOGGED_IN) { 490 492 wd_client_lock_socket(client); … … 492 494 wd_client_unlock_socket(client); 493 495 } 494 } 495 496 wi_array_unlock(chat->clients); 496 497 wd_client_unlock_client(client); 498 } 499 500 wd_chat_unlock(chat); 497 501 498 502 wi_release(string); wired/trunk/wired/trackers.c
r4576 r4738 418 418 static void wd_tracker_update(wd_tracker_t *tracker) { 419 419 wi_socket_t *socket; 420 wi_string_t *string = NULL;421 420 wi_integer_t bytes; 422 421 uint32_t guest, download; … … 425 424 download = (guest && wd_trackers_guest_account->download); 426 425 427 socket = wi_ socket_init_with_address(wi_socket_alloc(), tracker->address, WI_SOCKET_UDP);426 socket = wi_autorelease(wi_socket_init_with_address(wi_socket_alloc(), tracker->address, WI_SOCKET_UDP)); 428 427 429 428 if(!socket) { … … 431 430 tracker->host); 432 431 433 goto end;432 return; 434 433 } 435 434 … … 446 445 tracker->host); 447 446 448 goto end; 449 } 450 451 end: 452 wi_release(string); 453 wi_release(socket); 447 return; 448 } 454 449 } 455 450
