From 347c93f1c1360d7f03d337d4b428cd24ad6d7b16 Mon Sep 17 00:00:00 2001 From: Marc Olivier Chouinard Date: Wed, 30 Nov 2016 14:28:39 -0500 Subject: [PATCH] FS-9788: Add close() option to FileIO implementation --- src/mod/languages/mod_v8/include/fsfileio.hpp | 1 + src/mod/languages/mod_v8/src/fsfileio.cpp | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/mod/languages/mod_v8/include/fsfileio.hpp b/src/mod/languages/mod_v8/include/fsfileio.hpp index 05a4d220db..e232137f45 100644 --- a/src/mod/languages/mod_v8/include/fsfileio.hpp +++ b/src/mod/languages/mod_v8/include/fsfileio.hpp @@ -67,6 +67,7 @@ public: JS_FILEIO_FUNCTION_DEF(Read); JS_FILEIO_FUNCTION_DEF(Write); JS_FILEIO_FUNCTION_DEF(GetData); + JS_FILEIO_FUNCTION_DEF(Close); JS_FILEIO_GET_PROPERTY_DEF(GetProperty); }; diff --git a/src/mod/languages/mod_v8/src/fsfileio.cpp b/src/mod/languages/mod_v8/src/fsfileio.cpp index a89d1ae892..18aeba04db 100644 --- a/src/mod/languages/mod_v8/src/fsfileio.cpp +++ b/src/mod/languages/mod_v8/src/fsfileio.cpp @@ -42,9 +42,17 @@ FSFileIO::~FSFileIO(void) if (_fd) { switch_file_close(_fd); } + switch_core_destroy_memory_pool(&_pool); } +JS_FILEIO_FUNCTION_IMPL(Close) +{ + if (_fd) { + switch_file_close(_fd); + _fd = NULL; + } +} string FSFileIO::GetJSClassName() { return js_class_name; @@ -213,6 +221,7 @@ static const js_function_t fileio_proc[] = { {"read", FSFileIO::Read}, {"write", FSFileIO::Write}, {"data", FSFileIO::GetData}, + {"close", FSFileIO::Close}, {0} };