Node.js  v8.x
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine
inspector_socket_server.h
Go to the documentation of this file.
1 #ifndef SRC_INSPECTOR_SOCKET_SERVER_H_
2 #define SRC_INSPECTOR_SOCKET_SERVER_H_
3 
4 #include "inspector_agent.h"
5 #include "inspector_socket.h"
6 #include "uv.h"
7 
8 #include <map>
9 #include <string>
10 #include <vector>
11 
12 #if !HAVE_INSPECTOR
13 #error("This header can only be used when inspector is enabled")
14 #endif
15 
16 namespace node {
17 namespace inspector {
18 
19 class Closer;
20 class SocketSession;
21 class ServerSocket;
22 
24  public:
25  virtual bool StartSession(int session_id, const std::string& target_id) = 0;
26  virtual void EndSession(int session_id) = 0;
27  virtual void MessageReceived(int session_id, const std::string& message) = 0;
28  virtual std::vector<std::string> GetTargetIds() = 0;
29  virtual std::string GetTargetTitle(const std::string& id) = 0;
30  virtual std::string GetTargetUrl(const std::string& id) = 0;
31  virtual void ServerDone() = 0;
32 };
33 
34 // HTTP Server, writes messages requested as TransportActions, and responds
35 // to HTTP requests and WS upgrades.
36 
37 
38 
40  public:
43  uv_loop_t* loop,
44  const std::string& host,
45  int port,
46  FILE* out = stderr);
47  // Start listening on host/port
48  bool Start();
49 
50  // Called by the TransportAction sent with InspectorIo::Write():
51  // kKill and kStop
52  void Stop(ServerCallback callback);
53  // kSendMessage
54  void Send(int session_id, const std::string& message);
55  // kKill
56  void TerminateConnections();
57 
58  int Port() const;
59 
60  // Server socket lifecycle. There may be multiple sockets
61  void ServerSocketListening(ServerSocket* server_socket);
62  void ServerSocketClosed(ServerSocket* server_socket);
63 
64  // Session connection lifecycle
65  bool HandleGetRequest(InspectorSocket* socket, const std::string& path);
66  bool SessionStarted(SocketSession* session, const std::string& id);
67  void SessionTerminated(SocketSession* session);
68  void MessageReceived(int session_id, const std::string& message) {
69  delegate_->MessageReceived(session_id, message);
70  }
71 
73  return next_session_id_++;
74  }
75 
76  private:
77  void SendListResponse(InspectorSocket* socket);
78  bool TargetExists(const std::string& id);
79 
80  enum class ServerState {kNew, kRunning, kStopping, kStopped};
81  uv_loop_t* loop_;
82  SocketServerDelegate* const delegate_;
83  const std::string host_;
84  int port_;
85  std::string path_;
86  std::vector<ServerSocket*> server_sockets_;
87  Closer* closer_;
88  std::map<int, SocketSession*> connected_sessions_;
89  int next_session_id_;
90  FILE* out_;
91  ServerState state_;
92 
93  friend class Closer;
94 };
95 
96 } // namespace inspector
97 } // namespace node
98 
99 #endif // SRC_INSPECTOR_SOCKET_SERVER_H_
virtual void MessageReceived(int session_id, const std::string &message)=0
virtual bool StartSession(int session_id, const std::string &target_id)=0
hostent * host
Definition: cares_wrap.cc:482
void MessageReceived(int session_id, const std::string &message)
virtual std::vector< std::string > GetTargetIds()=0
void(*)(InspectorSocketServer *) ServerCallback
virtual std::string GetTargetTitle(const std::string &id)=0
virtual std::string GetTargetUrl(const std::string &id)=0
virtual void EndSession(int session_id)=0
int Start(Isolate *isolate, IsolateData *isolate_data, int argc, const char *const *argv, int exec_argc, const char *const *exec_argv)
Definition: node.cc:4536