mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-10 07:56:09 +00:00
Simplify encoder's loop
This commit is contained in:
parent
80e8baaff4
commit
641943944d
@ -69,11 +69,11 @@ namespace zmq
|
|||||||
unsigned char *buffer = !*data_ ? buf : *data_;
|
unsigned char *buffer = !*data_ ? buf : *data_;
|
||||||
size_t buffersize = !*data_ ? bufsize : *size_;
|
size_t buffersize = !*data_ ? bufsize : *size_;
|
||||||
|
|
||||||
size_t pos = 0;
|
|
||||||
if (offset_)
|
if (offset_)
|
||||||
*offset_ = -1;
|
*offset_ = -1;
|
||||||
|
|
||||||
while (true) {
|
size_t pos = 0;
|
||||||
|
while (pos < buffersize) {
|
||||||
|
|
||||||
// If there are no more data to return, run the state machine.
|
// If there are no more data to return, run the state machine.
|
||||||
// If there are still no data, return what we already have
|
// If there are still no data, return what we already have
|
||||||
@ -85,11 +85,8 @@ namespace zmq
|
|||||||
if (offset_ && *offset_ == -1)
|
if (offset_ && *offset_ == -1)
|
||||||
*offset_ = static_cast <int> (pos);
|
*offset_ = static_cast <int> (pos);
|
||||||
|
|
||||||
if (!(static_cast <T*> (this)->*next) ()) {
|
if (!(static_cast <T*> (this)->*next) ())
|
||||||
*data_ = buffer;
|
break;
|
||||||
*size_ = pos;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there are no data in the buffer yet and we are able to
|
// If there are no data in the buffer yet and we are able to
|
||||||
@ -116,12 +113,10 @@ namespace zmq
|
|||||||
pos += to_copy;
|
pos += to_copy;
|
||||||
write_pos += to_copy;
|
write_pos += to_copy;
|
||||||
to_write -= to_copy;
|
to_write -= to_copy;
|
||||||
if (pos == buffersize) {
|
}
|
||||||
|
|
||||||
*data_ = buffer;
|
*data_ = buffer;
|
||||||
*size_ = pos;
|
*size_ = pos;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user