improve iostream

This commit is contained in:
lixianjing 2019-12-29 15:27:38 +08:00
parent e0f4b42c2d
commit 56e39cc852
3 changed files with 89 additions and 0 deletions

View File

@ -1,6 +1,8 @@
# 最新动态
* 2019/12/29
* 使用event\_source\_manager实现主循环。
* iostream增加几个包装函数。
* 2019/12/27
* 增加str\_from\_wstr\_with\_len

View File

@ -32,3 +32,30 @@ tk_ostream_t* tk_iostream_get_ostream(tk_iostream_t* stream) {
return stream->get_ostream(stream);
}
int32_t tk_iostream_read(tk_iostream_t* stream, uint8_t* buff, uint32_t max_size) {
tk_istream_t* is = tk_iostream_get_istream(stream);
return tk_istream_read(is, buff, max_size);
}
int32_t tk_iostream_read_len(tk_iostream_t* stream, uint8_t* buff, uint32_t max_size,
uint32_t timeout_ms) {
tk_istream_t* is = tk_iostream_get_istream(stream);
return tk_istream_read_len(is, buff, max_size, timeout_ms);
}
int32_t tk_iostream_write(tk_iostream_t* stream, const uint8_t* buff, uint32_t max_size) {
tk_ostream_t* os = tk_iostream_get_ostream(stream);
return tk_ostream_write(os, buff, max_size);
}
int32_t tk_iostream_write_len(tk_iostream_t* stream, const uint8_t* buff, uint32_t max_size,
uint32_t timeout_ms) {
tk_ostream_t* os = tk_iostream_get_ostream(stream);
return tk_ostream_write_len(os, buff, max_size, timeout_ms);
}

View File

@ -72,6 +72,66 @@ tk_istream_t* tk_iostream_get_istream(tk_iostream_t* stream);
*/
tk_ostream_t* tk_iostream_get_ostream(tk_iostream_t* stream);
/**
* @method tk_iostream_read
*
*
*
* @param {tk_iostream_t*} stream iostream对象
* @param {uint8_t*} buff
* @param {uint32_t} max_size
*
* @return {int32_t}
*
*/
int32_t tk_iostream_read(tk_iostream_t* stream, uint8_t* buff, uint32_t max_size);
/**
* @method tk_iostream_read_len
*
*
*
* @param {tk_iostream_t*} stream iostream对象
* @param {uint8_t*} buff
* @param {uint32_t} max_size
* @param {uint32_t} timeout_ms timeout.
*
* @return {int32_t}
*
*/
int32_t tk_iostream_read_len(tk_iostream_t* stream, uint8_t* buff, uint32_t max_size,
uint32_t timeout_ms);
/**
* @method tk_iostream_write
*
*
*
* @param {tk_iostream_t*} stream iostream对象
* @param {const uint8_t*} buff
* @param {uint32_t} max_size
*
* @return {int32_t}
*
*/
int32_t tk_iostream_write(tk_iostream_t* stream, const uint8_t* buff, uint32_t max_size);
/**
* @method tk_iostream_write_len
*
*
*
* @param {tk_iostream_t*} stream iostream对象
* @param {const uint8_t*} buff
* @param {uint32_t} max_size
* @param {uint32_t} timeout_ms timeout.
*
* @return {int32_t}
*
*/
int32_t tk_iostream_write_len(tk_iostream_t* stream, const uint8_t* buff, uint32_t max_size,
uint32_t timeout_ms);
#define TK_IOSTREAM(obj) ((tk_iostream_t*)(obj))
END_C_DECLS