暂时改成读取不传入len
This commit is contained in:
parent
be1766e590
commit
0f4041d8d9
@ -62,7 +62,7 @@ public:
|
||||
return send_size;
|
||||
}
|
||||
|
||||
int read(char* data, int size)
|
||||
int read(char* data)
|
||||
{
|
||||
bytes_transferred_ = 0;
|
||||
io_.reset();
|
||||
@ -77,16 +77,11 @@ public:
|
||||
boost::asio::placeholders::bytes_transferred));
|
||||
|
||||
io_.run();
|
||||
|
||||
if (size < bytes_transferred_) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (bytes_transferred_ > 0) {
|
||||
std::memcpy(data, buffer_, bytes_transferred_);
|
||||
return static_cast<int>(bytes_transferred_);
|
||||
data[bytes_transferred_] = '\0';
|
||||
}
|
||||
return 0;
|
||||
return bytes_transferred_;
|
||||
}
|
||||
const char* get_last_error() const { return error_; }
|
||||
void set_timeout(uint64_t timeout) { time_out_ = timeout; }
|
||||
@ -103,12 +98,13 @@ private:
|
||||
if (code) {
|
||||
return;
|
||||
}
|
||||
bytes_transferred_ = -1;
|
||||
port_->cancel();
|
||||
}
|
||||
void handle_read(const boost::system::error_code& error, std::size_t bytes_transferred)
|
||||
{
|
||||
if (!error) {
|
||||
bytes_transferred_ = bytes_transferred;
|
||||
bytes_transferred_ = static_cast<int>(bytes_transferred);
|
||||
timer_.cancel();
|
||||
}
|
||||
}
|
||||
@ -123,7 +119,7 @@ private:
|
||||
serial_port::flow_control flow_control_;
|
||||
|
||||
private:
|
||||
std::size_t bytes_transferred_{};
|
||||
int bytes_transferred_{};
|
||||
boost::asio::io_context io_{};
|
||||
boost::asio::serial_port* port_{};
|
||||
boost::system::error_code ec_{};
|
||||
@ -238,9 +234,9 @@ void CSerialOpr::close()
|
||||
{
|
||||
imp_->close();
|
||||
}
|
||||
int CSerialOpr::read(char* data, int size)
|
||||
int CSerialOpr::read(char* data)
|
||||
{
|
||||
return imp_->read(data, size);
|
||||
return imp_->read(data);
|
||||
}
|
||||
int CSerialOpr::write(const char* data, int len)
|
||||
{
|
||||
|
@ -54,7 +54,7 @@ public:
|
||||
public:
|
||||
int open();
|
||||
void close();
|
||||
int read(char* data, int size);
|
||||
int read(char* data);
|
||||
int write(const char* data, int len);
|
||||
const char* get_last_error() const;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user