Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
1f3d3970
Commit
1f3d3970
authored
10 years ago
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/update/InotifySource: remove FifoBuffer
Eliminate support for partial reads. The Linux kernel will never return partial results, so this buffering was unnecessary.
parent
c9a71a71
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
16 deletions
+15
-16
InotifySource.cxx
src/db/update/InotifySource.cxx
+15
-13
InotifySource.hxx
src/db/update/InotifySource.hxx
+0
-3
No files found.
src/db/update/InotifySource.cxx
View file @
1f3d3970
...
@@ -25,43 +25,45 @@
...
@@ -25,43 +25,45 @@
#include "system/FatalError.hxx"
#include "system/FatalError.hxx"
#include "Log.hxx"
#include "Log.hxx"
#include <algorithm>
#include <sys/inotify.h>
#include <sys/inotify.h>
#include <unistd.h>
#include <unistd.h>
#include <errno.h>
#include <errno.h>
#include <stdint.h>
#include <limits.h>
bool
bool
InotifySource
::
OnSocketReady
(
gcc_unused
unsigned
flags
)
InotifySource
::
OnSocketReady
(
gcc_unused
unsigned
flags
)
{
{
const
auto
dest
=
buffer
.
Write
()
;
uint8_t
buffer
[
4096
]
;
if
(
dest
.
IsEmpty
())
static_assert
(
sizeof
(
buffer
)
>=
sizeof
(
struct
inotify_event
)
+
NAME_MAX
+
1
,
FatalError
(
"buffer fu
ll"
);
"inotify buffer too sma
ll"
);
ssize_t
nbytes
=
read
(
Get
(),
dest
.
data
,
dest
.
size
);
ssize_t
nbytes
=
read
(
Get
(),
buffer
,
sizeof
(
buffer
)
);
if
(
nbytes
<
0
)
if
(
nbytes
<
0
)
FatalSystemError
(
"Failed to read from inotify"
);
FatalSystemError
(
"Failed to read from inotify"
);
if
(
nbytes
==
0
)
if
(
nbytes
==
0
)
FatalError
(
"end of file from inotify"
);
FatalError
(
"end of file from inotify"
);
buffer
.
Append
(
nbytes
)
;
const
uint8_t
*
p
=
buffer
,
*
const
end
=
p
+
nbytes
;
while
(
true
)
{
while
(
true
)
{
const
char
*
name
;
const
size_t
remaining
=
end
-
p
;
auto
range
=
buffer
.
Read
();
const
struct
inotify_event
*
event
=
const
struct
inotify_event
*
event
=
(
const
struct
inotify_event
*
)
(
const
struct
inotify_event
*
)
p
;
range
.
data
;
if
(
remaining
<
sizeof
(
*
event
)
||
if
(
range
.
size
<
sizeof
(
*
event
)
||
remaining
<
sizeof
(
*
event
)
+
event
->
len
)
range
.
size
<
sizeof
(
*
event
)
+
event
->
len
)
break
;
break
;
const
char
*
name
;
if
(
event
->
len
>
0
&&
event
->
name
[
event
->
len
-
1
]
==
0
)
if
(
event
->
len
>
0
&&
event
->
name
[
event
->
len
-
1
]
==
0
)
name
=
event
->
name
;
name
=
event
->
name
;
else
else
name
=
nullptr
;
name
=
nullptr
;
callback
(
event
->
wd
,
event
->
mask
,
name
,
callback_ctx
);
callback
(
event
->
wd
,
event
->
mask
,
name
,
callback_ctx
);
buffer
.
Consume
(
sizeof
(
*
event
)
+
event
->
len
)
;
p
+=
sizeof
(
*
event
)
+
event
->
len
;
}
}
return
true
;
return
true
;
...
...
This diff is collapsed.
Click to expand it.
src/db/update/InotifySource.hxx
View file @
1f3d3970
...
@@ -21,7 +21,6 @@
...
@@ -21,7 +21,6 @@
#define MPD_INOTIFY_SOURCE_HXX
#define MPD_INOTIFY_SOURCE_HXX
#include "event/SocketMonitor.hxx"
#include "event/SocketMonitor.hxx"
#include "util/FifoBuffer.hxx"
class
Error
;
class
Error
;
...
@@ -32,8 +31,6 @@ class InotifySource final : private SocketMonitor {
...
@@ -32,8 +31,6 @@ class InotifySource final : private SocketMonitor {
mpd_inotify_callback_t
callback
;
mpd_inotify_callback_t
callback
;
void
*
callback_ctx
;
void
*
callback_ctx
;
FifoBuffer
<
uint8_t
,
4096
>
buffer
;
InotifySource
(
EventLoop
&
_loop
,
InotifySource
(
EventLoop
&
_loop
,
mpd_inotify_callback_t
callback
,
void
*
ctx
,
int
fd
);
mpd_inotify_callback_t
callback
,
void
*
ctx
,
int
fd
);
...
...
This diff is collapsed.
Click to expand it.
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