Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor FTP classes #2125

Merged
merged 2 commits into from
Oct 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Sming/Core/Network/Ftp/FtpDataFileList.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class FtpDataFileList : public FtpDataStream
{
public:
explicit FtpDataFileList(FtpServerConnection* connection) : FtpDataStream(connection)
explicit FtpDataFileList(FtpServerConnection& connection) : FtpDataStream(connection)
{
}

Expand All @@ -28,7 +28,12 @@ class FtpDataFileList : public FtpDataStream
Vector<String> list = fileList();
debug_d("send file list: %d", list.count());
for(unsigned i = 0; i < list.count(); i++) {
writeString("01-01-15 01:00AM " + String(fileGetSize(list[i])) + " " + list[i] + "\r\n");
String s = F("01-01-15 01:00AM ");
s += fileGetSize(list[i]);
s += ' ';
s += list[i];
s += "\r\n";
writeString(s);
}
completed = true;
finishTransfer();
Expand Down
2 changes: 1 addition & 1 deletion Sming/Core/Network/Ftp/FtpDataRetrieve.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class FtpDataRetrieve : public FtpDataStream
{
public:
FtpDataRetrieve(FtpServerConnection* connection, const String& fileName)
FtpDataRetrieve(FtpServerConnection& connection, const String& fileName)
: FtpDataStream(connection), file(fileOpen(fileName, eFO_ReadOnly))
{
}
Expand Down
2 changes: 1 addition & 1 deletion Sming/Core/Network/Ftp/FtpDataStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class FtpDataStore : public FtpDataStream
{
public:
FtpDataStore(FtpServerConnection* connection, const String& fileName)
FtpDataStore(FtpServerConnection& connection, const String& fileName)
: FtpDataStream(connection), file(fileOpen(fileName, eFO_WriteOnly | eFO_CreateNewAlways))
{
}
Expand Down
16 changes: 8 additions & 8 deletions Sming/Core/Network/Ftp/FtpDataStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class FtpDataStream : public TcpConnection
{
public:
explicit FtpDataStream(FtpServerConnection* connection) : TcpConnection(true), parent(connection)
explicit FtpDataStream(FtpServerConnection& connection) : TcpConnection(true), parent(connection)
{
}

Expand All @@ -40,12 +40,12 @@ class FtpDataStream : public TcpConnection
void finishTransfer()
{
close();
parent->dataTransferFinished(this);
parent.dataTransferFinished(this);
}

void response(int code, String text = nullptr)
{
parent->response(code, text);
parent.response(code, text);
}

int write(const char* data, int len, uint8_t apiflags = 0) override
Expand All @@ -56,7 +56,7 @@ class FtpDataStream : public TcpConnection

void onReadyToSendData(TcpConnectionEvent sourceEvent) override
{
if(!parent->isCanTransfer()) {
if(!parent.isCanTransfer()) {
return;
}
if(completed && written == 0) {
Expand All @@ -70,8 +70,8 @@ class FtpDataStream : public TcpConnection
}

protected:
FtpServerConnection* parent = nullptr;
bool completed = false;
unsigned written = 0;
unsigned sent = 0;
FtpServerConnection& parent;
bool completed{false};
unsigned written{0};
unsigned sent{0};
};
Loading