1 #ifndef incl_HPHP_FILE_AWAIT_H
2 #define incl_HPHP_FILE_AWAIT_H
4 #include "hphp/runtime/ext/extension.h"
5 #include "hphp/runtime/ext/asio/asio-external-thread-event.h"
6 #include "hphp/runtime/ext/asio/socket-event.h"
13 /////////////////////////////////////////////////////////////////////////////
17 struct FileTimeoutHandler
: AsioTimeoutHandler
{
18 friend struct FileAwait
;
20 FileTimeoutHandler(AsioEventBase
* base
, FileAwait
& fa
):
21 AsioTimeoutHandler(base
), m_fileAwait(fa
) {}
23 void timeoutExpired() noexcept override
;
26 FileAwait
& m_fileAwait
;
29 struct FileEventHandler
: AsioEventHandler
{
30 friend struct FileAwait
;
32 FileEventHandler(AsioEventBase
* base
, int fd
, FileAwait
& fa
):
33 AsioEventHandler(base
, folly::NetworkSocket::fromFd(fd
)), m_fileAwait(fa
) {}
35 void handlerReady(uint16_t events
) noexcept override
;
38 FileAwait
& m_fileAwait
;
41 struct FileAwait
: AsioExternalThreadEvent
{
49 FileAwait(int fd
, uint16_t events
, std::chrono::nanoseconds timeout
);
51 void unserialize(TypedValue
& c
) override
;
52 void setFinished(int64_t status
);
54 std::unique_ptr
<FileEventHandler
> m_file
;
55 std::unique_ptr
<FileTimeoutHandler
> m_timeout
;
57 std::atomic
<bool> m_finished
{false};
60 /////////////////////////////////////////////////////////////////////////////
62 #endif // incl_HPHP_FILE_AWAIT_H