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