aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-30 10:53:32 +0100
committerMax Kellermann <max@duempel.org>2013-01-30 11:03:44 +0100
commit4ad7456428913f5232768367f2c0694bcb4540bb (patch)
tree213a06a779ca285f6cec035cb3385bd0b96d0164
parent73f36858bb4026eff7c9e44007c87e870d324a5f (diff)
downloadmpd-4ad7456428913f5232768367f2c0694bcb4540bb.tar.gz
mpd-4ad7456428913f5232768367f2c0694bcb4540bb.tar.xz
mpd-4ad7456428913f5232768367f2c0694bcb4540bb.zip
event/SocketMonitor: OnSocketReady() returns bool
-rw-r--r--src/InotifySource.cxx4
-rw-r--r--src/InotifySource.hxx2
-rw-r--r--src/ServerSocket.cxx5
-rw-r--r--src/event/BufferedSocket.cxx10
-rw-r--r--src/event/BufferedSocket.hxx2
-rw-r--r--src/event/SocketMonitor.hxx5
6 files changed, 18 insertions, 10 deletions
diff --git a/src/InotifySource.cxx b/src/InotifySource.cxx
index 5da32c9bd..5552ed578 100644
--- a/src/InotifySource.cxx
+++ b/src/InotifySource.cxx
@@ -41,7 +41,7 @@ mpd_inotify_quark(void)
return g_quark_from_static_string("inotify");
}
-void
+bool
InotifySource::OnSocketReady(gcc_unused unsigned flags)
{
void *dest;
@@ -79,6 +79,8 @@ InotifySource::OnSocketReady(gcc_unused unsigned flags)
callback(event->wd, event->mask, name, callback_ctx);
fifo_buffer_consume(buffer, sizeof(*event) + event->len);
}
+
+ return true;
}
inline
diff --git a/src/InotifySource.hxx b/src/InotifySource.hxx
index 0f29ae754..d174cc863 100644
--- a/src/InotifySource.hxx
+++ b/src/InotifySource.hxx
@@ -68,7 +68,7 @@ public:
void Remove(unsigned wd);
private:
- virtual void OnSocketReady(unsigned flags) override;
+ virtual bool OnSocketReady(unsigned flags) override;
};
#endif
diff --git a/src/ServerSocket.cxx b/src/ServerSocket.cxx
index 7f14168a8..a1e2ee01e 100644
--- a/src/ServerSocket.cxx
+++ b/src/ServerSocket.cxx
@@ -101,7 +101,7 @@ struct OneServerSocket final : private SocketMonitor {
void Accept();
private:
- virtual void OnSocketReady(unsigned flags) override;
+ virtual bool OnSocketReady(unsigned flags) override;
};
struct server_socket {
@@ -205,10 +205,11 @@ OneServerSocket::Accept()
parent.callback_ctx);
}
-void
+bool
OneServerSocket::OnSocketReady(gcc_unused unsigned flags)
{
Accept();
+ return true;
}
inline bool
diff --git a/src/event/BufferedSocket.cxx b/src/event/BufferedSocket.cxx
index b95519e49..dec60b5f7 100644
--- a/src/event/BufferedSocket.cxx
+++ b/src/event/BufferedSocket.cxx
@@ -202,21 +202,21 @@ BufferedSocket::ConsumeInput(size_t nbytes)
fifo_buffer_consume(input, nbytes);
}
-void
+bool
BufferedSocket::OnSocketReady(unsigned flags)
{
assert(IsDefined());
if (gcc_unlikely(flags & (ERROR|HANGUP))) {
OnSocketClosed();
- return;
+ return false;
}
if (flags & READ) {
assert(input == nullptr || !fifo_buffer_is_full(input));
if (!ReadToBuffer() || !ResumeInput())
- return;
+ return false;
if (input == nullptr || !fifo_buffer_is_full(input))
ScheduleRead();
@@ -233,6 +233,8 @@ BufferedSocket::OnSocketReady(unsigned flags)
assert(!output.IsEmpty());
if (!WriteFromBuffer())
- return;
+ return false;
}
+
+ return true;
}
diff --git a/src/event/BufferedSocket.hxx b/src/event/BufferedSocket.hxx
index 6e55a5e19..23fd97d38 100644
--- a/src/event/BufferedSocket.hxx
+++ b/src/event/BufferedSocket.hxx
@@ -113,7 +113,7 @@ protected:
virtual void OnSocketClosed() = 0;
private:
- virtual void OnSocketReady(unsigned flags) override;
+ virtual bool OnSocketReady(unsigned flags) override;
};
#endif
diff --git a/src/event/SocketMonitor.hxx b/src/event/SocketMonitor.hxx
index b8ded1967..c815e4f53 100644
--- a/src/event/SocketMonitor.hxx
+++ b/src/event/SocketMonitor.hxx
@@ -115,7 +115,10 @@ public:
ssize_t Write(const void *data, size_t length);
protected:
- virtual void OnSocketReady(unsigned flags) = 0;
+ /**
+ * @return false if the socket has been closed
+ */
+ virtual bool OnSocketReady(unsigned flags) = 0;
public:
/* GSource callbacks */