Skip to content

Commit b61c33d

Browse files
committed
DataStrategyImpl: make some functions protected
1 parent 7e1e611 commit b61c33d

File tree

2 files changed

+49
-51
lines changed

2 files changed

+49
-51
lines changed

libraries/ESP8266WiFi/src/include/DataStrategy.h

-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,4 @@ class DataStrategy
1919
virtual void on_poll(ClientContext& ctx) = 0;
2020
};
2121

22-
/// in DataStrategyImpl.h
23-
24-
2522
#endif//DATASTRATEGY_H

libraries/ESP8266WiFi/src/include/DataStrategyImpl.h

+49-48
Original file line numberDiff line numberDiff line change
@@ -22,53 +22,54 @@ class BufferStrategy : public DataStrategy
2222

2323
size_t write(ClientContext& ctx) override
2424
{
25-
write_some(ctx);
25+
_write_some(ctx);
2626
while (!_done) {
2727
esp_yield();
2828
}
2929
return _written;
3030
}
3131

32-
void write_some(ClientContext& ctx)
33-
{
34-
size_t can_write = ctx.getSendBufferSize();
35-
size_t will_write = (can_write < _size) ? can_write : _size;
36-
if (!ctx.write(_buf, will_write)) {
37-
end();
38-
return;
39-
}
40-
_buf += will_write;
41-
_size -= will_write;
42-
_queued += will_write;
43-
}
44-
4532
void on_sent(ClientContext& ctx, size_t size) override
4633
{
4734
if (_size > 0) {
48-
write_some(ctx);
35+
_write_some(ctx);
4936
}
5037
_queued -= size;
5138
_written += size;
5239
if (_queued == 0) {
53-
end();
40+
_end();
5441
}
5542
}
5643

5744
void on_error(ClientContext& ctx) override
5845
{
5946
if (_queued > 0) {
60-
end();
47+
_end();
6148
}
6249
}
6350

6451
void on_poll(ClientContext& ctx) override
6552
{
6653
if (millis() > _timeout && _queued > 0) {
67-
end();
54+
_end();
55+
}
56+
}
57+
58+
protected:
59+
void _write_some(ClientContext& ctx)
60+
{
61+
size_t can_write = ctx.getSendBufferSize();
62+
size_t will_write = (can_write < _size) ? can_write : _size;
63+
if (!ctx.write(_buf, will_write)) {
64+
_end();
65+
return;
6866
}
67+
_buf += will_write;
68+
_size -= will_write;
69+
_queued += will_write;
6970
}
7071

71-
void end()
72+
void _end()
7273
{
7374
if (!_done) {
7475
_done = true;
@@ -168,40 +169,17 @@ class ChunkedStrategy : public DataStrategy
168169

169170
size_t write(ClientContext& ctx) override
170171
{
171-
write_some(ctx);
172+
_write_some(ctx);
172173
while (!_done) {
173174
esp_yield();
174175
}
175176
return _written;
176177
}
177178

178-
void write_some(ClientContext& ctx)
179-
{
180-
size_t can_write = ctx.getSendBufferSize();
181-
size_t will_write = (can_write < _size) ? can_write : _size;
182-
183-
BufferLink* new_buf = new BufferLink(will_write, _buffers_tail);
184-
if (!_buffers_head) {
185-
_buffers_head = new_buf;
186-
}
187-
_buffers_tail = new_buf;
188-
size_t cb = _source.readBytes((char*) new_buf->data(), will_write);
189-
if (cb < will_write) {
190-
end();
191-
return;
192-
}
193-
if (!ctx.write(new_buf->data(), will_write)) {
194-
end();
195-
return;
196-
}
197-
_size -= will_write;
198-
_last_write_time = millis();
199-
}
200-
201179
void on_sent(ClientContext& ctx, size_t size) override
202180
{
203181
if (_size > 0) {
204-
write_some(ctx);
182+
_write_some(ctx);
205183
}
206184
auto size_to_remove = size;
207185
while (size_to_remove) {
@@ -219,14 +197,14 @@ class ChunkedStrategy : public DataStrategy
219197
}
220198
_written += size;
221199
if (_buffers_head == nullptr) {
222-
end();
200+
_end();
223201
}
224202
}
225203

226204
void on_error(ClientContext& ctx) override
227205
{
228206
if (_buffers_head != nullptr) {
229-
end();
207+
_end();
230208
}
231209
}
232210

@@ -235,11 +213,34 @@ class ChunkedStrategy : public DataStrategy
235213
if (_last_write_time != 0 &&
236214
millis() - _last_write_time > _timeout &&
237215
_buffers_head != nullptr) {
238-
end();
216+
_end();
239217
}
240218
}
241219

242-
void end()
220+
protected:
221+
void _write_some(ClientContext& ctx)
222+
{
223+
size_t can_write = ctx.getSendBufferSize();
224+
size_t will_write = (can_write < _size) ? can_write : _size;
225+
BufferLink* new_buf = new BufferLink(will_write, _buffers_tail);
226+
if (!_buffers_head) {
227+
_buffers_head = new_buf;
228+
}
229+
_buffers_tail = new_buf;
230+
size_t cb = _source.readBytes((char*) new_buf->data(), will_write);
231+
if (cb < will_write) {
232+
_end();
233+
return;
234+
}
235+
if (!ctx.write(new_buf->data(), will_write)) {
236+
_end();
237+
return;
238+
}
239+
_size -= will_write;
240+
_last_write_time = millis();
241+
}
242+
243+
void _end()
243244
{
244245
if (!_done) {
245246
_done = true;

0 commit comments

Comments
 (0)