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

[BUG] Fixed the use of the right error constant #2595

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2424c99
Fixing implicit integer and wrong use of SRT_ERROR and SRT_INVALID_SO…
Dec 22, 2022
6ad1041
[MAINT] Fixed example buildbreaks. Added examples for message mode tr…
ethouris Dec 22, 2022
340f0b5
Updated
ethouris Dec 22, 2022
29e8c19
Fixed wrong assertion for drop snd buf sequence check
Dec 23, 2022
31b3a78
Updated
Dec 23, 2022
ce98b8a
[MAINT] Refax for CSndBuffer::readData to make the call form clearer
Dec 23, 2022
333eaf2
[MAINT] Removed reference fields from CPacket pinned to the SRT header
Dec 23, 2022
43c0883
Updated and fixed
Dec 23, 2022
6e2280d
Updated with the fixes
Dec 23, 2022
512e548
Merge branch 'master' into dev-fix-implicit-int
Jan 11, 2023
08d1e5c
Minor fixes
Jan 11, 2023
4888873
Merge branch 'master' into dev-refax-readdata-rexmit
Jan 11, 2023
dba39ef
Merge branch 'master' into dev-refax-readdata-rexmit
Jan 24, 2023
addefb3
Merge branch 'master' into dev-fix-implicit-int
Jan 25, 2023
03c19ac
Merge branch 'master' into dev-refax-readdata-rexmit
Feb 20, 2023
b0e681f
Updated and fixed
Feb 20, 2023
3781775
Merge branch 'master' into dev-refax-readdata-rexmit
May 4, 2023
d126e64
Merge branch 'master' into dev-refax-remove-cpacket-refs
May 8, 2023
380e12f
Updated to latest upstream through #2594
May 8, 2023
88b9f33
Fixed build break on Android
May 10, 2023
084c9c5
Merge branch 'master' into dev-refax-remove-cpacket-refs
Sep 14, 2023
185276c
Merged and fixed
Sep 14, 2023
200e3c5
Updated and fixed
Oct 9, 2023
1ffde27
Merge branch 'master' into dev-refax-readdata-rexmit
Oct 10, 2023
58fbf27
Updated and fixed
Oct 10, 2023
a0de6ff
Merge branch 'dev-refax-remove-cpacket-refs' into dev-fix-implicit-int
Oct 10, 2023
920969b
Synchronized and improved
Oct 10, 2023
7a4e00c
Fixed clang warnings (build break on some CI)
Oct 10, 2023
8c0102a
Updated and fixed
Feb 19, 2024
d28e3b2
Introduced SRTRUNSTATUS to cover all cases of srt_startup(). Fixed do…
Feb 19, 2024
be302ca
Removed srt::isgroup. Reused CUDT::isgroup where applicable. Added mi…
Feb 20, 2024
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
14 changes: 9 additions & 5 deletions apps/socketoptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,27 @@ struct SocketOption
bool applyt(Object socket, std::string value) const;

template <Domain D, typename Object>
static int setso(Object socket, int protocol, int symbol, const void* data, size_t size);
static int setso(Object socket, int protocol, int symbol, const void* data, size_t size)
{
typename Object::wrong_version error;
return -1;
}

template<Type T>
bool extract(std::string value, OptionValue& val) const;
};

template<>
inline int SocketOption::setso<SocketOption::SRT, int>(int socket, int /*ignored*/, int sym, const void* data, size_t size)
inline int SocketOption::setso<SocketOption::SRT, SRTSOCKET>(SRTSOCKET socket, int /*ignored*/, int sym, const void* data, size_t size)
{
return srt_setsockopt(socket, 0, SRT_SOCKOPT(sym), data, (int) size);
return (int)srt_setsockopt(socket, 0, SRT_SOCKOPT(sym), data, (int) size);
}

#if ENABLE_BONDING
template<>
inline int SocketOption::setso<SocketOption::SRT, SRT_SOCKOPT_CONFIG*>(SRT_SOCKOPT_CONFIG* obj, int /*ignored*/, int sym, const void* data, size_t size)
{
return srt_config_add(obj, SRT_SOCKOPT(sym), data, (int) size);
return (int)srt_config_add(obj, SRT_SOCKOPT(sym), data, (int) size);
}
#endif

