Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liblongpath-rsync
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liblongpath
liblongpath-rsync
Commits
08571358
Commit
08571358
authored
Apr 09, 2002
by
Martin Pool
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factor out bwlimit sleep code from writefd_unbuffered into its own function.
parent
8901a07f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
12 deletions
+28
-12
io.c
io.c
+28
-12
No files found.
io.c
View file @
08571358
...
@@ -390,6 +390,33 @@ unsigned char read_byte(int f)
...
@@ -390,6 +390,33 @@ unsigned char read_byte(int f)
}
}
/**
* Sleep after writing to limit I/O bandwidth usage.
*
* @todo Rather than sleeping after each write, it might be better to
* use some kind of averaging. The current algorithm seems to always
* use a bit less bandwidth than specified, because it doesn't make up
* for slow periods. But arguably this is a feature. In addition, we
* ought to take the time used to write the data into account.
**/
static
void
sleep_for_bwlimit
(
int
bytes_written
)
{
struct
timeval
tv
;
if
(
!
bwlimit
)
return
;
tv
.
tv_sec
=
0
;
tv
.
tv_usec
=
bytes_written
*
1000
/
bwlimit
;
while
(
tv
.
tv_usec
>
1000000
)
{
tv
.
tv_sec
++
;
tv
.
tv_usec
-=
1000000
;
}
select
(
0
,
NULL
,
NULL
,
NULL
,
tv
);
}
/**
/**
* Write len bytes to the file descriptor @p fd.
* Write len bytes to the file descriptor @p fd.
*
*
...
@@ -470,18 +497,7 @@ static void writefd_unbuffered(int fd,char *buf,size_t len)
...
@@ -470,18 +497,7 @@ static void writefd_unbuffered(int fd,char *buf,size_t len)
exit_cleanup
(
RERR_STREAMIO
);
exit_cleanup
(
RERR_STREAMIO
);
}
}
/* Sleep after writing to limit I/O bandwidth */
sleep_for_bwlimit
(
ret
);
if
(
bwlimit
)
{
tv
.
tv_sec
=
0
;
tv
.
tv_usec
=
ret
*
1000
/
bwlimit
;
while
(
tv
.
tv_usec
>
1000000
)
{
tv
.
tv_sec
++
;
tv
.
tv_usec
-=
1000000
;
}
select
(
0
,
NULL
,
NULL
,
NULL
,
&
tv
);
}
total
+=
ret
;
total
+=
ret
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment