Permalink
Browse files

process, refactor: use AsyncIO.close to close process pipe.

  • Loading branch information...
xicilion committed Nov 10, 2017
1 parent 8bff4df commit 910b473727bde41b9622c6a56526f1603c999928
Showing with 14 additions and 64 deletions.
  1. +7 −8 fibjs/include/AsyncIO.h
  2. +7 −23 fibjs/include/SubProcess.h
  3. +0 −33 fibjs/src/io/AsyncIO_ev.cpp
View
@@ -52,18 +52,17 @@ class AsyncIO {
result_t recvfrom(int32_t bytes, obj_ptr<NObject>& retVal, AsyncEvent* ac);
#ifndef _WIN32
result_t cancel(AsyncEvent* ac);
result_t close(intptr_t& s, AsyncEvent* ac);
#else
result_t cancel(AsyncEvent* ac)
{
return 0;
}
result_t close(intptr_t& s, AsyncEvent* ac)
{
if (s != INVALID_SOCKET)
::closesocket(s);
if (s != INVALID_SOCKET) {
if (m_type == -1)
::CloseHandle((HANDLE)s);
else
::closesocket(s);
}
s = INVALID_SOCKET;
return 0;
View
@@ -72,14 +72,18 @@ class SubProcess : public SubProcess_base {
public:
Pipe(intptr_t fd)
: m_aio(fd, 0, 0)
: m_aio(fd, 0, -1)
{
}
~Pipe()
{
if (m_aio.m_fd != INVALID_SOCKET)
asyncCall(close_pipe, m_aio.m_fd);
#ifdef _WIN32
asyncCall(::CloseHandle, (HANDLE)m_aio.m_fd);
#else
asyncCall(::close, m_aio.m_fd);
#endif
}
public:
@@ -108,16 +112,7 @@ class SubProcess : public SubProcess_base {
if (ac->isSync())
return CHECK_ERROR(CALL_E_NOSYNC);
if (m_aio.m_fd != INVALID_SOCKET)
close_pipe(m_aio.m_fd);
m_aio.m_fd = INVALID_SOCKET;
#ifndef _WIN32
return m_aio.cancel(ac);
#else
return 0;
#endif
return m_aio.close(m_aio.m_fd, ac);
}
virtual result_t copyTo(Stream_base* stm, int64_t bytes,
@@ -129,17 +124,6 @@ class SubProcess : public SubProcess_base {
return io_base::copyStream(this, stm, bytes, retVal, ac);
}
private:
static result_t close_pipe(intptr_t fd)
{
#ifdef _WIN32
::CloseHandle((HANDLE)fd);
#else
::close(fd);
#endif
return 0;
}
private:
AsyncIO m_aio;
};
@@ -236,39 +236,6 @@ void init_aio()
s_acIO.start();
}
result_t AsyncIO::cancel(AsyncEvent* ac)
{
class asyncCancel : public asyncEv {
public:
asyncCancel(void*& opt1, void*& opt2, AsyncEvent* ac)
: m_ac(ac)
, m_opt1(opt1)
, m_opt2(opt2)
{
}
virtual void start()
{
if (m_opt1)
((asyncProc*)m_opt1)->onready();
if (m_opt2)
((asyncProc*)m_opt2)->onready();
m_ac->apost(0);
delete this;
}
public:
AsyncEvent* m_ac;
void*& m_opt1;
void*& m_opt2;
};
(new asyncCancel(m_RecvOpt, m_SendOpt, ac))->post();
return CALL_E_PENDDING;
}
result_t AsyncIO::close(intptr_t& s, AsyncEvent* ac)
{
class asyncClose : public asyncEv {

0 comments on commit 910b473

Please sign in to comment.