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
70711267
Commit
70711267
authored
Jan 15, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
InotifySource: use the SocketMonitor class
parent
2101daef
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
43 deletions
+29
-43
Makefile.am
Makefile.am
+1
-0
InotifySource.cxx
src/InotifySource.cxx
+14
-24
InotifySource.hxx
src/InotifySource.hxx
+8
-15
InotifyUpdate.cxx
src/InotifyUpdate.cxx
+2
-1
run_inotify.cxx
test/run_inotify.cxx
+4
-3
No files found.
Makefile.am
View file @
70711267
...
...
@@ -1335,6 +1335,7 @@ test_run_inotify_SOURCES = test/run_inotify.cxx \
src/fd_util.c
\
src/InotifySource.cxx
test_run_inotify_LDADD
=
\
libevent.a
\
libutil.a
\
$(GLIB_LIBS)
endif
...
...
src/InotifySource.cxx
View file @
70711267
...
...
@@ -41,8 +41,8 @@ mpd_inotify_quark(void)
return
g_quark_from_static_string
(
"inotify"
);
}
inline
void
InotifySource
::
InEvent
(
)
void
InotifySource
::
OnSocketReady
(
gcc_unused
unsigned
flags
)
{
void
*
dest
;
size_t
length
;
...
...
@@ -52,7 +52,7 @@ InotifySource::InEvent()
if
(
dest
==
NULL
)
MPD_ERROR
(
"buffer full"
);
nbytes
=
read
(
fd
,
dest
,
length
);
nbytes
=
read
(
Get
()
,
dest
,
length
);
if
(
nbytes
<
0
)
MPD_ERROR
(
"failed to read from inotify: %s"
,
g_strerror
(
errno
));
...
...
@@ -81,28 +81,21 @@ InotifySource::InEvent()
}
}
gboolean
InotifySource
::
InEvent
(
G_GNUC_UNUSED
GIOChannel
*
_source
,
G_GNUC_UNUSED
GIOCondition
condition
,
gpointer
data
)
{
InotifySource
&
source
=
*
(
InotifySource
*
)
data
;
source
.
InEvent
();
return
true
;
}
inline
InotifySource
::
InotifySource
(
mpd_inotify_callback_t
_callback
,
void
*
_ctx
,
InotifySource
::
InotifySource
(
EventLoop
&
_loop
,
mpd_inotify_callback_t
_callback
,
void
*
_ctx
,
int
_fd
)
:
callback
(
_callback
),
callback_ctx
(
_ctx
),
fd
(
_fd
),
channel
(
g_io_channel_unix_new
(
fd
)),
id
(
g_io_add_watch
(
channel
,
G_IO_IN
,
InEvent
,
this
)),
:
SocketMonitor
(
_fd
,
_loop
),
callback
(
_callback
),
callback_ctx
(
_ctx
),
buffer
(
fifo_buffer_new
(
4096
))
{
ScheduleRead
();
}
InotifySource
*
InotifySource
::
Create
(
mpd_inotify_callback_t
callback
,
void
*
callback_ctx
,
InotifySource
::
Create
(
EventLoop
&
loop
,
mpd_inotify_callback_t
callback
,
void
*
callback_ctx
,
GError
**
error_r
)
{
int
fd
=
inotify_init_cloexec
();
...
...
@@ -113,21 +106,18 @@ InotifySource::Create(mpd_inotify_callback_t callback, void *callback_ctx,
return
NULL
;
}
return
new
InotifySource
(
callback
,
callback_ctx
,
fd
);
return
new
InotifySource
(
loop
,
callback
,
callback_ctx
,
fd
);
}
InotifySource
::~
InotifySource
()
{
g_source_remove
(
id
);
g_io_channel_unref
(
channel
);
fifo_buffer_free
(
buffer
);
close
(
fd
);
}
int
InotifySource
::
Add
(
const
char
*
path_fs
,
unsigned
mask
,
GError
**
error_r
)
{
int
wd
=
inotify_add_watch
(
fd
,
path_fs
,
mask
);
int
wd
=
inotify_add_watch
(
Get
()
,
path_fs
,
mask
);
if
(
wd
<
0
)
g_set_error
(
error_r
,
mpd_inotify_quark
(),
errno
,
"inotify_add_watch() has failed: %s"
,
...
...
@@ -139,7 +129,7 @@ InotifySource::Add(const char *path_fs, unsigned mask, GError **error_r)
void
InotifySource
::
Remove
(
unsigned
wd
)
{
int
ret
=
inotify_rm_watch
(
fd
,
wd
);
int
ret
=
inotify_rm_watch
(
Get
()
,
wd
);
if
(
ret
<
0
&&
errno
!=
EINVAL
)
g_warning
(
"inotify_rm_watch() has failed: %s"
,
g_strerror
(
errno
));
...
...
src/InotifySource.hxx
View file @
70711267
...
...
@@ -20,29 +20,23 @@
#ifndef MPD_INOTIFY_SOURCE_HXX
#define MPD_INOTIFY_SOURCE_HXX
#include "event/SocketMonitor.hxx"
#include "gerror.h"
#include "gcc.h"
#include <glib.h>
typedef
void
(
*
mpd_inotify_callback_t
)(
int
wd
,
unsigned
mask
,
const
char
*
name
,
void
*
ctx
);
class
InotifySource
{
class
InotifySource
final
:
private
SocketMonitor
{
mpd_inotify_callback_t
callback
;
void
*
callback_ctx
;
int
fd
;
GIOChannel
*
channel
;
/**
* The channel's source id in the GLib main loop.
*/
guint
id
;
struct
fifo_buffer
*
buffer
;
InotifySource
(
mpd_inotify_callback_t
callback
,
void
*
ctx
,
int
fd
);
InotifySource
(
EventLoop
&
_loop
,
mpd_inotify_callback_t
callback
,
void
*
ctx
,
int
fd
);
public
:
/**
...
...
@@ -51,7 +45,8 @@ public:
*
* @param a callback invoked for events received from the kernel
*/
static
InotifySource
*
Create
(
mpd_inotify_callback_t
callback
,
static
InotifySource
*
Create
(
EventLoop
&
_loop
,
mpd_inotify_callback_t
callback
,
void
*
ctx
,
GError
**
error_r
);
...
...
@@ -73,9 +68,7 @@ public:
void
Remove
(
unsigned
wd
);
private
:
void
InEvent
();
static
gboolean
InEvent
(
GIOChannel
*
source
,
GIOCondition
condition
,
gpointer
data
);
virtual
void
OnSocketReady
(
unsigned
flags
)
override
;
};
#endif
src/InotifyUpdate.cxx
View file @
70711267
...
...
@@ -318,7 +318,8 @@ mpd_inotify_init(unsigned max_depth)
return
;
}
inotify_source
=
InotifySource
::
Create
(
mpd_inotify_callback
,
nullptr
,
inotify_source
=
InotifySource
::
Create
(
*
main_loop
,
mpd_inotify_callback
,
nullptr
,
&
error
);
if
(
inotify_source
==
NULL
)
{
g_warning
(
"%s"
,
error
->
message
);
...
...
test/run_inotify.cxx
View file @
70711267
...
...
@@ -61,7 +61,10 @@ int main(int argc, char **argv)
path
=
argv
[
1
];
InotifySource
*
source
=
InotifySource
::
Create
(
my_inotify_callback
,
event_loop
=
new
EventLoop
(
EventLoop
::
Default
());
InotifySource
*
source
=
InotifySource
::
Create
(
*
event_loop
,
my_inotify_callback
,
nullptr
,
&
error
);
if
(
source
==
NULL
)
{
g_warning
(
"%s"
,
error
->
message
);
...
...
@@ -77,8 +80,6 @@ int main(int argc, char **argv)
return
2
;
}
event_loop
=
new
EventLoop
(
EventLoop
::
Default
());
struct
sigaction
sa
;
sa
.
sa_flags
=
0
;
sigemptyset
(
&
sa
.
sa_mask
);
...
...
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