コード例 #1
0
ファイル: transfers.c プロジェクト: ProfDrLuigi/zanka
static inline void wd_transfer_limit_upload_speed(wd_transfer_t *transfer, wd_account_t *account, ssize_t bytes, wi_time_interval_t now, wi_time_interval_t then) {
	wi_uinteger_t	limit, totallimit;
	
	if(account->upload_speed > 0 || wd_settings.totaluploadspeed > 0) {
		totallimit = (wd_settings.totaluploadspeed > 0)
			? (float) wd_settings.totaluploadspeed / (float) wd_current_uploads
			: 0;
		
		if(totallimit > 0 && account->upload_speed > 0)
			limit = WI_MIN(totallimit, account->upload_speed);
		else if(totallimit > 0)
			limit = totallimit;
		else
			limit = account->upload_speed;

		if(limit > 0) {
			while(transfer->speed > limit) {
				usleep(10000);
				now += 0.01;
				
				transfer->speed = bytes / (now - then);
			}
		}
	}
}
コード例 #2
0
ファイル: wi-file.c プロジェクト: axelandersson/libwired
wi_data_t * wi_file_read(wi_file_t *file, wi_uinteger_t length) {
    wi_mutable_data_t   *data;
    char                buffer[WI_FILE_BUFFER_SIZE];
    wi_integer_t        bytes = -1;
    
    _WI_FILE_ASSERT_OPEN(file);
    
    data = wi_data_init_with_capacity(wi_mutable_data_alloc(), length);
    
    while(length > 0) {
        bytes = wi_file_read_bytes(file, buffer, WI_MIN(sizeof(buffer), length));
        
        if(bytes <= 0)
            break;
        
        wi_mutable_data_append_bytes(data, buffer, bytes);
        
        length -= bytes;
    }
    
    if(bytes < 0) {
        wi_release(data);
        
        data = NULL;
    }
    
    wi_runtime_make_immutable(data);

    return wi_autorelease(data);
}
コード例 #3
0
ファイル: transfers.c プロジェクト: ProfDrLuigi/zanka
static inline void wd_transfer_limit_speed(wd_transfer_t *transfer, wi_uinteger_t totalspeed, wi_uinteger_t accountspeed, wi_uinteger_t totalcount, wi_uinteger_t accountcount, ssize_t bytes, wi_time_interval_t now, wi_time_interval_t then) {
	wi_uinteger_t		limit, totallimit, accountlimit;
	wi_time_interval_t	start;
	
	if(totalspeed > 0 || accountspeed > 0) {
		totallimit		= (totalspeed > 0 && totalcount > 0) ? (float) totalspeed / (float) totalcount : 0;
		accountlimit	= (accountspeed > 0 && accountcount > 0) ? (float) accountspeed / (float) accountcount : 0;
		
		if(totallimit > 0 && accountlimit > 0)
			limit = WI_MIN(totallimit, accountlimit);
		else if(totallimit > 0)
			limit = totallimit;
		else
			limit = accountlimit;

		if(limit > 0) {
			start = now;
			
			while(transfer->speed > limit && now - start < 5.0) {
				usleep(10000);
				now += 0.01;
				
				transfer->speed = bytes / (now - then);
			}
		}
	}
}
コード例 #4
0
ファイル: wi-date.c プロジェクト: ProfDrLuigi/zanka
static wi_boolean_t _wi_date_is_equal(wi_runtime_instance_t *instance1, wi_runtime_instance_t *instance2) {
	wi_date_t		*date1 = instance1;
	wi_date_t		*date2 = instance2;
	
	return (WI_MAX(date1, date2) - WI_MIN(date1, date2) < _WI_DATE_EPSILON);
}
コード例 #5
0
ファイル: wi-data.c プロジェクト: ProfDrLuigi/zanka
static wi_hash_code_t _wi_data_hash(wi_runtime_instance_t *instance) {
	wi_data_t		*data = instance;
	
	return wi_hash_data(data->bytes, WI_MIN(data->length, 16));
}