Skip to content

Commit

Permalink
fs, feat: File add fd property (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngot authored and xicilion committed Jun 19, 2017
1 parent 18cad50 commit 9ed5946
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions fibjs/include/File.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class File : public File_base {
public:
// File_base
virtual result_t get_name(exlib::string& retVal);
virtual result_t get_fd(int32_t& retVal);
virtual result_t chmod(int32_t mode, AsyncEvent* ac);

public:
Expand Down
17 changes: 16 additions & 1 deletion fibjs/include/ifs/File.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class File_base : public SeekableStream_base {
public:
// File_base
virtual result_t get_name(exlib::string& retVal) = 0;
virtual result_t get_fd(int32_t& retVal) = 0;
virtual result_t chmod(int32_t mode, AsyncEvent* ac) = 0;

public:
Expand All @@ -40,6 +41,7 @@ class File_base : public SeekableStream_base {

public:
static void s_get_name(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_get_fd(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_chmod(const v8::FunctionCallbackInfo<v8::Value>& args);

public:
Expand All @@ -55,7 +57,8 @@ inline ClassInfo& File_base::class_info()
};

static ClassData::ClassProperty s_property[] = {
{ "name", s_get_name, block_set, false }
{ "name", s_get_name, block_set, false },
{ "fd", s_get_fd, block_set, false }
};

static ClassData s_cd = {
Expand All @@ -80,6 +83,18 @@ inline void File_base::s_get_name(v8::Local<v8::String> property, const v8::Prop
METHOD_RETURN();
}

inline void File_base::s_get_fd(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args)
{
int32_t vr;

METHOD_INSTANCE(File_base);
PROPERTY_ENTER();

hr = pInst->get_fd(vr);

METHOD_RETURN();
}

inline void File_base::s_chmod(const v8::FunctionCallbackInfo<v8::Value>& args)
{
METHOD_INSTANCE(File_base);
Expand Down
3 changes: 3 additions & 0 deletions fibjs/include/ifs/File.idl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ interface File : SeekableStream
/*! @brief 查询当前文件名 */
readonly String name;

/*! @brief 查询当前文件描述符 */
readonly Integer fd;

/*! @brief 查询当前文件的访问权限,Windows 不支持此方法
@param mode 指定设定的访问权限
*/
Expand Down
9 changes: 9 additions & 0 deletions fibjs/src/fs/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@ result_t File::get_name(exlib::string& retVal)
return 0;
}

result_t File::get_fd(int32_t& retVal)
{
if (m_fd == -1)
return CHECK_ERROR(CALL_E_INVALID_CALL);

retVal = m_fd;
return 0;
}

#ifdef _WIN32

result_t File::stat(obj_ptr<Stat_base>& retVal, AsyncEvent* ac)
Expand Down

0 comments on commit 9ed5946

Please sign in to comment.