void wd_broadcast(wd_chat_t *chat, uint32_t n, wi_string_t *fmt, ...) { wi_enumerator_t *enumerator; wi_string_t *string; wi_array_t *users; wd_user_t *user; va_list ap; va_start(ap, fmt); string = wi_string_init_with_format_and_arguments(wi_string_alloc(), fmt, ap); va_end(ap); users = wd_chat_users(chat); wi_array_rdlock(users); enumerator = wi_array_data_enumerator(users); while((user = wi_enumerator_next_data(enumerator))) { if(wd_user_state(user) == WD_USER_LOGGED_IN) { wd_user_lock_socket(user); wi_socket_write_format(wd_user_socket(user), 0.0, WI_STR("%u %@%c"), n, string, WD_MESSAGE_SEPARATOR); wd_user_unlock_socket(user); } } wi_array_unlock(users); wi_release(string); }
void wd_sreply(wi_socket_t *socket, uint32_t n, wi_string_t *fmt, ...) { wi_string_t *string; va_list ap; va_start(ap, fmt); string = wi_string_init_with_format_and_arguments(wi_string_alloc(), fmt, ap); va_end(ap); wi_socket_write_format(socket, 0.0, WI_STR("%u %@%c"), n, string, WD_MESSAGE_SEPARATOR); wi_release(string); }
void wd_reply(uint32_t n, wi_string_t *fmt, ...) { wd_user_t *user = wd_users_user_for_thread(); wi_string_t *string; va_list ap; va_start(ap, fmt); string = wi_string_init_with_format_and_arguments(wi_string_alloc(), fmt, ap); va_end(ap); wd_user_lock_socket(user); wi_socket_write_format(wd_user_socket(user), 0.0, WI_STR("%u %@%c"), n, string, WD_MESSAGE_SEPARATOR); wd_user_unlock_socket(user); wi_release(string); }
static wi_boolean_t wd_tracker_write(wd_tracker_t *tracker, wi_string_t *fmt, ...) { wi_string_t *string; wi_integer_t bytes; va_list ap; va_start(ap, fmt); string = wi_string_init_with_format_and_arguments(wi_string_alloc(), fmt, ap); va_end(ap); bytes = wi_socket_write_format(tracker->socket, 30.0, WI_STR("%@%c"), string, WD_MESSAGE_SEPARATOR); if(bytes <= 0) { wi_log_err(WI_STR("Could not write to tracker %@: %m"), tracker->host); } wi_release(string); return (bytes > 0); }
wi_boolean_t wr_send_command_on_socket(wi_socket_t *socket, wi_string_t *fmt, ...) { wi_mutable_string_t *string; wi_integer_t result; va_list ap; va_start(ap, fmt); string = wi_string_init_with_format_and_arguments(wi_mutable_string_alloc(), fmt, ap); va_end(ap); wi_mutable_string_convert_encoding(string, wr_client_string_encoding, wr_server_string_encoding); result = wi_socket_write_format(socket, 15.0, WI_STR("%@%c"), string, WR_MESSAGE_SEPARATOR); if(result <= 0) wr_printf_prefix(WI_STR("Could not write to server: %m")); wi_release(string); return (result > 0); }