event/SocketMonitor: OnSocketReady() returns bool
This commit is contained in:
parent
73f36858bb
commit
4ad7456428
@ -41,7 +41,7 @@ mpd_inotify_quark(void)
|
|||||||
return g_quark_from_static_string("inotify");
|
return g_quark_from_static_string("inotify");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
InotifySource::OnSocketReady(gcc_unused unsigned flags)
|
InotifySource::OnSocketReady(gcc_unused unsigned flags)
|
||||||
{
|
{
|
||||||
void *dest;
|
void *dest;
|
||||||
@ -79,6 +79,8 @@ InotifySource::OnSocketReady(gcc_unused unsigned flags)
|
|||||||
callback(event->wd, event->mask, name, callback_ctx);
|
callback(event->wd, event->mask, name, callback_ctx);
|
||||||
fifo_buffer_consume(buffer, sizeof(*event) + event->len);
|
fifo_buffer_consume(buffer, sizeof(*event) + event->len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
|
@ -68,7 +68,7 @@ public:
|
|||||||
void Remove(unsigned wd);
|
void Remove(unsigned wd);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void OnSocketReady(unsigned flags) override;
|
virtual bool OnSocketReady(unsigned flags) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -101,7 +101,7 @@ struct OneServerSocket final : private SocketMonitor {
|
|||||||
void Accept();
|
void Accept();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void OnSocketReady(unsigned flags) override;
|
virtual bool OnSocketReady(unsigned flags) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct server_socket {
|
struct server_socket {
|
||||||
@ -205,10 +205,11 @@ OneServerSocket::Accept()
|
|||||||
parent.callback_ctx);
|
parent.callback_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
OneServerSocket::OnSocketReady(gcc_unused unsigned flags)
|
OneServerSocket::OnSocketReady(gcc_unused unsigned flags)
|
||||||
{
|
{
|
||||||
Accept();
|
Accept();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
|
@ -202,21 +202,21 @@ BufferedSocket::ConsumeInput(size_t nbytes)
|
|||||||
fifo_buffer_consume(input, nbytes);
|
fifo_buffer_consume(input, nbytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
BufferedSocket::OnSocketReady(unsigned flags)
|
BufferedSocket::OnSocketReady(unsigned flags)
|
||||||
{
|
{
|
||||||
assert(IsDefined());
|
assert(IsDefined());
|
||||||
|
|
||||||
if (gcc_unlikely(flags & (ERROR|HANGUP))) {
|
if (gcc_unlikely(flags & (ERROR|HANGUP))) {
|
||||||
OnSocketClosed();
|
OnSocketClosed();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & READ) {
|
if (flags & READ) {
|
||||||
assert(input == nullptr || !fifo_buffer_is_full(input));
|
assert(input == nullptr || !fifo_buffer_is_full(input));
|
||||||
|
|
||||||
if (!ReadToBuffer() || !ResumeInput())
|
if (!ReadToBuffer() || !ResumeInput())
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
if (input == nullptr || !fifo_buffer_is_full(input))
|
if (input == nullptr || !fifo_buffer_is_full(input))
|
||||||
ScheduleRead();
|
ScheduleRead();
|
||||||
@ -233,6 +233,8 @@ BufferedSocket::OnSocketReady(unsigned flags)
|
|||||||
assert(!output.IsEmpty());
|
assert(!output.IsEmpty());
|
||||||
|
|
||||||
if (!WriteFromBuffer())
|
if (!WriteFromBuffer())
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ protected:
|
|||||||
virtual void OnSocketClosed() = 0;
|
virtual void OnSocketClosed() = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void OnSocketReady(unsigned flags) override;
|
virtual bool OnSocketReady(unsigned flags) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -115,7 +115,10 @@ public:
|
|||||||
ssize_t Write(const void *data, size_t length);
|
ssize_t Write(const void *data, size_t length);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void OnSocketReady(unsigned flags) = 0;
|
/**
|
||||||
|
* @return false if the socket has been closed
|
||||||
|
*/
|
||||||
|
virtual bool OnSocketReady(unsigned flags) = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/* GSource callbacks */
|
/* GSource callbacks */
|
||||||
|
Loading…
Reference in New Issue
Block a user