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

Added modified API.md and new APISocketOptions.md #1510

Merged
merged 5 commits into from
Sep 4, 2020

Conversation

stevomatthews
Copy link
Collaborator

In response to PR#1378, I have removed the socket options sections from API.md, and incorporated them in the new document APISocketOptions.md. Both files have been edited and require technical review.

@maxsharabayko maxsharabayko added this to the v1.5.0 - Sprint 22 milestone Aug 31, 2020
@maxsharabayko maxsharabayko added [docs] Area: Improvements or additions to documentation Type: Maintenance Work required to maintain or clean up the code labels Aug 31, 2020
Comment on lines +1227 to +1234
- *TODO: This option weirdly only allows the socket used in **bind()** to use the
local address that another socket is already using, but not to disallow another
socket in the same application to use the binding address that the current
socket is already using. What it actually changes is that when given an address in
**bind()** is already used by another socket, this option will make the binding
fail instead of adding the socket to the shared group of that socket that
already has bound this address - but it will not disallow another socket to reuse
its address.*
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ethouris Could you comment on this TODO? Is it still valid?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Tell you what. Remove this, and I'll make a PR to fix it. This maybe isn't as bad as described here, but I still think there's some weird inconsistency.

docs/API.md Outdated

There are some example applications so that you can see how the API is being used,
including `srt-live-transmit`, `srt-file-transmit` and `srt-multiplex`. All SRT
related material is contained in `transmitmedia.*` files in the `common` directory
Copy link
Collaborator

Choose a reason for hiding this comment

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

Things have changed over time here and it wasn't updated:

  1. srt-multiplex no longer exists. The architecture was updated in srt-live-transmit and therefore this application has been moved to test, as only they preserve the old architecture. So this file should be removed from this list.
  2. The directory that contains these transmitmedia.* files is now apps, not common.

Rest of the description can stay as is.

docs/API.md Outdated
* srctime: [OUT] timestamp set for this dataset when sending
* pktseq: [OUT] packet sequence number (first packet from the message, if it spans multiple UDP packets)
* msgno: [OUT] message number assigned to the currently received message
* `msgttl`: inorder; unused
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here were two fields mentioned in this entry. So, either leave as is, or split into two different enums.

