feat(pty): use process internal, not _process

This commit is contained in:
Leroy Hopson 2024-03-01 20:25:51 +13:00
parent 91aee43a30
commit 39b5614f61
No known key found for this signature in database
GPG key ID: D2747312A6DB51AA
2 changed files with 19 additions and 5 deletions

View file

@ -131,6 +131,9 @@ Error PTY::fork(const String &file, const PackedStringArray &args, const String
} }
#endif #endif
status = STATUS_CONNECTED;
set_process_internal(true);
return OK; return OK;
} }
@ -191,19 +194,31 @@ void PTY::write(const Variant &data) const {
} }
} }
void PTY::_process(double delta) { void PTY::_notification(int p_what) {
switch (p_what)
{
case NOTIFICATION_INTERNAL_PROCESS:
_run(UV_RUN_NOWAIT);
break;
}
}
void PTY::_run(uv_run_mode mode) {
#if defined(__linux__) || defined(__APPLE__) #if defined(__linux__) || defined(__APPLE__)
if (status == STATUS_CONNECTED) { if (status == STATUS_CONNECTED) {
if (!uv_is_active((uv_handle_t *)&pipe)) { if (!uv_is_active((uv_handle_t *)&pipe)) {
uv_read_start((uv_stream_t *)&pipe, _alloc_buffer, _read_cb); uv_read_start((uv_stream_t *)&pipe, _alloc_buffer, _read_cb);
} }
uv_run(uv_default_loop(), UV_RUN_NOWAIT); uv_run(uv_default_loop(), mode);
} }
#endif #endif
} }
void PTY::_close() { void PTY::_close() {
set_process_internal(false);
status = STATUS_NONE;
#if defined(__linux__) || defined(__APPLE__) #if defined(__linux__) || defined(__APPLE__)
if (!uv_is_closing((uv_handle_t *)&pipe)) { if (!uv_is_closing((uv_handle_t *)&pipe)) {
uv_close((uv_handle_t *)&pipe, _close_cb); uv_close((uv_handle_t *)&pipe, _close_cb);
@ -216,7 +231,6 @@ void PTY::_close() {
fd = -1; fd = -1;
pid = -1; pid = -1;
status = STATUS_NONE;
#endif #endif
} }
@ -350,7 +364,6 @@ Error PTY::_pipe_open(const int fd) {
ERR_FAIL_UV_ERR(uv_stream_set_blocking((uv_stream_t *)&pipe, false)); ERR_FAIL_UV_ERR(uv_stream_set_blocking((uv_stream_t *)&pipe, false));
ERR_FAIL_UV_ERR(uv_read_start((uv_stream_t *)&pipe, _alloc_buffer, _read_cb)); ERR_FAIL_UV_ERR(uv_read_start((uv_stream_t *)&pipe, _alloc_buffer, _read_cb));
status = STATUS_CONNECTED;
return OK; return OK;
} }

View file

@ -63,7 +63,8 @@ namespace godot
void resizev(const Vector2i &size) const { resize(size.x, size.y); }; void resizev(const Vector2i &size) const { resize(size.x, size.y); };
void write(const Variant &data) const; void write(const Variant &data) const;
void _process(double delta) override; void _notification(int p_what);
void _run(uv_run_mode mode);
protected: protected:
static void _bind_methods(); static void _bind_methods();