for #742, refine the file reader and writer interface.

pull/756/head
winlin 8 years ago
parent bb5bd0ee1c
commit eaa222f034

2
trunk/configure vendored

@ -156,7 +156,7 @@ ModuleLibIncs=(${SRS_OBJS_DIR})
MODULE_FILES=("srs_kernel_error" "srs_kernel_log" "srs_kernel_buffer"
"srs_kernel_utility" "srs_kernel_flv" "srs_kernel_codec" "srs_kernel_file"
"srs_kernel_consts" "srs_kernel_aac" "srs_kernel_mp3" "srs_kernel_ts"
"srs_kernel_stream" "srs_kernel_balance" "srs_kernel_mp4")
"srs_kernel_stream" "srs_kernel_balance" "srs_kernel_mp4" "srs_kernel_io")
KERNEL_INCS="src/kernel"; MODULE_DIR=${KERNEL_INCS} . auto/modules.sh
KERNEL_OBJS="${MODULE_OBJS[@]}"
#

@ -115,6 +115,7 @@
3C7175B91E1DEA8000E8C49F /* sync.c in Sources */ = {isa = PBXBuildFile; fileRef = 3C7175B11E1DEA8000E8C49F /* sync.c */; };
3C82802C1BAFF8CC004A1794 /* srs_kafka_stack.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C82802A1BAFF8CC004A1794 /* srs_kafka_stack.cpp */; };
3C8CE01E1C3F482100548CC6 /* srs_app_hourglass.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C8CE01D1C3F482100548CC6 /* srs_app_hourglass.cpp */; };
3CA432A81E3F46DD001DA0C6 /* srs_kernel_io.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3CA432A61E3F46DD001DA0C6 /* srs_kernel_io.cpp */; };
3CB25C2A1BB269FD00C97A63 /* jmp_sp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3CB25C291BB269FD00C97A63 /* jmp_sp.cpp */; };
3CC52DD81ACE4023006FEB01 /* srs_utest_amf0.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3CC52DCA1ACE4023006FEB01 /* srs_utest_amf0.cpp */; };
3CC52DD91ACE4023006FEB01 /* srs_utest_config.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3CC52DCC1ACE4023006FEB01 /* srs_utest_config.cpp */; };
@ -403,6 +404,8 @@
3C82802B1BAFF8CC004A1794 /* srs_kafka_stack.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_kafka_stack.hpp; path = ../../../src/protocol/srs_kafka_stack.hpp; sourceTree = "<group>"; };
3C8CE01C1C3F482100548CC6 /* srs_app_hourglass.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_app_hourglass.hpp; path = ../../../src/app/srs_app_hourglass.hpp; sourceTree = "<group>"; };
3C8CE01D1C3F482100548CC6 /* srs_app_hourglass.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_app_hourglass.cpp; path = ../../../src/app/srs_app_hourglass.cpp; sourceTree = "<group>"; };
3CA432A61E3F46DD001DA0C6 /* srs_kernel_io.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_kernel_io.cpp; path = ../../../src/kernel/srs_kernel_io.cpp; sourceTree = "<group>"; };
3CA432A71E3F46DD001DA0C6 /* srs_kernel_io.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_kernel_io.hpp; path = ../../../src/kernel/srs_kernel_io.hpp; sourceTree = "<group>"; };
3CB25C281BB2596300C97A63 /* setup_variables.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = setup_variables.sh; path = ../../../auto/setup_variables.sh; sourceTree = "<group>"; };
3CB25C291BB269FD00C97A63 /* jmp_sp.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = jmp_sp.cpp; path = ../../../research/arm/jmp_sp.cpp; sourceTree = "<group>"; };
3CC52DCA1ACE4023006FEB01 /* srs_utest_amf0.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_utest_amf0.cpp; path = ../../src/utest/srs_utest_amf0.cpp; sourceTree = "<group>"; };
@ -534,6 +537,8 @@
3C1232131AAE814D00CE8F6C /* srs_kernel_file.hpp */,
3C1232141AAE814D00CE8F6C /* srs_kernel_flv.cpp */,
3C1232151AAE814D00CE8F6C /* srs_kernel_flv.hpp */,
3CA432A61E3F46DD001DA0C6 /* srs_kernel_io.cpp */,
3CA432A71E3F46DD001DA0C6 /* srs_kernel_io.hpp */,
3C1232161AAE814D00CE8F6C /* srs_kernel_log.cpp */,
3C1232171AAE814D00CE8F6C /* srs_kernel_log.hpp */,
3C1232181AAE814D00CE8F6C /* srs_kernel_mp3.cpp */,
@ -1074,6 +1079,7 @@
3C12329D1AAE81D900CE8F6C /* srs_app_heartbeat.cpp in Sources */,
3C1232231AAE814D00CE8F6C /* srs_kernel_consts.cpp in Sources */,
3C1232AF1AAE81D900CE8F6C /* srs_app_rtsp.cpp in Sources */,
3CA432A81E3F46DD001DA0C6 /* srs_kernel_io.cpp in Sources */,
3CC52DDD1ACE4023006FEB01 /* srs_utest_reload.cpp in Sources */,
3C689FA11AB6AAC800C9CEEE /* sync.c in Sources */,
3C068D6A1B10149F00AA722C /* srs_protocol_kbps.cpp in Sources */,

