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 8881033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:15:59+00:00 2026-06-14T20:15:59+00:00

I am writing a small program to test network throughput as part of an

  • 0

I am writing a small program to test network throughput as part of an exercise and need to increase the sending and receiving buffers to 256 KB (to try and boost TCP performance). I am doing this with setsockopt() and the SO_SNDBUF/SO_RCVBUF options and have also increased the ‘net.core.rmem_max’ and ‘net.core.wmem_max’ values.

The getsockopt() confirms the increase in the buffer sizes (double the 256KB value) so I know this is fine. However when I send 256KB of data from one host to another the receiver is always receiving it in several reads each of varying size (form somewhere between 20 to 40 reads ranging in number of received bytes form 1448 to 18824) until it receives all the data. I pretty confused at this point mainly with these questions,

  1. With the increased buffer size shouldn’t it receive it in one read?
  2. Also why do the amount of bytes in each read differ so much (shouldnt they be more of less constant)?
  3. Is there some way to ensure the 256KB is received in one read?

Below is the receiver side snippet showing the read part,

  while(1) {
    memset(&client_addr, 0, sizeof(client_addr));
    if ((connfd = accept(listenfd, (struct sockaddr*)&client_addr, &socklen)) <= 0) {
      perror("accept()");
      exit(EXIT_FAILURE);
    }

    while ((n = recv(connfd, &buff[0], BUFF_SIZE, 0/*MSG_WAITALL*/)) > 0) {
      totalBytes += n;
      ++pktCount;
      printf("Received(%d): %d bytes\n", pktCount, n);
    }

    if (n == 0) {
      printf("Connection closed (Total: %lu bytes received)\n", totalBytes);
    }

    close(connfd);
    connfd = -1;
    totalBytes = 0;
    pktCount = 0;
  }

Any help would be great.

TIA

  • 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-14T20:16:01+00:00Added an answer on June 14, 2026 at 8:16 pm

    With the increased buffer size shouldn’t it receive it in one read?

    No. TCP/IP is a streaming protocol and fragments data over a smaller packets. The buffer size primarily affects how much memory an underlying network layer implementation can use (and Linux generally doubles what you have set), but there is no guarantee that receives will receive data in chunks of exactly the same size as sender was sending it (after all, when you call send()/write(), it doesn’t mean the packet was sent, actually. Also, you are most likely have your packets split anyway due to the MTU.

    Also why do the amount of bytes in each read differ so much (shouldnt they be more of less constant)?

    You may want to debug as to why this is happening. There are hundreds of factors — NIC in use, its settings, its driver, TCP/IP, TCP, Ethernet network layer settings, stuff in between sender and receiver (i.e. a switch) etc. But hey, more data comes in while your OS and the application is processing the previous chunk. Given a fact that passing data from the NIC to the user-space application is relatively very expensive, it is not surprising that data is being buffered and you get it in different sizes.

    Is there some way to ensure the 256KB is received in one read?

    There might be. One might use a blocking read() and require OS to wake up the process only upon receiving at least 256KB or if the error occurs.

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

Sidebar

Related Questions

I am writing a small program that sends and receive multicast packets.I need to
I am writing a small program that gets activated when sms is received.We need
I am writing a small test program that gives the following xml file as
I am writing a small program as part of a University course. In this
I'm learning haskell and decided to try writing some small test programs to get
I'm writing a small program to record reading progress, the data models are simple:
I am writing a small program for our local high school (pro bono). The
I am writing a small program in C++ using OpenCV-2.3 API. I have an
Today I am writing a small program in Haskell. I found that in ghci's
I am writing a small program in Visual Studio 11 (beta) that a console

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.