mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-30 02:58:26 +08:00
improve istream/ostream
This commit is contained in:
parent
1e88ba179e
commit
a78307488d
@ -55,7 +55,7 @@ ret_t tk_istream_flush(tk_istream_t* stream) {
|
||||
|
||||
int32_t tk_istream_read_len(tk_istream_t* stream, uint8_t* buff, uint32_t max_size,
|
||||
uint32_t timeout_ms) {
|
||||
uint32_t start = 0;
|
||||
uint32_t now = 0;
|
||||
uint32_t end = 0;
|
||||
int32_t offset = 0;
|
||||
int32_t read_bytes = 0;
|
||||
@ -63,8 +63,8 @@ int32_t tk_istream_read_len(tk_istream_t* stream, uint8_t* buff, uint32_t max_si
|
||||
return_value_if_fail(stream != NULL && stream->read != NULL, -1);
|
||||
return_value_if_fail(buff != NULL, 0);
|
||||
|
||||
start = time_now_ms();
|
||||
end = start + timeout_ms;
|
||||
now = time_now_ms();
|
||||
end = now + timeout_ms;
|
||||
|
||||
do {
|
||||
read_bytes = tk_istream_read(stream, buff + offset, remain_bytes);
|
||||
@ -75,7 +75,13 @@ int32_t tk_istream_read_len(tk_istream_t* stream, uint8_t* buff, uint32_t max_si
|
||||
|
||||
offset += read_bytes;
|
||||
remain_bytes -= read_bytes;
|
||||
if (time_now_ms() > end) {
|
||||
|
||||
if(remain_bytes == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
now = time_now_ms();
|
||||
if (now > end) {
|
||||
log_debug("read timeout\n");
|
||||
break;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ ret_t tk_ostream_seek(tk_ostream_t* stream, uint32_t offset) {
|
||||
|
||||
int32_t tk_ostream_write_len(tk_ostream_t* stream, const uint8_t* buff, uint32_t max_size,
|
||||
uint32_t timeout_ms) {
|
||||
uint32_t start = 0;
|
||||
uint32_t now = 0;
|
||||
uint32_t end = 0;
|
||||
int32_t offset = 0;
|
||||
int32_t write_bytes = 0;
|
||||
@ -46,8 +46,8 @@ int32_t tk_ostream_write_len(tk_ostream_t* stream, const uint8_t* buff, uint32_t
|
||||
return_value_if_fail(stream != NULL && stream->write != NULL, -1);
|
||||
return_value_if_fail(buff != NULL, 0);
|
||||
|
||||
start = time_now_ms();
|
||||
end = start + timeout_ms;
|
||||
now = time_now_ms();
|
||||
end = now + timeout_ms;
|
||||
do {
|
||||
write_bytes = tk_ostream_write(stream, buff + offset, remain_bytes);
|
||||
|
||||
@ -57,8 +57,13 @@ int32_t tk_ostream_write_len(tk_ostream_t* stream, const uint8_t* buff, uint32_t
|
||||
|
||||
offset += write_bytes;
|
||||
remain_bytes -= write_bytes;
|
||||
|
||||
if(remain_bytes == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (time_now_ms() > end) {
|
||||
now = time_now_ms();
|
||||
if (now > end) {
|
||||
log_debug("write timeout\n");
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user