2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_HTTP_SERVER_TAKEOVER_AGENT_H_
18 #define incl_HPHP_HTTP_SERVER_TAKEOVER_AGENT_H_
26 #include "hphp/runtime/base/type-string.h"
29 ///////////////////////////////////////////////////////////////////////////////
32 * A callback to be informed when a server is shutting down because its socket
33 * has been taken over by a new process.
35 struct TakeoverListener
{
36 virtual ~TakeoverListener();
37 virtual void takeoverShutdown() = 0;
42 * Agent with the ability to take over an accept socket
43 * from another process, and give its accept socket up.
45 struct TakeoverAgent
{
46 enum class RequestType
{
52 virtual ~Callback() {}
53 // Called by the TakeoverAgent when it receives a request for takeover
54 // Returns non zero on error, which terminates the takeover action
55 virtual int onTakeoverRequest(RequestType type
) = 0;
57 // Called by the TakeoverAgent when it is shutdown mid-way through a
59 virtual void takeoverAborted() = 0;
62 explicit TakeoverAgent(const std::string
&fname
);
64 // execute a takeover and return the fd. -1 if an fd could not be acquired
65 int takeover(std::chrono::seconds timeout
= std::chrono::seconds(2));
67 // instruct the old server to shutdown
68 void requestShutdown();
70 // setup a server to listen for takeover requests
71 int setupFdServer(event_base
*eventBase
, int sock
, Callback
*callback
);
73 // stop the takeover agent, including in-progress takeovers
76 void addTakeoverListener(TakeoverListener
* listener
) {
77 m_takeover_listeners
.insert(listener
);
79 void removeTakeoverListener(TakeoverListener
* listener
) {
80 m_takeover_listeners
.erase(listener
);
83 // These are public so they can be called from a C-style callback.
84 // They are not a part of the public interface.
85 void afdtResponse(String response
, int fd
);
86 int afdtRequest(String request
, String
* response
);
90 enum class TakeoverState
{
96 void notifyTakeoverComplete();
98 void* m_delete_handle
;
99 std::string m_transfer_fname
;
100 std::set
<TakeoverListener
*> m_takeover_listeners
;
102 // Was this server initiated with a socket from another server?
105 // The state of taking over this server's socket
106 TakeoverState m_takeover_state
;
111 // User callback for events
112 Callback
*m_callback
{nullptr};
115 ///////////////////////////////////////////////////////////////////////////////
118 #endif // incl_HPHP_HTTP_SERVER_TAKEOVER_AGENT_H_