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

  • SEARCH
  • Home
  • 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 8932085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:15:44+00:00 2026-06-15T09:15:44+00:00

If the application can ensure that there would always be space in the socket’s

  • 0

If the application can ensure that there would always be space in the socket’s send buffer, would blocking and non blocking send have same performance? In this scenario, is there any advantages in either approach over the other?

  • 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-06-15T09:15:45+00:00Added an answer on June 15, 2026 at 9:15 am

    The only difference between blocking and non-blocking send is whether the kernel puts your process to sleep or returns EWOULDBLOCK. So in terms of performance, there should be no difference.

    However, I doubt your implicit assumption that the send cannot block just because the send buffer has free space. Imagine an idle socket on a system that places heavy demands on memory. I would not necessarily expect the kernel to “pin” the physical pages for your send buffer; I would expect it to use that memory for something useful instead. And then when you try to send, the kernel will need to grab a free page for the send buffer; and if there are no such pages available, it might decide to return EWOULDBLOCK instead of waiting on (say) swap.

    Now, that is a lot of “maybes” and “mights”, and someone more familiar with the kernel’s internals could tell me I am wrong. But even if Linux does not behave this way today, it might tomorrow; and are you 100% sure you will never run your application on anything other than Linux, ever?

    So I would not write my application with such a fragile assumption. I suggest you decide whether blocking or non-blocking semantics make more sense for your own code, and do not try to game the kernel’s internals.

    [Update]

    I was hoping I would not have to dig in to Linux internals, but an overconfident downvoter has driven me to it.

    Start with net/ipv4/tcp.c at the “new_segment” label:

    new_segment:
    if (!sk_stream_memory_free(sk))
        goto wait_for_sndbuf;
    
    skb = sk_stream_alloc_skb(sk, 0, sk->sk_allocation);
    if (!skb)
        goto wait_for_memory;
    

    See how “wait_for_sndbuf” is distinct from “wait_for_memory”? That is what I am talking about.

    At the “wait_for_memory” label, there is a call to sk_stream_wait_memory with a timeo value that depends on whether this is a non-blocking send. That function, in turn, either puts the process to sleep or returns EAGAIN depending on timeo.

    [Update 2]

    Just to be clear what question I am answering…

    I interpret this question to be, “If I know that my socket’s send buffer has sufficient free space, is there any difference — performance or otherwise — between a blocking and a non-blocking send on that socket?”

    The premise is certainly possible if, for example, your protocol is to send one message, and then only send a new message after receiving a reply to a previous message. In this case, you know the send buffer is always empty when you send. By getting and/or setting the POSIX-standard SO_SNDBUF socket option, you can know that your socket has adequate free space. In this case, can a blocking send behave differently from a non-blocking send?

    My reading of the POSIX spec says “yes” in principle. My reading of the Linux source code says “yes” in practice. I could certainly be wrong, but it would take someone more knowledgeable about POSIX or Linux to demonstrate it, and none of them have answered this question so far.

    [Final (?) update]

    Here is what I believe POSIX allows/requires you to assume.

    If there is adequate free space in the send buffer, then a blocking send cannot block forever. This is the same sense in which a call to calloc with adequate free virtual memory cannot block forever. Eventually the system will find the resources it needs to send your data.

    (Note the same is not true when the send buffer is full, in which case a blocking send might block forever depending on what is happening at the receiving end of the socket.)

    However, even when there is adequate space in the send buffer, a non-blocking send might still return EWOULDBLOCK. So if you use non-blocking sockets, your code must handle this regardless of what you know about the send buffer or anything else.

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

Sidebar

Related Questions

I would like to have a layered window that is always-on-top, which I can
How can I ensure that the hower preview of my WPF application (.net 4)
I have an issue that people can't work with an intranet application that is
i have invoked blackberry calender from my application can anyone tell me how to
Hi I have a situation where my application can be used for different purposes
In C++, a console application can have a message handler in its WinMain procedure,
What strategies should be employed to ensure that JVM memory management is always quick?
I have an application which uses SslStream to send and receive data with its
We have a Silverlight application that shows text over video. Both the text and
I have a custom Windows controls that superclass standard ones. I would like my

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.