Skip to content

Socket.EndSend reference doc inaccuracy #1701

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

Open
ghogen opened this issue Mar 14, 2018 · 5 comments
Open

Socket.EndSend reference doc inaccuracy #1701

ghogen opened this issue Mar 14, 2018 · 5 comments
Labels
area-System.Net doc-bug Problem with the content; needs to be fixed dotnet-api/prod Pri1 Indicates issues/PRs that are high priority
Milestone

Comments

@ghogen
Copy link
Contributor

ghogen commented Mar 14, 2018

This issue was reported by a .NET user a while ago via a different channel:

Hi alll, no authoritative response has been given on this in several discussions in the past, so I decided to report this as a documentation bug, because there is an obvious conflict in the documentation of the Socket.BeginSend and Socket.EndSend methods even in the latest .NET framework version. MSDN says in Socket.BeginSend: "When your application calls BeginSend, the system will use a separate thread to execute the specified callback method, and will block on EndSend until the Socket sends the number of bytes requested or throws an exception." From this sentence I infer, that BeginSend queues ALL data for sending or there will be an exception. But let's have a look what MSDN says in Socket.EndSend: "If you are using a connection-oriented protocol, EndSend will block until some of the buffer was sent. If the return value from EndSend indicates that the buffer was not completely sent, call the BeginSend method again, modifying the buffer to hold the unsent data." This sentence says, that EndSend might succeed even with less bytes sent than requested for connection-oriented protocols. Since it is realy important to know what the real behaviour of these methods is, the documentation should be fixed (or clariefied) to make this very old problem finally clear. According to our tests EndSend never returns less bytes than requested when it succeeds even for very large (MB) sents. So can you please explain to the public the behaviour of these two methods? Does it play a role if the socket is set to nonblocking? Thank you very much. Alex


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@mairaw
Copy link
Contributor

mairaw commented Mar 14, 2018

@davidsh
Copy link
Contributor

davidsh commented Mar 14, 2018

cc: @stephentoub @rmkerr @karelz

@mairaw
Copy link
Contributor

mairaw commented Jun 19, 2018

@stephentoub @rmkerr @karelz can one of you comment on this? Thanks!

@rmkerr
Copy link
Contributor

rmkerr commented Jun 19, 2018

There definitely is some conflicting info here. From the BeginSend docs:

When your application calls BeginSend, the system will use a separate thread to execute the specified callback method, and will block on EndSend until the Socket sends the number of bytes requested or throws an exception.

And from the EndSend docs:

If you are using a connection-oriented protocol, EndSend will block until some of the buffer was sent. If the return value from EndSend indicates that the buffer was not completely sent, call the BeginSend method again, modifying the buffer to hold the unsent data.

Unless someone else already knows the answer, I'll take a look at the code and see if I can find out what info is correct.

@rmkerr
Copy link
Contributor

rmkerr commented Jun 19, 2018

The EndSend docs are the correct ones. BeginSend is implemented using the WSASend function, which provides the following explanation (source):

If the socket is non-blocking and stream-oriented, and there is not sufficient space in the transport's buffer, WSASend will return with only part of the application's buffers having been consumed.

I'm not sure of the exact buffer sizes required to trigger this behavior, but it does appear to be possible. We should update the BeginSend docs to reflect the actual behavior, since there does seem to be some confusion around this issue.

@dotnet-bot dotnet-bot added the untriaged New issue has not been triaged by the area owner label Jan 26, 2019
@mairaw mairaw transferred this issue from dotnet/docs Jan 26, 2019
@mairaw mairaw added Pri1 Indicates issues/PRs that are high priority doc-bug Problem with the content; needs to be fixed and removed untriaged New issue has not been triaged by the area owner labels Jan 26, 2019
@mairaw mairaw added this to the Backlog milestone Jan 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Net doc-bug Problem with the content; needs to be fixed dotnet-api/prod Pri1 Indicates issues/PRs that are high priority
Projects
None yet
Development

No branches or pull requests

8 participants