docs/API.md Outdated
Mode settings determine how the sender and receiver functions work.
The main socket options (see below for full description) that control it are:
Mode settings determine how the sender and receiver functions work. The main
[socket options](#https://github.com/Haivision/srt/blob/master/docs/API-SocketOptions.md)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Dash in the name causes likely a wrong link.

OTOH I personally prefer the API-SocketOptions.md filename, you may consider renaming it.

BTW. I think it will be better if the links to the document use a relative, not network-absolute path.

@maxsharabayko maxsharabayko linked an issue Sep 1, 2020 that may be closed by this pull request
and receiving. For example, SNDSYN defines blocking for `srt_connect` and
RCVSYN defines blocking for `srt_accept`. The SNDSYN also makes `srt_close`
and receiving. For example, `SNDSYN` defines blocking for `srt_connect` and
`RCVSYN` defines blocking for `srt_accept`. The `SNDSYN` also makes `srt_close`
Copy link
Collaborator

@ethouris ethouris Sep 1, 2020

Choose a reason for hiding this comment

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

That should be updated as this is completely wrong.

The non-blocking for srt_connect is set by setting SRTO_RCVSYN to false (surprisingly, as the connection-ready state in epoll is SRT_EPOLL_OUT). The non-blocking for srt_accept is, also surprisingly, set by SRTO_RCVSYN to false on the listener socket from which the accepting is done, although the readiness for acceptance is marked by SRT_EPOLL_IN event in epoll.

I'd make rather something like this:

Note also that blocking and non-blocking modes apply not only for sending and receiving. The SRTO_RCVSYN flag set to false on a socket used with srt_connect makes this function work asynchronously (connection-ready state in epoll is however SRT_EPOLL_OUT - that is, you should call this function once, and then treat it as connected when it becomes write-ready). When this flag is set to false on a listener socket, then the call to srt_accept with that socket is also asynchronous (accept-ready state in epoll is SRT_EPOLL_IN), that is, when called without having a new connection reporting in, it will return immediately with SRT_EASYNCRCV. Also when SRTO_SNDSYN set to true on the socket (default), it makes also srt_close exit only after the sending buffer is completely empty.

Copy link
Collaborator

Choose a reason for hiding this comment

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

(Updated the comment above - I messed up a bit with explanations, but the text in the last paragraph is ok.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How about this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Blocking and Non-blocking Mode

SRT functions can also work in blocking and non-blocking modes, for which
there are two separate options for sending and receiving: SRTO_SNDSYN and
SRTO_RCVSYN. When blocking mode is used, a function will not exit until
the availability condition is satisfied. In non-blocking mode the function
always exits immediately, and if enough resources are not available it
returns an error with an appropriate code. The use of non-blocking mode usually
requires using some polling mechanism, which in SRT is EPoll.

Note also that blocking and non-blocking modes apply not only to sending and
receiving. For example, to make srt_connect run asynchronously (blocking mode),
set SRTO_RCVSYN to false on the socket used for connecting (the SRT_EPOLL_OUT
readiness should be checked here). To make srt_accept run asynchronously (blocking
mode), set SRTO_RCVSYN to false on the listener socket (the SRT_EPOLL_IN readiness
should be checked here). Setting SRTO_SNDSYN to true on the socket makes srt_close
exit only after the sending buffer is completely empty.

Copy link
Collaborator

Choose a reason for hiding this comment

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

First of all, to make you imagine how it works: The SRTO_SNDSYN and SRTO_RCVSYN options are set to true by default, and this means blocking mode. So you should set appropriate option to false in order to have non-blocking mode. So, among things mentioned here:

  • SRTO_RCVSYN set to false makes srt_connect run asynchronously (non-blocking)
  • IDEM (on the listener socket), makes srt_accept run asynchronously (non-blocking)
  • When SRTO_SNDSYN is true (default!) then also srt_close will block until the sender buffer is empty. When this is set to false, the srt_close function exits immediately, but sending will continue in the background.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Blocking and Non-blocking Mode

SRT functions can also work in blocking and non-blocking modes, for which
there are two separate options for sending and receiving: SRTO_SNDSYN and
SRTO_RCVSYN (both are set to true by default, corresponding to blocking mode).
When blocking mode is used, a function will not exit until the availability
condition is satisfied. In non-blocking mode the function always exits immediately,
and if enough resources are not available it returns an error with an appropriate
code. The use of non-blocking mode usually requires using some polling mechanism,
which in SRT is EPoll.

Note also that blocking and non-blocking modes apply not only to sending and
receiving. For example, to make srt_connect run asynchronously (non-blocking mode),
set SRTO_RCVSYN to false on the socket used for connecting (the SRT_EPOLL_OUT
readiness should be checked here). To make srt_accept run asynchronously (non-blocking
mode), set SRTO_RCVSYN to false on the listener socket (the SRT_EPOLL_IN readiness
should be checked here). When SRTO_SNDSYN is true (default) then also srt_close
will block until the sender buffer is empty. When SRTO_SNDSYN is set to false, the
srt_close function exits immediately, but sending will continue in the background.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Perfect.

docs/API.md Outdated

The following terms are used in the description of transmission types:

**HANGUP / RESUME**: When a function "HANGS UP" this means that it returns an
Copy link
Collaborator

@ethouris ethouris Sep 1, 2020

Choose a reason for hiding this comment

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

Actually the intention of this description was to have some common abstract terms for what happens differently depending on whether the function works in blocking and non-blocking mode.

If the function makes a "HANGUP", it means that:

  • in blocking mode, the call will block until the condition no longer applies
  • in non-blocking mode, the call will end up with appropriate "again" error (as enumerated below)

If the function makes a "RESUME", it means that it has done something it was intended to do, and in blocking mode it exits at all. In case of non-blocking mode it would exit immediately anyway, but in this case with success.

I think better would be to describe these terms both at one for particular mode (separately for blocking and non-blocking), for example:

The terms of HANGUP and RESUME resolve differently depending on the blocking state.

In blocking mode:

  • HANGUP means that the function execution is stalled (blocking)
  • RESUME means that the function exits - with either success or operation failure code

In non-blocking mode the function always exits immediately, with only a different result:

  • HANGUP means that the function exits with the "again"-type error (such as SRT_EASYNC*, SRT_ETIMEOUT or SRT_ECONGEST, as specified in its description).
  • RESUME means that the function, when called, exits with either success or an operation failure

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How about this:

HANGUP: When a function "HANGS UP" this means that:

  • In blocking mode the call will block until the condition no longer applies.
  • In non-blocking mode the call will end up with appropriate error. It returns
    an error from the MJ_AGAIN category (see SRT_EASYNC*, SRT_ETIMEOUT and
    SRT_ECONGEST symbols from the SRT_ERRNO enumeration type.

RESUME: When a function "RESUMES" this means that:

  • In blocking the function has done something it was intended to do and exits.
  • In non-blocking the function has done something and returned a non-error
    status. It would exit immediately anyway, but in this case successfully.

Note that blocking mode in SRT is separate for sending and receiving, and is set
by the SRTO_SNDSYN and SRTO_RCVSYN options respectively.

Copy link
Collaborator

@ethouris ethouris Sep 2, 2020

Choose a reason for hiding this comment

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

Not sure how clear the "condition" statement is. I'd rather speak about "readiness".

HANGUP is when the function is not ready to perform the operation. In blocking mode it will block, in non-blocking mode will return an error as per this list.

RESUME is when the function is (or better: becomes) ready to perform the operation and it performs it. In both modes the same way.

These terms are intended to be used in the further description by stating under which condition the function is ready, so it HANGS UP if not, and RESUMES if it is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Terminology

The following terms are used in the description of transmission types:

HANGUP: When a function "HANGS UP" this means that it is not ready to perform
an operation:

  • In blocking mode the call will block until the condition no longer applies.
  • In non-blocking mode the call will return the appropriate error from the
    MJ_AGAIN category (see SRT_EASYNC*, SRT_ETIMEOUT and SRT_ECONGEST
    symbols from the SRT_ERRNO enumeration type.

RESUME: When a function "RESUMES" this means that it has become ready to perform
an operation:

  • In blocking mode the function has done something it was intended to do and exits.
  • In non-blocking mode the function has done something and returned a non-error
    status. It would exit immediately anyway, but in this case successfully.

In the descriptions further below, these terms denote the readiness of a function
under certain conditions. Note that blocking mode in SRT is separate for sending
and receiving, and is set by the SRTO_SNDSYN and SRTO_RCVSYN options respectively.

docs/API.md Outdated

- **TTL** defines how much time (in ms) the message should wait in the sending
buffer for the opportunity to be picked up by the sender thread and sent over
the network; otherwise it is dropped.
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's one thing nonprecise here: The packet is ALWAYS sent for the first time. The TTL parameter sets only a time tolerance for a case when the packet was lost and had to be retransmitted. After that time the retransmission is given up, and if the receiver peer still requests this retransmission, it will be denied by DROPREQ message. I don't think it should be described here in such details, but it should be clearly stated that TTL does not concern regular first-time sending of the packet - which is always done regardless of any conditions - but only if any of the packets carrying this message were lost.

bursts sent at the moment when an idle link is activated.

- Smaller values of this option respect low latency requirements very
well, may cause overreaction on even slightly stretched response times. This is
Copy link
Collaborator

Choose a reason for hiding this comment

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

As the second part of this sentence is a drawback warning and contradicts the first part of the sentence being an advantage announcement, I think the second part definitely deserves some "however" or "unfortunately".

Copy link
Collaborator

@ethouris ethouris left a comment

Choose a reason for hiding this comment

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

Done review, please consider the above.

docs/API.md Outdated Show resolved Hide resolved
docs/API.md Outdated Show resolved Hide resolved
docs/API.md Outdated Show resolved Hide resolved
Co-authored-by: stevomatthews <smatthews@haivision.com>
Copy link
Collaborator Author

@stevomatthews stevomatthews left a comment

Choose a reason for hiding this comment

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

Addressed comments from @ethouris

and receiving. For example, SNDSYN defines blocking for `srt_connect` and
RCVSYN defines blocking for `srt_accept`. The SNDSYN also makes `srt_close`
and receiving. For example, `SNDSYN` defines blocking for `srt_connect` and
`RCVSYN` defines blocking for `srt_accept`. The `SNDSYN` also makes `srt_close`
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How about this?

and receiving. For example, SNDSYN defines blocking for `srt_connect` and
RCVSYN defines blocking for `srt_accept`. The SNDSYN also makes `srt_close`
and receiving. For example, `SNDSYN` defines blocking for `srt_connect` and
`RCVSYN` defines blocking for `srt_accept`. The `SNDSYN` also makes `srt_close`
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Blocking and Non-blocking Mode

SRT functions can also work in blocking and non-blocking modes, for which
there are two separate options for sending and receiving: SRTO_SNDSYN and
SRTO_RCVSYN. When blocking mode is used, a function will not exit until
the availability condition is satisfied. In non-blocking mode the function
always exits immediately, and if enough resources are not available it
returns an error with an appropriate code. The use of non-blocking mode usually
requires using some polling mechanism, which in SRT is EPoll.

Note also that blocking and non-blocking modes apply not only to sending and
receiving. For example, to make srt_connect run asynchronously (blocking mode),
set SRTO_RCVSYN to false on the socket used for connecting (the SRT_EPOLL_OUT
readiness should be checked here). To make srt_accept run asynchronously (blocking
mode), set SRTO_RCVSYN to false on the listener socket (the SRT_EPOLL_IN readiness
should be checked here). Setting SRTO_SNDSYN to true on the socket makes srt_close
exit only after the sending buffer is completely empty.

docs/API.md Outdated

The following terms are used in the description of transmission types:

**HANGUP / RESUME**: When a function "HANGS UP" this means that it returns an
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How about this:

HANGUP: When a function "HANGS UP" this means that:

  • In blocking mode the call will block until the condition no longer applies.
  • In non-blocking mode the call will end up with appropriate error. It returns
    an error from the MJ_AGAIN category (see SRT_EASYNC*, SRT_ETIMEOUT and
    SRT_ECONGEST symbols from the SRT_ERRNO enumeration type.

RESUME: When a function "RESUMES" this means that:

  • In blocking the function has done something it was intended to do and exits.
  • In non-blocking the function has done something and returned a non-error
    status. It would exit immediately anyway, but in this case successfully.

Note that blocking mode in SRT is separate for sending and receiving, and is set
by the SRTO_SNDSYN and SRTO_RCVSYN options respectively.

docs/API.md Outdated Show resolved Hide resolved
Co-authored-by: stevomatthews <smatthews@haivision.com>
Copy link
Collaborator Author

@stevomatthews stevomatthews left a comment

Choose a reason for hiding this comment

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

More changes in response to comments from @ethouris

docs/API.md Outdated Show resolved Hide resolved
docs/API.md Outdated Show resolved Hide resolved
Copy link
Collaborator Author

@stevomatthews stevomatthews left a comment

Choose a reason for hiding this comment

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

Minor edits.

ethouris and others added 2 commits September 3, 2020 17:57
Co-authored-by: stevomatthews <smatthews@haivision.com>
Co-authored-by: stevomatthews <smatthews@haivision.com>
Comment on lines +1227 to +1234
- *TODO: This option weirdly only allows the socket used in **bind()** to use the
local address that another socket is already using, but not to disallow another
socket in the same application to use the binding address that the current
socket is already using. What it actually changes is that when given an address in
**bind()** is already used by another socket, this option will make the binding
fail instead of adding the socket to the shared group of that socket that
already has bound this address - but it will not disallow another socket to reuse
its address.*
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
- *TODO: This option weirdly only allows the socket used in **bind()** to use the
local address that another socket is already using, but not to disallow another
socket in the same application to use the binding address that the current
socket is already using. What it actually changes is that when given an address in
**bind()** is already used by another socket, this option will make the binding
fail instead of adding the socket to the shared group of that socket that
already has bound this address - but it will not disallow another socket to reuse
its address.*

Copy link
Collaborator Author

@stevomatthews stevomatthews left a comment

Choose a reason for hiding this comment

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

Minor edits

@maxsharabayko maxsharabayko merged commit 4ee1780 into Haivision:master Sep 4, 2020
@mbakholdina mbakholdina modified the milestones: v1.5.0 - Sprint 22, v1.4.2 Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[docs] Area: Improvements or additions to documentation Type: Maintenance Work required to maintain or clean up the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[docs] Move socket options from API.md to a separate document
4 participants