22 #include "mythprototransfer.h" 23 #include "../private/debug.h" 24 #include "../private/socket.h" 25 #include "../private/os/threads/mutex.h" 26 #include "../private/builtin.h" 38 ProtoTransfer::ProtoTransfer(
const std::string& server,
unsigned port,
const std::string& pathname,
const std::string& sgname)
44 , m_pathName(pathname)
45 , m_storageGroupName(sgname)
49 bool ProtoTransfer::Open()
55 if (!OpenConnection(PROTO_TRANSFER_RCVBUF))
58 if (m_protoVersion >= 75)
70 void ProtoTransfer::Close()
72 OS::CLockGuard lock(*m_mutex);
77 m_filePosition = m_fileRequest = 0;
81 void ProtoTransfer::Lock()
86 void ProtoTransfer::Unlock()
91 bool ProtoTransfer::TryLock()
93 return m_mutex->TryLock();
98 OS::CLockGuard lock(*m_mutex);
99 int64_t unread = m_fileRequest - m_filePosition;
102 char buf[PROTO_BUFFER_SIZE];
103 size_t n = (size_t)unread;
106 size_t s = (n > PROTO_BUFFER_SIZE ? PROTO_BUFFER_SIZE : n);
107 if(m_socket->ReceiveData(buf, s) != s)
111 DBG(DBG_DEBUG,
"%s: unreaded bytes (%u)\n", __FUNCTION__, (
unsigned)n);
113 m_filePosition = m_fileRequest;
117 bool ProtoTransfer::Announce75()
119 OS::CLockGuard lock(*m_mutex);
120 m_filePosition = m_fileSize = m_fileRequest = 0;
121 std::string cmd(
"ANN FileTransfer ");
122 cmd.append(m_socket->GetMyHostName());
123 cmd.append(
" 0 0 1000" PROTO_STR_SEPARATOR);
124 cmd.append(m_pathName).append(PROTO_STR_SEPARATOR);
125 cmd.append(m_storageGroupName);
126 if (!SendCommand(cmd.c_str()))
130 if (!
ReadField(field) || !IsMessageOK(field))
132 if (!
ReadField(field) || 0 != string_to_uint32(field.c_str(), &m_fileId))
134 if (!
ReadField(field) || 0 != string_to_int64(field.c_str(), &m_fileSize))
143 uint32_t ProtoTransfer::GetFileId()
const 148 std::string ProtoTransfer::GetPathName()
const 153 std::string ProtoTransfer::GetStorageGroupName()
const 155 return m_storageGroupName;
158 int64_t ProtoTransfer::GetSize()
const 160 OS::CLockGuard lock(*m_mutex);
164 int64_t ProtoTransfer::GetPosition()
const 166 OS::CLockGuard lock(*m_mutex);
167 return m_filePosition;
170 int64_t ProtoTransfer::GetRequested()
const 172 OS::CLockGuard lock(*m_mutex);
173 return m_fileRequest;
176 int64_t ProtoTransfer::GetRemaining()
const 178 OS::CLockGuard lock(*m_mutex);
179 return (m_fileSize - m_filePosition);
182 void ProtoTransfer::SetSize(int64_t size)
184 OS::CLockGuard lock(*m_mutex);
188 void ProtoTransfer::SetPosition(int64_t position)
190 OS::CLockGuard lock(*m_mutex);
191 m_filePosition = position;
194 void ProtoTransfer::SetRequested(int64_t requested)
196 OS::CLockGuard lock(*m_mutex);
197 m_fileRequest = requested;
void Flush()
Flushing unread data previously requested.
bool m_hang
Connection hang: while true allow retry.
bool ReadField(std::string &field)
This is the main namespace that encloses all public classes.
bool m_tainted
Connection has hung since last reset.