Expand Down Expand Up @@ -184,7 +188,7 @@ inline bool SocketOption::applyt(Object socket, std::string value) const
int result = -1;
if (extract<T>(value, o))
result = setso<D>(socket, protocol, symbol, o.value, o.size);
return result != -1;
return result != int(SRT_ERROR);
}


Expand Down
6 changes: 3 additions & 3 deletions apps/statswriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class SrtStatsJson : public SrtStatsWriter
}

public:
string WriteStats(int sid, const CBytePerfMon& mon) override
string WriteStats(SRTSOCKET sid, const CBytePerfMon& mon) override
{
std::ostringstream output;

Expand Down Expand Up @@ -235,7 +235,7 @@ class SrtStatsCsv : public SrtStatsWriter
public:
SrtStatsCsv() : first_line_printed(false) {}

string WriteStats(int sid, const CBytePerfMon& mon) override
string WriteStats(SRTSOCKET sid, const CBytePerfMon& mon) override
{
std::ostringstream output;

Expand Down Expand Up @@ -286,7 +286,7 @@ class SrtStatsCsv : public SrtStatsWriter
class SrtStatsCols : public SrtStatsWriter
{
public:
string WriteStats(int sid, const CBytePerfMon& mon) override
string WriteStats(SRTSOCKET sid, const CBytePerfMon& mon) override
{
std::ostringstream output;
output << "======= SRT STATS: sid=" << sid << endl;
Expand Down
2 changes: 1 addition & 1 deletion apps/statswriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct SrtStatDataType: public SrtStatData
class SrtStatsWriter
{
public:
virtual std::string WriteStats(int sid, const CBytePerfMon& mon) = 0;
virtual std::string WriteStats(SRTSOCKET sid, const CBytePerfMon& mon) = 0;
virtual std::string WriteBandwidth(double mbpsBandwidth) = 0;
virtual ~SrtStatsWriter() {}

Expand Down
67 changes: 33 additions & 34 deletions apps/transmitmedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,19 @@ void SrtCommon::InitParameters(string host, map<string,string> par)
void SrtCommon::PrepareListener(string host, int port, int backlog)
{
m_bindsock = srt_create_socket();
if ( m_bindsock == SRT_ERROR )
if (m_bindsock == SRT_INVALID_SOCK)
Error("srt_create_socket");

int stat = ConfigurePre(m_bindsock);
if ( stat == SRT_ERROR )
SRTSTATUS stat = ConfigurePre(m_bindsock);
if (stat == SRT_ERROR)
Error("ConfigurePre");

sockaddr_any sa = CreateAddr(host, port);
sockaddr* psa = sa.get();
Verb() << "Binding a server on " << host << ":" << port << " ...";

stat = srt_bind(m_bindsock, psa, sizeof sa);
if ( stat == SRT_ERROR )
if (stat == SRT_ERROR)
{
srt_close(m_bindsock);
Error("srt_bind");
Expand All @@ -229,7 +229,7 @@ void SrtCommon::PrepareListener(string host, int port, int backlog)
Verb() << " listen...";

stat = srt_listen(m_bindsock, backlog);
if ( stat == SRT_ERROR )
if (stat == SRT_ERROR)
{
srt_close(m_bindsock);
Error("srt_listen");
Expand Down Expand Up @@ -272,8 +272,8 @@ bool SrtCommon::AcceptNewClient()

// ConfigurePre is done on bindsock, so any possible Pre flags
// are DERIVED by sock. ConfigurePost is done exclusively on sock.
int stat = ConfigurePost(m_sock);
if ( stat == SRT_ERROR )
SRTSTATUS stat = ConfigurePost(m_sock);
if (stat == SRT_ERROR)
Error("ConfigurePost");

return true;
Expand All @@ -299,14 +299,14 @@ void SrtCommon::Init(string host, int port, map<string,string> par, bool dir_out
}
}

int SrtCommon::ConfigurePost(SRTSOCKET sock)
SRTSTATUS SrtCommon::ConfigurePost(SRTSOCKET sock)
{
bool no = false;
int result = 0;
SRTSTATUS result = SRT_STATUS_OK;
if ( m_output_direction )
{
result = srt_setsockopt(sock, 0, SRTO_SNDSYN, &no, sizeof no);
if ( result == -1 )
if ( result == SRT_ERROR )
return result;

if ( m_timeout )
Expand All @@ -315,7 +315,7 @@ int SrtCommon::ConfigurePost(SRTSOCKET sock)
else
{
result = srt_setsockopt(sock, 0, SRTO_RCVSYN, &no, sizeof no);
if ( result == -1 )
if ( result == SRT_ERROR )
return result;

if ( m_timeout )
Expand All @@ -339,23 +339,23 @@ int SrtCommon::ConfigurePost(SRTSOCKET sock)
}
}

return 0;
return SRT_STATUS_OK;
}

int SrtCommon::ConfigurePre(SRTSOCKET sock)
SRTSTATUS SrtCommon::ConfigurePre(SRTSOCKET sock)
{
int result = 0;
SRTSTATUS result = SRT_STATUS_OK;

bool no = false;
if ( !m_tsbpdmode )
{
result = srt_setsockopt(sock, 0, SRTO_TSBPDMODE, &no, sizeof no);
if ( result == -1 )
if ( result == SRT_ERROR )
return result;
}

result = srt_setsockopt(sock, 0, SRTO_RCVSYN, &no, sizeof no);
if ( result == -1 )
if ( result == SRT_ERROR )
return result;


Expand All @@ -380,14 +380,14 @@ int SrtCommon::ConfigurePre(SRTSOCKET sock)
return SRT_ERROR;
}

return 0;
return SRT_STATUS_OK;
}

void SrtCommon::SetupAdapter(const string& host, int port)
{
sockaddr_any localsa = CreateAddr(host, port);
sockaddr* psa = localsa.get();
int stat = srt_bind(m_sock, psa, sizeof localsa);
SRTSTATUS stat = srt_bind(m_sock, psa, sizeof localsa);
if ( stat == SRT_ERROR )
Error("srt_bind");
}
Expand All @@ -407,31 +407,30 @@ void SrtCommon::OpenClient(string host, int port)
void SrtCommon::PrepareClient()
{
m_sock = srt_create_socket();
if ( m_sock == SRT_ERROR )
if ( m_sock == SRT_INVALID_SOCK)
Error("srt_create_socket");

int stat = ConfigurePre(m_sock);
SRTSTATUS stat = ConfigurePre(m_sock);
if ( stat == SRT_ERROR )
Error("ConfigurePre");
}


void SrtCommon::ConnectClient(string host, int port)
{

sockaddr_any sa = CreateAddr(host, port);
sockaddr* psa = sa.get();

Verb() << "Connecting to " << host << ":" << port;

int stat = srt_connect(m_sock, psa, sizeof sa);
if ( stat == SRT_ERROR )
SRTSOCKET cstat = srt_connect(m_sock, psa, sizeof sa);
if (cstat == SRT_INVALID_SOCK)
{
srt_close(m_sock);
Error("srt_connect");
}

stat = ConfigurePost(m_sock);
SRTSTATUS stat = ConfigurePost(m_sock);
if ( stat == SRT_ERROR )
Error("ConfigurePost");
}
Expand All @@ -449,13 +448,13 @@ void SrtCommon::Error(string src)
void SrtCommon::OpenRendezvous(string adapter, string host, int port)
{
m_sock = srt_create_socket();
if ( m_sock == SRT_ERROR )
if (m_sock == SRT_INVALID_SOCK)
Error("srt_create_socket");

bool yes = true;
srt_setsockopt(m_sock, 0, SRTO_RENDEZVOUS, &yes, sizeof yes);

int stat = ConfigurePre(m_sock);
SRTSTATUS stat = ConfigurePre(m_sock);
if ( stat == SRT_ERROR )
Error("ConfigurePre");

Expand All @@ -480,8 +479,8 @@ void SrtCommon::OpenRendezvous(string adapter, string host, int port)

Verb() << "Connecting to " << host << ":" << port;

stat = srt_connect(m_sock, sa.get(), sizeof sa);
if ( stat == SRT_ERROR )
SRTSOCKET cstat = srt_connect(m_sock, sa.get(), sizeof sa);
if ( cstat == SRT_INVALID_SOCK)
{
srt_close(m_sock);
Error("srt_connect");
Expand Down Expand Up @@ -565,10 +564,10 @@ int SrtSource::Read(size_t chunk, MediaPacket& pkt, ostream &out_stats)
return stat;
}

int SrtTarget::ConfigurePre(SRTSOCKET sock)
SRTSTATUS SrtTarget::ConfigurePre(SRTSOCKET sock)
{
int result = SrtCommon::ConfigurePre(sock);
if ( result == -1 )
SRTSTATUS result = SrtCommon::ConfigurePre(sock);
if ( result == SRT_ERROR )
return result;

int yes = 1;
Expand All @@ -577,10 +576,10 @@ int SrtTarget::ConfigurePre(SRTSOCKET sock)
// In HSv4 this setting is obligatory; otherwise the SRT handshake
// extension will not be done at all.
result = srt_setsockopt(sock, 0, SRTO_SENDER, &yes, sizeof yes);
if ( result == -1 )
if ( result == SRT_ERROR )
return result;

return 0;
return SRT_STATUS_OK;
}

int SrtTarget::Write(const char* data, size_t size, int64_t src_time, ostream &out_stats)
Expand All @@ -590,7 +589,7 @@ int SrtTarget::Write(const char* data, size_t size, int64_t src_time, ostream &o
SRT_MSGCTRL ctrl = srt_msgctrl_default;
ctrl.srctime = src_time;
int stat = srt_sendmsg2(m_sock, data, (int) size, &ctrl);
if (stat == SRT_ERROR)
if (stat == int(SRT_ERROR))
{
return stat;
}
Expand Down
6 changes: 3 additions & 3 deletions apps/transmitmedia.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class SrtCommon
void Error(string src);
void Init(string host, int port, map<string,string> par, bool dir_output);

virtual int ConfigurePost(SRTSOCKET sock);
virtual int ConfigurePre(SRTSOCKET sock);
virtual SRTSTATUS ConfigurePost(SRTSOCKET sock);
virtual SRTSTATUS ConfigurePre(SRTSOCKET sock);

void OpenClient(string host, int port);
void PrepareClient();
Expand Down Expand Up @@ -132,7 +132,7 @@ class SrtTarget: public Target, public SrtCommon

SrtTarget() {}

int ConfigurePre(SRTSOCKET sock) override;
SRTSTATUS ConfigurePre(SRTSOCKET sock) override;
int Write(const char* data, size_t size, int64_t src_time, ostream &out_stats = cout) override;
bool IsOpen() override { return IsUsable(); }
bool Broken() override { return IsBroken(); }
Expand Down
74 changes: 74 additions & 0 deletions common/devel_util.h
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference with utilities.h?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file contains things that are in any temporary use for development. This is only provided for convenience for the use during development, but the normal code goes with this file ousted, with provided just plain definitions for the specific types as alias to integer.

Directly this file is provided so that by a temporary change in srt.h you can run the compile command and then by the errors you get you can find out where the rules for the right usage of the status types has been violated.

Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

template<class INT, int ambg>
struct IntWrapper
{
INT v;

IntWrapper() {}
explicit IntWrapper(INT val): v(val) {}

bool operator==(const IntWrapper& x) const
{
return v == x.v;
}

bool operator!=(const IntWrapper& x) const
{
return !(*this == x);
}

explicit operator INT() const
{
return v;
}

template<class I, class T>
friend T& operator<<(T& out, const IntWrapper<I, ambg>& x)
{
out << x.v;
return out;
}

bool operator<(const IntWrapper& w) const
{
return v < w.v;
}
};

template<class INT, int ambg>
struct IntWrapperLoose: IntWrapper<INT, ambg>
{
typedef IntWrapper<INT, ambg> base_t;
explicit IntWrapperLoose(INT val): base_t(val) {}

bool operator==(const IntWrapper<INT, ambg>& x) const
{
return this->v == x.v;
}

friend bool operator==(const IntWrapper<INT, ambg>& x, const IntWrapperLoose& y)
{
return x.v == y.v;
}

bool operator==(INT val) const
{
return this->v == val;
}

friend bool operator==(INT val, const IntWrapperLoose<INT, ambg>& x)
{
return val == x.v;
}

operator INT() const
{
return this->v;
}
};


typedef IntWrapper<int32_t, 0> SRTSOCKET;
typedef IntWrapper<int, 1> SRTSTATUS;
typedef IntWrapperLoose<int, 1> SRTSTATUS_LOOSE;

2 changes: 1 addition & 1 deletion examples/sendmsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ int main(int argc, char* argv[])
// 2. Otherwise the first number is the ID, followed by a space, to be filled in first 4 bytes.
// 3. Rest of the characters, up to the end of line, should be put into a solid block and sent at once.

int status = 0;
int status = SRT_STATUS_OK;

int ordinal = 1;
int lpos = 0;
Expand Down
Loading