Skip to content

Commit

Permalink
Eliminated ref_t. Some more convention fixes (#1045)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethouris authored and rndi committed Jan 20, 2020
1 parent 7845bc4 commit c6c29f8
Show file tree
Hide file tree
Showing 32 changed files with 548 additions and 620 deletions.
14 changes: 5 additions & 9 deletions apps/srt-file-transmit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,8 @@ int parse_args(FileTransmitConfig &cfg, int argc, char** argv)
}



void ExtractPath(string path, ref_t<string> dir, ref_t<string> fname)
void ExtractPath(string path, string& w_dir, string& w_fname)
{
//string& dir = r_dir;
//string& fname = r_fname;

string directory = path;
string filename = "";

Expand Down Expand Up @@ -272,8 +268,8 @@ void ExtractPath(string path, ref_t<string> dir, ref_t<string> fname)
directory = wd + "/" + directory;
}

*dir = directory;
*fname = filename;
w_dir = directory;
w_fname = filename;
}

bool DoUpload(UriParser& ut, string path, string filename,
Expand Down Expand Up @@ -648,7 +644,7 @@ bool Upload(UriParser& srt_target_uri, UriParser& fileuri,

string path = fileuri.path();
string directory, filename;
ExtractPath(path, ref(directory), ref(filename));
ExtractPath(path, (directory), (filename));
Verb() << "Extract path '" << path << "': directory=" << directory << " filename=" << filename;
// Set ID to the filename.
// Directory will be preserved.
Expand All @@ -669,7 +665,7 @@ bool Download(UriParser& srt_source_uri, UriParser& fileuri,
}

string path = fileuri.path(), directory, filename;
ExtractPath(path, Ref(directory), Ref(filename));
ExtractPath(path, (directory), (filename));
Verb() << "Extract path '" << path << "': directory=" << directory << " filename=" << filename;

return DoDownload(srt_source_uri, directory, filename, cfg, out_stats);
Expand Down
62 changes: 28 additions & 34 deletions apps/srt-tunnel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ class Medium
virtual int ReadInternal(char* output, int size) = 0;
virtual bool IsErrorAgain() = 0;

ReadStatus Read(ref_t<bytevector> output);
virtual void Write(ref_t<bytevector> portion) = 0;
ReadStatus Read(bytevector& output);
virtual void Write(bytevector& portion) = 0;

virtual void CreateListener() = 0;
virtual void CreateCaller() = 0;
Expand Down Expand Up @@ -335,14 +335,14 @@ void Engine::Worker()
try
{
which_medium = media[DIR_IN];
rdst = media[DIR_IN]->Read(Ref(outbuf));
rdst = media[DIR_IN]->Read((outbuf));
switch (rdst)
{
case Medium::RD_DATA:
{
which_medium = media[DIR_OUT];
// We get the data, write them to the output
media[DIR_OUT]->Write(Ref(outbuf));
media[DIR_OUT]->Write((outbuf));
}
break;

Expand Down Expand Up @@ -411,7 +411,7 @@ class SrtMedium: public Medium
virtual int ReadInternal(char* output, int size) override;
virtual bool IsErrorAgain() override;

virtual void Write(ref_t<bytevector> portion) override;
virtual void Write(bytevector& portion) override;
virtual void CreateListener() override;
virtual void CreateCaller() override;
virtual unique_ptr<Medium> Accept() override;
Expand Down Expand Up @@ -494,7 +494,7 @@ class TcpMedium: public Medium
virtual const char* type() override { return "tcp"; }
virtual int ReadInternal(char* output, int size) override;
virtual bool IsErrorAgain() override;
virtual void Write(ref_t<bytevector> portion) override;
virtual void Write(bytevector& portion) override;
virtual void CreateListener() override;
virtual void CreateCaller() override;
virtual unique_ptr<Medium> Accept() override;
Expand Down Expand Up @@ -691,17 +691,17 @@ void TcpMedium::Connect()
ConfigurePost(m_socket);
}

int SrtMedium::ReadInternal(char* buffer, int size)
int SrtMedium::ReadInternal(char* w_buffer, int size)
{
int st = srt_recv(m_socket, buffer, size);
int st = srt_recv(m_socket, (w_buffer), size);
if (st == SRT_ERROR)
return -1;
return st;
}

int TcpMedium::ReadInternal(char* buffer, int size)
int TcpMedium::ReadInternal(char* w_buffer, int size)
{
return ::recv(m_socket, buffer, size, 0);
return ::recv(m_socket, (w_buffer), size, 0);
}

bool SrtMedium::IsErrorAgain()
Expand All @@ -722,19 +722,17 @@ bool TcpMedium::IsErrorAgain()
// This will cause the worker loop to redirect to Write immediately
// thereafter and possibly will flush out the remains of the buffer.
// It's still possible that the buffer won't be completely purged
Medium::ReadStatus Medium::Read(ref_t<bytevector> r_output)
Medium::ReadStatus Medium::Read(bytevector& w_output)
{
bytevector& output = *r_output;

// Don't read, but fake that you read
if (output.size() > m_chunk)
if (w_output.size() > m_chunk)
{
Verb() << "BUFFER EXCEEDED";
return RD_DATA;
}

// Resize to maximum first
size_t shift = output.size();
size_t shift = w_output.size();
if (shift && m_eof)
{
// You have nonempty buffer, but eof was already
Expand All @@ -747,8 +745,8 @@ Medium::ReadStatus Medium::Read(ref_t<bytevector> r_output)

size_t pred_size = shift + m_chunk;

output.resize(pred_size);
int st = ReadInternal(output.data() + shift, m_chunk);
w_output.resize(pred_size);
int st = ReadInternal((w_output.data() + shift), m_chunk);
if (st == -1)
{
if (IsErrorAgain())
Expand All @@ -769,64 +767,60 @@ Medium::ReadStatus Medium::Read(ref_t<bytevector> r_output)
//
// Set back the size this buffer had before we attempted
// to read into it.
output.resize(shift);
w_output.resize(shift);
return RD_DATA;
}
output.clear();
w_output.clear();
return RD_EOF;
}

output.resize(shift+st);
w_output.resize(shift+st);
return RD_DATA;
}

void SrtMedium::Write(ref_t<bytevector> r_buffer)
void SrtMedium::Write(bytevector& w_buffer)
{
bytevector& buffer = *r_buffer;

int st = srt_send(m_socket, buffer.data(), buffer.size());
int st = srt_send(m_socket, w_buffer.data(), w_buffer.size());
if (st == SRT_ERROR)
{
Error(UDT::getlasterror(), "srt_send");
}

// This should be ==, whereas > is not possible, but
// this should simply embrace this case as a sanity check.
if (st >= int(buffer.size()))
buffer.clear();
if (st >= int(w_buffer.size()))
w_buffer.clear();
else if (st == 0)
{
Error("Unexpected EOF on Write");
}
else
{
// Remove only those bytes that were sent
buffer.erase(buffer.begin(), buffer.begin()+st);
w_buffer.erase(w_buffer.begin(), w_buffer.begin()+st);
}
}

void TcpMedium::Write(ref_t<bytevector> r_buffer)
void TcpMedium::Write(bytevector& w_buffer)
{
bytevector& buffer = *r_buffer;

int st = ::send(m_socket, buffer.data(), buffer.size(), DEF_SEND_FLAG);
int st = ::send(m_socket, w_buffer.data(), w_buffer.size(), DEF_SEND_FLAG);
if (st == -1)
{
Error(errno, "send");
}

// This should be ==, whereas > is not possible, but
// this should simply embrace this case as a sanity check.
if (st >= int(buffer.size()))
buffer.clear();
if (st >= int(w_buffer.size()))
w_buffer.clear();
else if (st == 0)
{
Error("Unexpected EOF on Write");
}
else
{
// Remove only those bytes that were sent
buffer.erase(buffer.begin(), buffer.begin()+st);
w_buffer.erase(w_buffer.begin(), w_buffer.begin()+st);
}
}

Expand Down
24 changes: 12 additions & 12 deletions apps/transmitmedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class FileSource: public Source
throw std::runtime_error(path + ": Can't open file for reading");
}

int Read(size_t chunk, bytevector& data, ostream &SRT_ATR_UNUSED = cout) override
int Read(size_t chunk, bytevector& data, ostream & ignored SRT_ATR_UNUSED = cout) override
{
if (data.size() < chunk)
data.resize(chunk);
Expand Down Expand Up @@ -83,7 +83,7 @@ class FileTarget: public Target

FileTarget(const string& path): ofile(path, ios::out | ios::trunc | ios::binary) {}

int Write(const char* data, size_t size, ostream &SRT_ATR_UNUSED = cout) override
int Write(const char* data, size_t size, ostream & ignored SRT_ATR_UNUSED = cout) override
{
ofile.write(data, size);
return !(ofile.bad()) ? (int) size : 0;
Expand Down Expand Up @@ -598,7 +598,7 @@ SrtModel::SrtModel(string host, int port, map<string,string> par)
m_port = port;
}

void SrtModel::Establish(ref_t<std::string> name)
void SrtModel::Establish(std::string& w_name)
{
// This does connect or accept.
// When this returned true, the caller should create
Expand All @@ -614,10 +614,10 @@ void SrtModel::Establish(ref_t<std::string> name)

PrepareClient();

if (name.get() != "")
if (w_name != "")
{
Verb() << "Connect with requesting stream [" << name.get() << "]";
UDT::setstreamid(m_sock, *name);
Verb() << "Connect with requesting stream [" << w_name << "]";
UDT::setstreamid(m_sock, w_name);
}
else
{
Expand Down Expand Up @@ -660,8 +660,8 @@ void SrtModel::Establish(ref_t<std::string> name)
Verb() << "Accepting a client...";
AcceptNewClient();
// This rewrites m_sock with a new SRT socket ("accepted" socket)
*name = UDT::getstreamid(m_sock);
Verb() << "... GOT CLIENT for stream [" << name.get() << "]";
w_name = UDT::getstreamid(m_sock);
Verb() << "... GOT CLIENT for stream [" << w_name << "]";
}
}

Expand All @@ -686,7 +686,7 @@ class ConsoleSource: public Source
#endif
}

int Read(size_t chunk, bytevector& data, ostream &SRT_ATR_UNUSED = cout) override
int Read(size_t chunk, bytevector& data, ostream & ignored SRT_ATR_UNUSED = cout) override
{
if (data.size() < chunk)
data.resize(chunk);
Expand Down Expand Up @@ -728,7 +728,7 @@ class ConsoleTarget: public Target
cout.flush();
}

int Write(const char* data, size_t len, ostream &SRT_ATR_UNUSED = cout) override
int Write(const char* data, size_t len, ostream & ignored SRT_ATR_UNUSED = cout) override
{
cout.write(data, len);
return (int) len;
Expand Down Expand Up @@ -958,7 +958,7 @@ class UdpSource: public Source, public UdpCommon
eof = false;
}

int Read(size_t chunk, bytevector& data, ostream &SRT_ATR_UNUSED = cout) override
int Read(size_t chunk, bytevector& data, ostream & ignored SRT_ATR_UNUSED = cout) override
{
if (data.size() < chunk)
data.resize(chunk);
Expand Down Expand Up @@ -1007,7 +1007,7 @@ class UdpTarget: public Target, public UdpCommon

}

int Write(const char* data, size_t len, ostream &SRT_ATR_UNUSED = cout) override
int Write(const char* data, size_t len, ostream & ignored SRT_ATR_UNUSED = cout) override
{
int stat = sendto(m_sock, data, (int) len, 0, (sockaddr*)&sadr, sizeof sadr);
if ( stat == -1 )
Expand Down
2 changes: 1 addition & 1 deletion apps/transmitmedia.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class SrtModel: public SrtCommon


SrtModel(string host, int port, map<string,string> par);
void Establish(ref_t<std::string> name);
void Establish(std::string& name);

void Close()
{
Expand Down
Loading

0 comments on commit c6c29f8

Please sign in to comment.