event/SocketMonitor: OnSocketReady() returns bool

This commit is contained in:
Max Kellermann 2013-01-30 10:53:32 +01:00
parent 73f36858bb
commit 4ad7456428
6 changed files with 18 additions and 10 deletions

View File

@ -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

View File

@ -68,7 +68,7 @@ public:
void Remove(unsigned wd);
private:
virtual void OnSocketReady(unsigned flags) override;
virtual bool OnSocketReady(unsigned flags) override;
};
#endif

View File

@ -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

View File

@ -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;
}

View File

@ -113,7 +113,7 @@ protected:
virtual void OnSocketClosed() = 0;
private:
virtual void OnSocketReady(unsigned flags) override;
virtual bool OnSocketReady(unsigned flags) override;
};
#endif

View File

@ -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 */