Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tarantool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
tarantool
Commits
c5834d94
Commit
c5834d94
authored
11 years ago
by
Dmitry E. Oboukhov
Browse files
Options
Downloads
Patches
Plain Diff
Drop recursive calls. Rewrite by review.
parent
5e54cb0b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/fiob.c
+31
-47
31 additions, 47 deletions
src/fiob.c
src/log_io.cc
+1
-1
1 addition, 1 deletion
src/log_io.cc
test/unit/fiob.c
+3
-3
3 additions, 3 deletions
test/unit/fiob.c
with
35 additions
and
51 deletions
src/fiob.c
+
31
−
47
View file @
c5834d94
...
...
@@ -109,26 +109,22 @@ fiob_flushb(struct fiob *f)
if
(
!
f
->
buf
||
!
f
->
bfill
)
return
0
;
off_t
cur
=
lseek
(
f
->
fd
,
0L
,
SEEK_CUR
);
if
(
cur
==
(
off_t
)
-
1
)
return
-
1
;
off_t
size
=
lseek
(
f
->
fd
,
0L
,
SEEK_END
);
if
(
size
==
(
off_t
)
-
1
)
return
-
1
;
if
(
lseek
(
f
->
fd
,
cur
,
SEEK_SET
)
==
(
off_t
)
-
1
)
return
-
1
;
assert
(
cur
+
f
->
bfill
>=
size
);
size_t
tlen
=
f
->
bfill
/
4096
;
if
(
f
->
bfill
%
4096
)
tlen
++
;
tlen
*=
4096
;
if
(
fiob_writef
(
f
,
f
->
buf
,
f
->
bsize
)
<
0
)
if
(
fiob_writef
(
f
,
f
->
buf
,
tlen
)
<
0
)
{
return
-
1
;
}
if
(
lseek
(
f
->
fd
,
cur
+
f
->
bfill
,
SEEK_SET
)
==
(
off_t
)
-
1
)
off_t
size
=
lseek
(
f
->
fd
,
(
off_t
)(
f
->
bfill
)
-
tlen
,
SEEK_CUR
);
if
(
size
==
(
off_t
)
-
1
)
{
return
-
1
;
}
int
res
=
ftruncate
(
f
->
fd
,
size
);
int
res
=
ftruncate
(
f
->
fd
,
cur
+
f
->
bfill
);
f
->
bfill
=
0
;
return
res
;
}
...
...
@@ -143,54 +139,42 @@ fiob_write(void *cookie, const char *buf, size_t len)
#endif
{
struct
fiob
*
f
=
(
struct
fiob
*
)
cookie
;
ssize_t
wrdone
;
if
(
f
->
buf
)
{
/* append buffer */
if
(
f
->
bsize
-
f
->
bfill
>=
len
)
{
memcpy
(
f
->
buf
+
f
->
bfill
,
buf
,
len
);
f
->
bfill
+=
len
;
return
len
;
}
if
(
len
==
0
)
return
0
;
if
(
!
f
->
buf
)
return
fiob_writef
(
f
,
buf
,
len
);
/* buffer is full */
if
(
f
->
bfill
>=
f
->
bsize
)
{
wrdone
=
fiob_writef
(
f
,
f
->
buf
,
f
->
bsize
);
if
(
wrdone
<
0
)
return
wrdone
;
f
->
bfill
=
0
;
return
fiob_write
(
cookie
,
buf
,
len
);
for
(
ssize_t
wrdone
=
0
,
wrote
;;)
{
/* append buffer */
if
(
f
->
bsize
-
f
->
bfill
>
len
)
{
memcpy
(
f
->
buf
+
f
->
bfill
,
buf
,
len
);
f
->
bfill
+=
len
;
return
wrdone
+
len
;
}
/* data is longer than buffer */
memcpy
(
f
->
buf
+
f
->
bfill
,
buf
,
f
->
bsize
-
f
->
bfill
);
wrdone
=
fiob_writef
(
f
,
f
->
buf
,
f
->
bsize
);
if
(
f
->
bsize
>
f
->
bfill
)
memcpy
(
f
->
buf
+
f
->
bfill
,
buf
,
f
->
bsize
-
f
->
bfill
);
if
(
wrdone
<
0
)
return
wrdone
;
wrdone
-=
f
->
bfill
;
wrote
=
fiob_writef
(
f
,
f
->
buf
,
f
->
bsize
);
if
(
wrote
<
0
)
return
wrote
;
wrote
-=
f
->
bfill
;
wrdone
+=
wrote
;
f
->
bfill
=
0
;
buf
+=
wr
don
e
;
len
-=
wr
don
e
;
buf
+=
wr
ot
e
;
len
-=
wr
ot
e
;
if
(
len
>
0
)
{
ssize_t
wrtail
=
fiob_write
(
cookie
,
buf
,
len
);
if
(
wrtail
<
0
)
return
wrtail
;
wrdone
+=
wrtail
;
}
if
(
len
>
0
)
continue
;
return
wrdone
;
}
return
fiob_writef
(
f
,
buf
,
len
);
}
#ifdef HAVE_FUNOPEN
...
...
This diff is collapsed.
Click to expand it.
src/log_io.cc
+
1
−
1
View file @
c5834d94
...
...
@@ -614,7 +614,7 @@ log_io_open_for_read(struct log_dir *dir, int64_t lsn, enum log_suffix suffix)
assert
(
lsn
!=
0
);
const
char
*
filename
=
format_filename
(
dir
,
lsn
,
suffix
);
FILE
*
f
=
f
iob_
open
(
filename
,
"r"
);
FILE
*
f
=
fopen
(
filename
,
"r"
);
return
log_io_open
(
dir
,
LOG_READ
,
filename
,
suffix
,
f
);
}
...
...
This diff is collapsed.
Click to expand it.
test/unit/fiob.c
+
3
−
3
View file @
c5834d94
...
...
@@ -194,9 +194,9 @@ main(void)
fgets
(
buf
,
4096
,
f
);
if
(
strcmp
(
buf
,
"Hello, world
\n
"
)
==
0
)
done
++
;
else
fprintf
(
stderr
,
"# wrong line %zu: %s"
,
i
,
buf
);
/*
else
*/
/*
fprintf(stderr, "# wrong line %zu: %s",
*/
/*
i, buf);
*/
}
is
(
done
,
1000000
+
1
,
"all records were written properly"
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment