track total size of static array and Unit/Class/Func
[hiphop-php.git] / hphp / runtime / base / file-await.h
blob972ea43a5360e6b61b3018f73f1044e84a6e091a
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"
8 #include <atomic>
9 #include <chrono>
10 #include <memory>
12 namespace HPHP {
13 /////////////////////////////////////////////////////////////////////////////
15 struct FileAwait;
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;
25 private:
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;
37 private:
38 FileAwait& m_fileAwait;
41 struct FileAwait : AsioExternalThreadEvent {
42 enum Status {
43 ERROR = -1,
44 TIMEOUT = 0,
45 READY,
46 CLOSED,
49 FileAwait(int fd, uint16_t events, std::chrono::nanoseconds timeout);
50 ~FileAwait();
51 void unserialize(TypedValue& c) override;
52 void setFinished(int64_t status);
53 private:
54 std::unique_ptr<FileEventHandler> m_file;
55 std::unique_ptr<FileTimeoutHandler> m_timeout;
56 int m_result{-1};
57 std::atomic<bool> m_finished{false};
60 /////////////////////////////////////////////////////////////////////////////
61 } // namespace HPHP
62 #endif // incl_HPHP_FILE_AWAIT_H