-
Notifications
You must be signed in to change notification settings - Fork 5
/
ftpconnection.cpp
66 lines (54 loc) · 1.22 KB
/
ftpconnection.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "ftpconnection.h"
#include "ftp.h"
#include "log.h"
#include <psp2/net/net.h>
#include <psp2/kernel/error.h>
FtpConnection::FtpConnection(int socket)
: m_socket(socket)
, m_valid(true)
, m_ftpThread(this)
{
auto nonblocking = 0;
auto res = sceNetSetsockopt(socket, SCE_NET_SOL_SOCKET, SCE_NET_SO_NBIO, &nonblocking, sizeof(nonblocking));
if (res < 0)
{
LOG("error setting socket to blocking I/O (0x%08X)\n", res);
return;
}
auto set = 1;
res = sceNetSetsockopt(socket, SCE_NET_SOL_SOCKET, SCE_NET_TCP_NODELAY, &set, sizeof(set));
if (res < 0)
{
LOG("error setting TCP no-delay on socket (0x%08X)\n", res);
}
m_ftpThread.start();
}
FtpConnection::~FtpConnection()
{
if (!m_valid)
{
return;
}
close();
}
bool FtpConnection::valid() const
{
return m_valid;
}
int FtpConnection::close()
{
auto res = sceNetSocketClose(m_socket);
m_socket = -1;
m_valid = false;
return res;
}
FtpConnection::FtpThread::FtpThread(FtpConnection *connection)
: m_connection(connection)
{
setStackSize(30*1024);
}
void FtpConnection::FtpThread::run()
{
do_ftp(m_connection->m_socket);
m_connection->close();
}