Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4108954
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:43:41+00:00 2026-05-20T21:43:41+00:00

I have read the documentation at least 10 times now and have also read

  • 0

I have read the documentation at least 10 times now and have also read some 10 or so code snippets and full programs where non-blocking sockets are used for sending data. The problem is that some of the tutorials are either for beginners (Beejs f.i.) or are pretty sloppy in their assumptions; and those that are not are complicated are specialized code examples that don’t explain why they do what they do. Even SO knowledge base doesn’t exhaustively cover the entire gamut of send behavior, in my opinion. What I am after are details on f.e:

  • What does return code of 0 indicate exactly, and is it worth checking errno then or should one just discard the connection without further investigation?
  • Does getting a negative return value warrant closing a connection gone bad, or is it only so unless errno is EWOULDBLOCK, EAGAIN or EINTR (…others) ?
  • Is it worth checking errno when return value is > 0? Apparently, the value indicates amount of data “sent” (in quotes because it’s a long process really, right), but since the socket is non-blocking, does it mean one can issue another call right away, or, depending on errno again, one should wait for the next sending occasion (using select/poll/epoll) ?
  • Basically, does one check the return value first and only then the errno value? Or maybe send sets errno on each call, return value regardless? That would make error checking somewhat easier…
  • If one gets EINTR, what would be a good, robust behavior for a program to take? Simply record the state and retry on next send occasion, like with EWOULDBLOCK and EAGAIN?
  • Does one check for both EWOULDBLOCK and EAGAIN? Can we trust both having the same value, or does it depend on the implementation?
  • Does send return EMSGSIZE for stream sockets? If it doesn’t, then no buffer size is too big, right?
  • Can return value itself be equal to either of the known error codes?

If you could provide an example of robust non-blocking send code, it would be absolutely appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T21:43:42+00:00Added an answer on May 20, 2026 at 9:43 pm

    A lot of questions here:

    • What does return code of 0 indicate exactly, and is it worth checking errno then or should one just discard the connection without further investigation?

    On a POSIX system, send(2) can never return 0 unless you call it with a length arg of 0. Check the docs for your specific system to make sure it follows the POSIX spec

    • Does getting a negative return value warrant closing a connection gone bad, or is it only so unless errno is EWOULDBLOCK, EAGAIN or EINTR (…others) ?

    No, a -1 return value (the only possible negative return value) just means that no data was sent. You need to check errno to see WHY — see the send(2) man page for a full listing of all the possible errno value and what they mean

    • Is it worth checking errno when return value is > 0 ? Apparently, the value indicates amount of data “sent” (in quotes because it’s a long process really, right), but since the socket is non-blocking, does it mean one can issue another call right away, or, depending on errno again, one should wait for the next sending occasion (using select/poll/epoll) ?

    If send returns success (> 0), then errno will be unchanged and will contain whatever it had before (which is probably an error from some earlier system call).

    • Basically, does one check the return value first and only then the errno value? Or maybe send sets errno on each call, return value regardless? That would make error checking somewhat easier…

    Check the return value first and then errno if the return value is -1. If you really want to, you can set errno to 0 before the call and then check it afterwards

    • If one gets EINTR, what would be a good, robust behavior for a program to take? Simply record the state and retry on next send occasion, like with EWOULDBLOCK and EAGAIN?

    Well, the simplest is to disable interruption of system calls, in which case you’ll never get an EINTR. Treating it the same as EWOULDBLOCK/EAGAIN is good too.

    • Does one check for both EWOULDBLOCK and EAGAIN? Can we trust both having the same value, or does it depend on the implementation?

    Depends on the implementation, though generally they’re the same. Sometimes there’s weirdness with SysV vs BSD emulation modes that might make them different and either might occur

    • Does send return EMSGSIZE for stream sockets? If it doesn’t, then no buffer size is too big, right?

    Stream sockets don’t have atomic messages and EMSGSIZE is only for atomic messages, so no, stream sockets can’t return EMSGSIZE

    • Can return value itself be equal to either of the known error codes?

    The only error code is -1. Success is the number of bytes written, so if you could write 2^32-1 bytes on a 32-bit machine (or 2^64-1 on a 64 bit machine), it would be a problem, but you can’t write that many bytes (and you’ll generally get a EINVAL or EFAULT if you try).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read documentation for functions such as values and define-values that return and
I have read the documentation and searched all over but I can't find how
I have read the documentation that states that "given the type of the enum,
I have read the documentation ( http://dev.mysql.com/doc/refman/5.1/en/partitioning.html ), but I would like, in your
I am trying to present a modal view controller. I have read the documentation,
I have read the Apple documentation, and many postings on the subject on SO,
I have read the FactoryGirl documentation, but I can't seem to figure this out.
I have read all the documentation I found on how to integrate Unity3D projects
I do not fully understand classes. I have read the python documentation and several
Ok, I'm programming in objective-C and using Xcode. I have read through the documentation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.