FtpDataStream.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * FtpDataStream.h
8  *
9  ****/
10 
11 #pragma once
12 
13 #include "FtpServerConnection.h"
14 #include "Network/TcpConnection.h"
15 
17 {
18 public:
19  explicit FtpDataStream(FtpServerConnection* connection) : TcpConnection(true), parent(connection)
20  {
21  }
22 
23  err_t onConnected(err_t err) override
24  {
25  //response(125, "Connected");
26  setTimeOut(300); // Update timeout
27  return TcpConnection::onConnected(err);
28  }
29 
30  err_t onSent(uint16_t len) override
31  {
32  sent += len;
33  if(written < sent || !completed) {
34  return TcpConnection::onSent(len);
35  }
37  return TcpConnection::onSent(len);
38  }
39 
41  {
42  close();
44  }
45 
46  void response(int code, String text = nullptr)
47  {
48  parent->response(code, text);
49  }
50 
51  int write(const char* data, int len, uint8_t apiflags = 0) override
52  {
53  written += len;
54  return TcpConnection::write(data, len, apiflags);
55  }
56 
57  void onReadyToSendData(TcpConnectionEvent sourceEvent) override
58  {
59  if(!parent->isCanTransfer()) {
60  return;
61  }
62  if(completed && written == 0) {
64  }
65  transferData(sourceEvent);
66  }
67 
68  virtual void transferData(TcpConnectionEvent sourceEvent)
69  {
70  }
71 
72 protected:
74  bool completed = false;
75  unsigned written = 0;
76  unsigned sent = 0;
77 };
Definition: FtpDataStream.h:16
virtual err_t onSent(uint16_t len)
void onReadyToSendData(TcpConnectionEvent sourceEvent) override
Definition: FtpDataStream.h:57
err_t onSent(uint16_t len) override
Definition: FtpDataStream.h:30
virtual void close()
Definition: TcpConnection.h:39
FtpServerConnection * parent
Definition: FtpDataStream.h:73
The String class.
Definition: WString.h:136
virtual void response(int code, String text="")
void response(int code, String text=nullptr)
Definition: FtpDataStream.h:46
virtual err_t onConnected(err_t err)
void setTimeOut(uint16_t waitTimeOut)
TcpConnectionEvent
Definition: TcpConnection.h:25
int write(const char *data, int len, uint8_t apiflags=0) override
Base write operation.
Definition: FtpDataStream.h:51
void dataTransferFinished(TcpConnection *connection)
virtual int write(const char *data, int len, uint8_t apiflags=TCP_WRITE_FLAG_COPY)
Base write operation.
void finishTransfer()
Definition: FtpDataStream.h:40
bool completed
Definition: FtpDataStream.h:74
Definition: FtpServerConnection.h:29
virtual void transferData(TcpConnectionEvent sourceEvent)
Definition: FtpDataStream.h:68
unsigned sent
Definition: FtpDataStream.h:76
err_t onConnected(err_t err) override
Definition: FtpDataStream.h:23
FtpDataStream(FtpServerConnection *connection)
Definition: FtpDataStream.h:19
bool isCanTransfer()
Definition: FtpServerConnection.h:56
unsigned written
Definition: FtpDataStream.h:75