@ -155,7 +155,7 @@ int SrsHttpResponseWriter::write(char* data, int size)
return ret;
}
int SrsHttpResponseWriter::writev(iovec* iov, int iovcnt, ssize_t* pnwrite)
int SrsHttpResponseWriter::writev(const iovec* iov, int iovcnt, ssize_t* pnwrite)
{
int ret = ERROR_SUCCESS;
@ -163,7 +163,7 @@ int SrsHttpResponseWriter::writev(iovec* iov, int iovcnt, ssize_t* pnwrite)
if (!header_wrote || content_length != -1) {
ssize_t nwrite = 0;
for (int i = 0; i < iovcnt; i++) {
iovec* piovc = iov + i;
const iovec* piovc = iov + i;
nwrite += piovc->iov_len;
if ((ret = write((char*)piovc->iov_base, (int)piovc->iov_len)) != ERROR_SUCCESS) {
return ret;
@ -196,7 +196,7 @@ int SrsHttpResponseWriter::writev(iovec* iov, int iovcnt, ssize_t* pnwrite)
// chunk size.
int size = 0;
for (int i = 0; i < iovcnt; i++) {
iovec* data_iov = iov + i;
const iovec* data_iov = iov + i;
size += data_iov->iov_len;
}
written += size;
@ -215,7 +215,7 @@ int SrsHttpResponseWriter::writev(iovec* iov, int iovcnt, ssize_t* pnwrite)
// chunk body.
for (int i = 0; i < iovcnt; i++) {
iovec* data_iov = iov + i;
const iovec* data_iov = iov + i;
iovs[0].iov_base = (char*)data_iov->iov_base;
iovs[0].iov_len = (int)data_iov->iov_len;
iovs++;

@ -103,7 +103,7 @@ public:
virtual int final_request();
virtual SrsHttpHeader* header();
virtual int write(char* data, int size);
virtual int writev(iovec* iov, int iovcnt, ssize_t* pnwrite);
virtual int writev(const iovec* iov, int iovcnt, ssize_t* pnwrite);
virtual void write_header(int code);
virtual int send_header(char* data, int size);
};

@ -440,7 +440,7 @@ int SrsBufferWriter::write(void* buf, size_t count, ssize_t* pnwrite)
return writer->write((char*)buf, (int)count);
}
int SrsBufferWriter::writev(iovec* iov, int iovcnt, ssize_t* pnwrite)
int SrsBufferWriter::writev(const iovec* iov, int iovcnt, ssize_t* pnwrite)
{
return writer->writev(iov, iovcnt, pnwrite);
}

@ -210,7 +210,7 @@ public:
virtual int64_t tellg();
public:
virtual int write(void* buf, size_t count, ssize_t* pnwrite);
virtual int writev(iovec* iov, int iovcnt, ssize_t* pnwrite);
virtual int writev(const iovec* iov, int iovcnt, ssize_t* pnwrite);
};
/**

@ -146,13 +146,13 @@ int SrsFileWriter::write(void* buf, size_t count, ssize_t* pnwrite)
return ret;
}
int SrsFileWriter::writev(iovec* iov, int iovcnt, ssize_t* pnwrite)
int SrsFileWriter::writev(const iovec* iov, int iovcnt, ssize_t* pnwrite)
{
int ret = ERROR_SUCCESS;
ssize_t nwrite = 0;
for (int i = 0; i < iovcnt; i++) {
iovec* piov = iov + i;
const iovec* piov = iov + i;
ssize_t this_nwrite = 0;
if ((ret = write(piov->iov_base, piov->iov_len, &this_nwrite)) != ERROR_SUCCESS) {
return ret;

@ -29,6 +29,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <srs_core.hpp>
#include <srs_kernel_io.hpp>
#include <string>
// for srs-librtmp, @see https://github.com/ossrs/srs/issues/213
@ -39,7 +41,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
* file writer, to write to file.
*/
class SrsFileWriter
class SrsFileWriter : public ISrsBufferWriter
{
private:
std::string path;
@ -77,13 +79,13 @@ public:
* for the HTTP FLV, to writev to improve performance.
* @see https://github.com/ossrs/srs/issues/405
*/
virtual int writev(iovec* iov, int iovcnt, ssize_t* pnwrite);
virtual int writev(const iovec* iov, int iovcnt, ssize_t* pnwrite);
};
/**
* file reader, to read from file.
*/
class SrsFileReader
class SrsFileReader : public ISrsBufferReader
{
private:
std::string path;

@ -0,0 +1,41 @@
/*
The MIT License (MIT)
Copyright (c) 2013-2017 SRS(ossrs)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <srs_kernel_io.hpp>
ISrsBufferReader::ISrsBufferReader()
{
}
ISrsBufferReader::~ISrsBufferReader()
{
}
ISrsBufferWriter::ISrsBufferWriter()
{
}
ISrsBufferWriter::~ISrsBufferWriter()
{
}

@ -0,0 +1,74 @@
/*
The MIT License (MIT)
Copyright (c) 2013-2017 SRS(ossrs)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef SRS_KERNEL_IO_HPP
#define SRS_KERNEL_IO_HPP
/*
#include <srs_kernel_io.hpp>
*/
#include <srs_core.hpp>
// for srs-librtmp, @see https://github.com/ossrs/srs/issues/213
#ifndef _WIN32
#include <sys/uio.h>
#endif
/**
* the reader for the buffer to read from whatever channel.
*/
class ISrsBufferReader
{
public:
ISrsBufferReader();
virtual ~ISrsBufferReader();
// for protocol/amf0/msg-codec
public:
virtual int read(void* buf, size_t size, ssize_t* nread) = 0;
};
/**
* the writer for the buffer to write to whatever channel.
*/
class ISrsBufferWriter
{
public:
ISrsBufferWriter();
virtual ~ISrsBufferWriter();
// for protocol
public:
/**
* write bytes over writer.
* @nwrite the actual written bytes. NULL to ignore.
*/
virtual int write(void* buf, size_t size, ssize_t* nwrite) = 0;
/**
* write iov over writer.
* @nwrite the actual written bytes. NULL to ignore.
*/
virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite) = 0;
};
#endif

@ -201,7 +201,7 @@ public:
* for the HTTP FLV, to writev to improve performance.
* @see https://github.com/ossrs/srs/issues/405
*/
virtual int writev(iovec* iov, int iovcnt, ssize_t* pnwrite) = 0;
virtual int writev(const iovec* iov, int iovcnt, ssize_t* pnwrite) = 0;
// WriteHeader sends an HTTP response header with status code.
// If WriteHeader is not called explicitly, the first call to Write

@ -23,22 +23,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_protocol_io.hpp>
ISrsBufferReader::ISrsBufferReader()
{
}
ISrsBufferReader::~ISrsBufferReader()
{
}
ISrsBufferWriter::ISrsBufferWriter()
{
}
ISrsBufferWriter::~ISrsBufferWriter()
{
}
ISrsProtocolStatistic::ISrsProtocolStatistic()
{
}

@ -30,10 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core.hpp>
// for srs-librtmp, @see https://github.com/ossrs/srs/issues/213
#ifndef _WIN32
#include <sys/uio.h>
#endif
#include <srs_kernel_io.hpp>
/**
* the system io reader/writer architecture:
@ -60,41 +57,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+----------------------------------+
*/
/**
* the reader for the buffer to read from whatever channel.
*/
class ISrsBufferReader
{
public:
ISrsBufferReader();
virtual ~ISrsBufferReader();
// for protocol/amf0/msg-codec
public:
virtual int read(void* buf, size_t size, ssize_t* nread) = 0;
};
/**
* the writer for the buffer to write to whatever channel.
*/
class ISrsBufferWriter
{
public:
ISrsBufferWriter();
virtual ~ISrsBufferWriter();
// for protocol
public:
/**
* write bytes over writer.
* @nwrite the actual written bytes. NULL to ignore.
*/
virtual int write(void* buf, size_t size, ssize_t* nwrite) = 0;
/**
* write iov over writer.
* @nwrite the actual written bytes. NULL to ignore.
*/
virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite) = 0;
};
/**
* get the statistic of channel.
*/

Loading…
Cancel
Save