Arduino DLNA Server
Loading...
Searching...
No Matches
HttpStreamCopy.h
Go to the documentation of this file.
1#pragma once
2
3#include "HttpChunkWriter.h"
4
5namespace tiny_dlna {
6
15 public:
16 HttpStreamCopy(Stream &input, Client &client, int outputSize = 215) {
17 this->is_open = true;
18 this->input_ptr = &input;
19 this->client_ptr = &client;
20 this->output_size = outputSize;
21 }
22
24
25 bool isOpen() { return is_open; }
26
27 void doLoop() {
28 if (is_open) {
29 char buffer[output_size];
30 if (input_ptr->available() > 0 && client_ptr->connected()) {
31 int len = input_ptr->readBytes(buffer, output_size);
32 writer.writeChunk(*client_ptr, buffer, len);
33 } else {
34 close();
35 }
36 }
37 }
38
39 protected:
41 Stream *input_ptr;
42 Client *client_ptr;
44 bool is_open;
45
46 void close() {
47 if (is_open) {
48 is_open = false;
49 // input_ptr->close();
51 client_ptr = nullptr;
52 }
53 }
54};
55
56} // namespace tiny_dlna
Writes the data chunked to the actual client.
Definition: HttpChunkWriter.h:19
int writeChunk(Client &client, const char *str, int len, const char *str1=nullptr, int len1=0)
Definition: HttpChunkWriter.h:21
void writeEnd(Client &client)
Definition: HttpChunkWriter.h:38
Processing of a single stream to a single client. In the loop we can simply provide individual small ...
Definition: HttpStreamCopy.h:14
bool isOpen()
Definition: HttpStreamCopy.h:25
HttpChunkWriter writer
Definition: HttpStreamCopy.h:40
void close()
Definition: HttpStreamCopy.h:46
Stream * input_ptr
Definition: HttpStreamCopy.h:41
~HttpStreamCopy()
Definition: HttpStreamCopy.h:23
bool is_open
Definition: HttpStreamCopy.h:44
int output_size
Definition: HttpStreamCopy.h:43
void doLoop()
Definition: HttpStreamCopy.h:27
Client * client_ptr
Definition: HttpStreamCopy.h:42
HttpStreamCopy(Stream &input, Client &client, int outputSize=215)
Definition: HttpStreamCopy.h:16
Definition: Allocator.h:13