Permalink
Browse files

io, refactor: move method flush to Interface Stream.

  • Loading branch information...
xicilion committed Oct 25, 2017
1 parent 666ae9f commit feac71466c8d98c62697d0a3fda0c766ba8a1fa9
@@ -33,6 +33,7 @@ class BufferedStream : public BufferedStream_base {
// Stream_base
virtual result_t read(int32_t bytes, obj_ptr<Buffer_base>& retVal, AsyncEvent* ac);
virtual result_t write(Buffer_base* data, AsyncEvent* ac);
virtual result_t flush(AsyncEvent* ac);
virtual result_t close(AsyncEvent* ac);
virtual result_t copyTo(Stream_base* stm, int64_t bytes, int64_t& retVal, AsyncEvent* ac);
View
@@ -57,6 +57,7 @@ class File : public File_base {
// Stream_base
virtual result_t read(int32_t bytes, obj_ptr<Buffer_base>& retVal, AsyncEvent* ac);
virtual result_t write(Buffer_base* data, AsyncEvent* ac);
virtual result_t flush(AsyncEvent* ac);
virtual result_t close(AsyncEvent* ac);
virtual result_t copyTo(Stream_base* stm, int64_t bytes, int64_t& retVal, AsyncEvent* ac);
@@ -69,7 +70,6 @@ class File : public File_base {
virtual result_t readAll(obj_ptr<Buffer_base>& retVal, AsyncEvent* ac);
virtual result_t truncate(int64_t bytes, AsyncEvent* ac);
virtual result_t eof(bool& retVal);
virtual result_t flush(AsyncEvent* ac);
virtual result_t stat(obj_ptr<Stat_base>& retVal, AsyncEvent* ac);
public:
@@ -31,6 +31,7 @@ class MemoryStream : public MemoryStream_base {
// Stream_base
virtual result_t read(int32_t bytes, obj_ptr<Buffer_base>& retVal, AsyncEvent* ac);
virtual result_t write(Buffer_base* data, AsyncEvent* ac);
virtual result_t flush(AsyncEvent* ac);
virtual result_t close(AsyncEvent* ac);
virtual result_t copyTo(Stream_base* stm, int64_t bytes, int64_t& retVal, AsyncEvent* ac);
@@ -43,7 +44,6 @@ class MemoryStream : public MemoryStream_base {
virtual result_t readAll(obj_ptr<Buffer_base>& retVal, AsyncEvent* ac);
virtual result_t truncate(int64_t bytes, AsyncEvent* ac);
virtual result_t eof(bool& retVal);
virtual result_t flush(AsyncEvent* ac);
virtual result_t stat(obj_ptr<Stat_base>& retVal, AsyncEvent* ac);
public:
@@ -68,6 +68,7 @@ class MemoryStream : public MemoryStream_base {
// Stream_base
virtual result_t read(int32_t bytes, obj_ptr<Buffer_base>& retVal, AsyncEvent* ac);
virtual result_t write(Buffer_base* data, AsyncEvent* ac);
virtual result_t flush(AsyncEvent* ac);
virtual result_t close(AsyncEvent* ac);
virtual result_t copyTo(Stream_base* stm, int64_t bytes, int64_t& retVal, AsyncEvent* ac);
@@ -80,7 +81,6 @@ class MemoryStream : public MemoryStream_base {
virtual result_t readAll(obj_ptr<Buffer_base>& retVal, AsyncEvent* ac);
virtual result_t truncate(int64_t bytes, AsyncEvent* ac);
virtual result_t eof(bool& retVal);
virtual result_t flush(AsyncEvent* ac);
virtual result_t stat(obj_ptr<Stat_base>& retVal, AsyncEvent* ac);
public:
View
@@ -48,9 +48,9 @@ class Socket : public Socket_base {
virtual result_t read(int32_t bytes, obj_ptr<Buffer_base>& retVal,
AsyncEvent* ac);
virtual result_t write(Buffer_base* data, AsyncEvent* ac);
virtual result_t flush(AsyncEvent* ac);
virtual result_t close(AsyncEvent* ac);
virtual result_t copyTo(Stream_base* stm, int64_t bytes,
int64_t& retVal, AsyncEvent* ac);
virtual result_t copyTo(Stream_base* stm, int64_t bytes, int64_t& retVal, AsyncEvent* ac);
public:
// Socket_base
@@ -62,20 +62,15 @@ class Socket : public Socket_base {
virtual result_t get_localPort(int32_t& retVal);
virtual result_t get_timeout(int32_t& retVal);
virtual result_t set_timeout(int32_t newVal);
virtual result_t connect(exlib::string host, int32_t port,
AsyncEvent* ac);
virtual result_t connect(exlib::string host, int32_t port, AsyncEvent* ac);
virtual result_t bind(exlib::string addr, int32_t port, bool allowIPv4);
virtual result_t bind(int32_t port, bool allowIPv4);
virtual result_t listen(int32_t backlog);
virtual result_t accept(obj_ptr<Socket_base>& retVal,
AsyncEvent* ac);
virtual result_t recv(int32_t bytes, obj_ptr<Buffer_base>& retVal,
AsyncEvent* ac);
virtual result_t recvfrom(int32_t bytes, obj_ptr<NObject>& retVal,
AsyncEvent* ac);
virtual result_t accept(obj_ptr<Socket_base>& retVal, AsyncEvent* ac);
virtual result_t recv(int32_t bytes, obj_ptr<Buffer_base>& retVal, AsyncEvent* ac);
virtual result_t recvfrom(int32_t bytes, obj_ptr<NObject>& retVal, AsyncEvent* ac);
virtual result_t send(Buffer_base* data, AsyncEvent* ac);
virtual result_t sendto(Buffer_base* data, exlib::string host,
int32_t port, AsyncEvent* ac);
virtual result_t sendto(Buffer_base* data, exlib::string host, int32_t port, AsyncEvent* ac);
public:
result_t create(int32_t family, int32_t type);
@@ -154,9 +154,9 @@ class SslSocket : public SslSocket_base {
virtual result_t read(int32_t bytes, obj_ptr<Buffer_base>& retVal,
AsyncEvent* ac);
virtual result_t write(Buffer_base* data, AsyncEvent* ac);
virtual result_t flush(AsyncEvent* ac);
virtual result_t close(AsyncEvent* ac);
virtual result_t copyTo(Stream_base* stm, int64_t bytes,
int64_t& retVal, AsyncEvent* ac);
virtual result_t copyTo(Stream_base* stm, int64_t bytes, int64_t& retVal, AsyncEvent* ac);
public:
// SslSocket_base
@@ -186,8 +186,8 @@ class SslSocket : public SslSocket_base {
private:
obj_ptr<X509Cert> m_ca;
std::vector<obj_ptr<X509Cert_base> > m_crts;
std::vector<obj_ptr<PKey_base> > m_keys;
std::vector<obj_ptr<X509Cert_base>> m_crts;
std::vector<obj_ptr<PKey_base>> m_keys;
obj_ptr<Stream_base> m_s;
exlib::string m_recv;
int32_t m_recv_pos;
@@ -33,6 +33,7 @@ class SubProcess : public SubProcess_base {
// Stream_base
virtual result_t read(int32_t bytes, obj_ptr<Buffer_base>& retVal, AsyncEvent* ac);
virtual result_t write(Buffer_base* data, AsyncEvent* ac);
virtual result_t flush(AsyncEvent* ac);
virtual result_t close(AsyncEvent* ac);
virtual result_t copyTo(Stream_base* stm, int64_t bytes, int64_t& retVal, AsyncEvent* ac);
@@ -92,6 +93,11 @@ class SubProcess : public SubProcess_base {
return m_aio.write(data, ac);
}
virtual result_t flush(AsyncEvent* ac)
{
return 0;
}
virtual result_t close(AsyncEvent* ac)
{
if (m_aio.m_fd == INVALID_SOCKET)
@@ -33,7 +33,6 @@ class SeekableStream_base : public Stream_base {
virtual result_t readAll(obj_ptr<Buffer_base>& retVal, AsyncEvent* ac) = 0;
virtual result_t truncate(int64_t bytes, AsyncEvent* ac) = 0;
virtual result_t eof(bool& retVal) = 0;
virtual result_t flush(AsyncEvent* ac) = 0;
virtual result_t stat(obj_ptr<Stat_base>& retVal, AsyncEvent* ac) = 0;
public:
@@ -55,13 +54,11 @@ class SeekableStream_base : public Stream_base {
static void s_readAll(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_truncate(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_eof(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_flush(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_stat(const v8::FunctionCallbackInfo<v8::Value>& args);
public:
ASYNC_MEMBERVALUE1(SeekableStream_base, readAll, obj_ptr<Buffer_base>);
ASYNC_MEMBER1(SeekableStream_base, truncate, int64_t);
ASYNC_MEMBER0(SeekableStream_base, flush);
ASYNC_MEMBERVALUE1(SeekableStream_base, stat, obj_ptr<Stat_base>);
};
}
@@ -82,8 +79,6 @@ inline ClassInfo& SeekableStream_base::class_info()
{ "truncate", s_truncate, false },
{ "truncateSync", s_truncate, false },
{ "eof", s_eof, false },
{ "flush", s_flush, false },
{ "flushSync", s_flush, false },
{ "stat", s_stat, false },
{ "statSync", s_stat, false }
};
@@ -210,23 +205,6 @@ inline void SeekableStream_base::s_eof(const v8::FunctionCallbackInfo<v8::Value>
METHOD_RETURN();
}
inline void SeekableStream_base::s_flush(const v8::FunctionCallbackInfo<v8::Value>& args)
{
METHOD_NAME("SeekableStream.flush");
METHOD_INSTANCE(SeekableStream_base);
METHOD_ENTER();
ASYNC_METHOD_OVER(0, 0);
if (!cb.IsEmpty()) {
pInst->acb_flush(cb);
hr = CALL_RETURN_NULL;
} else
hr = pInst->ac_flush();
METHOD_VOID();
}
inline void SeekableStream_base::s_stat(const v8::FunctionCallbackInfo<v8::Value>& args)
{
obj_ptr<Stat_base> vr;
View
@@ -25,6 +25,7 @@ class Stream_base : public object_base {
// Stream_base
virtual result_t read(int32_t bytes, obj_ptr<Buffer_base>& retVal, AsyncEvent* ac) = 0;
virtual result_t write(Buffer_base* data, AsyncEvent* ac) = 0;
virtual result_t flush(AsyncEvent* ac) = 0;
virtual result_t close(AsyncEvent* ac) = 0;
virtual result_t copyTo(Stream_base* stm, int64_t bytes, int64_t& retVal, AsyncEvent* ac) = 0;
@@ -42,12 +43,14 @@ class Stream_base : public object_base {
public:
static void s_read(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_write(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_flush(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_close(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_copyTo(const v8::FunctionCallbackInfo<v8::Value>& args);
public:
ASYNC_MEMBERVALUE2(Stream_base, read, int32_t, obj_ptr<Buffer_base>);
ASYNC_MEMBER1(Stream_base, write, Buffer_base*);
ASYNC_MEMBER0(Stream_base, flush);
ASYNC_MEMBER0(Stream_base, close);
ASYNC_MEMBERVALUE3(Stream_base, copyTo, Stream_base*, int64_t, int64_t);
};
@@ -63,6 +66,8 @@ inline ClassInfo& Stream_base::class_info()
{ "readSync", s_read, false },
{ "write", s_write, false },
{ "writeSync", s_write, false },
{ "flush", s_flush, false },
{ "flushSync", s_flush, false },
{ "close", s_close, false },
{ "closeSync", s_close, false },
{ "copyTo", s_copyTo, false },
@@ -119,6 +124,23 @@ inline void Stream_base::s_write(const v8::FunctionCallbackInfo<v8::Value>& args
METHOD_VOID();
}
inline void Stream_base::s_flush(const v8::FunctionCallbackInfo<v8::Value>& args)
{
METHOD_NAME("Stream.flush");
METHOD_INSTANCE(Stream_base);
METHOD_ENTER();
ASYNC_METHOD_OVER(0, 0);
if (!cb.IsEmpty()) {
pInst->acb_flush(cb);
hr = CALL_RETURN_NULL;
} else
hr = pInst->ac_flush();
METHOD_VOID();
}
inline void Stream_base::s_close(const v8::FunctionCallbackInfo<v8::Value>& args)
{
METHOD_NAME("Stream.close");
@@ -153,6 +153,11 @@ result_t BufferedStream::write(Buffer_base* data, AsyncEvent* ac)
return m_stm->write(data, ac);
}
result_t BufferedStream::flush(AsyncEvent* ac)
{
return 0;
}
result_t BufferedStream::close(AsyncEvent* ac)
{
return m_stm->close(ac);
View
@@ -114,6 +114,11 @@ result_t Socket::write(Buffer_base* data, AsyncEvent* ac)
return m_aio.write(data, ac);
}
result_t Socket::flush(AsyncEvent* ac)
{
return 0;
}
result_t Socket::copyTo(Stream_base* stm, int64_t bytes,
int64_t& retVal, AsyncEvent* ac)
{
@@ -41,6 +41,11 @@ result_t SubProcess::write(Buffer_base* data, AsyncEvent* ac)
return m_stdin->write(data, ac);
}
result_t SubProcess::flush(AsyncEvent* ac)
{
return 0;
}
result_t SubProcess::close(AsyncEvent* ac)
{
if (m_timer)
@@ -254,6 +254,11 @@ result_t SslSocket::write(Buffer_base* data, AsyncEvent* ac)
return (new asyncWrite(this, data, ac))->post(0);
}
result_t SslSocket::flush(AsyncEvent* ac)
{
return 0;
}
result_t SslSocket::close(AsyncEvent* ac)
{
class asyncClose : public asyncSsl {
@@ -35,9 +35,6 @@ interface SeekableStream : Stream
@return 返回 True 表示结尾
*/
Boolean eof();
/*! @brief 将文件缓冲区内容写入物理设备 */
flush() async;
/*! @brief 查询当前文件的基础信息
@return 返回 Stat 对象描述文件信息
View
@@ -15,6 +15,9 @@ interface Stream : object
*/
write(Buffer data) async;
/*! @brief 将文件缓冲区内容写入物理设备 */
flush() async;
/*! @brief 关闭当前流对象 */
close() async;

0 comments on commit feac714

Please sign in to comment.