Skip to content

Commit

Permalink
Further fixes for OptionProxy. Some cosmetics in the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikołaj Małecki committed Jan 23, 2024
1 parent 122d8a2 commit e8cd37d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
31 changes: 25 additions & 6 deletions apps/apputil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,22 +350,41 @@ struct OptionSetterProxy

struct OptionProxy
{
const OptionSetterProxy& parent;
OptionSetterProxy& parent;
SRT_SOCKOPT opt;

template<class Type>
OptionProxy& operator=(Type&& val)
#define SPEC(type) \
OptionProxy& operator=(const type& val)\
{\
parent.result = srt_setsockflag(parent.s, opt, &val, sizeof val);\
return *this;\
}

SPEC(int32_t);
SPEC(int64_t);
SPEC(bool);
#undef SPEC

template<size_t N>
OptionProxy& operator=(const char (&val)[N])
{
parent.result = srt_setsockflag(parent.s, opt, val, N-1);
return *this;
}

OptionProxy& operator=(const std::string& val)
{
Type vc(val);
srt_setsockflag(parent.s, opt, &vc, sizeof vc);
parent.result = srt_setsockflag(parent.s, opt, val.c_str(), val.size());
return *this;
}
};

OptionProxy operator[](SRT_SOCKOPT opt) const
OptionProxy operator[](SRT_SOCKOPT opt)
{
return OptionProxy {*this, opt};
}

operator int() { return result; }
};

inline OptionSetterProxy setopt(SRTSOCKET socket)
Expand Down
6 changes: 4 additions & 2 deletions docs/API/API-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ below).
* `addrlen`: INPUT: size of `addr` pointed object. OUTPUT: real size of the
returned object

General requirements for parameter correctness:
General requirements for a parameter correctness:

* `lsn` must be first [bound](#srt_bind) and [listening](#srt_listen)

Expand All @@ -656,7 +656,7 @@ depends on the address type used in the `srt_bind` call for `lsn`.
If unsure in a particular situation, it is recommended that you use
`sockaddr_storage` or `srt::sockaddr_any`.

If the `lsn` listener socket is blocking mode (if
If the `lsn` listener socket is in the blocking mode (if
[`SRTO_RCVSYN`](API-socket-options.md#SRTO_RCVSYN) is set to true,
which is default), the call will block until the incoming connection is ready
for extraction. Otherwise, the call always returns immediately, possibly with
Expand Down Expand Up @@ -707,6 +707,8 @@ request. This feature is prone to more tricky rules, however:
continue blocking. If you want to use only one thread for accepting
connections from potentially multiple listening sockets in the blocking
mode, you should use [`srt_accept_bond`](#srt_accept_bond) instead.
Note though that this function is actually a wrapper that changes locally
to the nonblocking mode on all these listeners and uses epoll internally.

* If at the moment multiple listener sockets have received connection
request and you query them all for readiness epoll flags (by calling
Expand Down

0 comments on commit e8cd37d

Please sign in to comment.