// Copyright 2009 Ryan Dahl #ifndef SRC_CHILD_PROCESS_H_ #define SRC_CHILD_PROCESS_H_ #include #include #include #include #include namespace node { class ChildProcess : EventEmitter { public: static void Initialize(v8::Handle target); protected: static v8::Persistent constructor_template; static v8::Handle New(const v8::Arguments& args); static v8::Handle Spawn(const v8::Arguments& args); static v8::Handle Write(const v8::Arguments& args); static v8::Handle Close(const v8::Arguments& args); static v8::Handle Kill(const v8::Arguments& args); static v8::Handle PIDGetter(v8::Local _, const v8::AccessorInfo& info); ChildProcess(); ~ChildProcess(); int Spawn(const char *file, char *const argv[], char *const env[]); int Write(const char *str, size_t len); int Close(void); int Kill(int sig); private: static void on_read(evcom_reader *r, const void *buf, size_t len); static void reader_closed(evcom_reader *r); static void stdin_closed(evcom_writer *w); static void OnCHLD(EV_P_ ev_child *watcher, int revents); void MaybeShutdown(void); void Shutdown(void); evcom_reader stdout_reader_; evcom_reader stderr_reader_; evcom_writer stdin_writer_; ev_child child_watcher_; int stdout_fd_; int stderr_fd_; int stdin_fd_; enum encoding stdout_encoding_; enum encoding stderr_encoding_; pid_t pid_; bool got_chld_; int exit_code_; }; } // namespace node #endif // SRC_CHILD_PROCESS_H_