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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:33:10+00:00 2026-06-04T05:33:10+00:00

In ubuntu 12.04, I want to write a concurrent server, which can receive http

  • 0

In ubuntu 12.04, I want to write a concurrent server, which can receive http packets from my virtual machine, then forward the packets to the original destination of my VM. But when I’m reading the packets using read function in C language, sometimes the return value and the length of buffer are not the same (for example: rbyte=1024, strlen(buf)=62 ). I’ve checked errno and find that errno=0, which means no error with the read function. I think that these two variables should be exactly the same, but for my program, they are not. The following is part of my code:

char buf[1024];
size_t rbyte = read(sFrom, buf, sizeof(buf) );
cerr << "length of buf: " << strlen(buf) << "\n";
cerr << "rbyte: " << rbyte << "\n";

I’ve read http://pubs.opengroup.org/onlinepubs/009695399/functions/read.html to get some clues, but still don’t know the reason of this error.

Does anyone know the reason?

  • 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-04T05:33:12+00:00Added an answer on June 4, 2026 at 5:33 am

    As the linked documentation states, read reads bytes, not strings, so if the input conatins a zero byte, you will get a string that is less than the number of bytes read (remember, C uses null-terminted strings), which means the first null character determines the end — and thus the length — of the string)

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

Sidebar

Related Questions

I have SBCL running on a Ubuntu machine. I want to write a little
Iam working on Ubuntu.(Linux) I want to redirect from the page one.php to two.php,
I want to install gcc-4.3 but it's not installed in Ubuntu 11.10. How can
I am working in ubuntu server 10.04 I am creating a test.h file which
I write a program that send TCP packets from localhost to localhost. And I
I want to write a programme (in python) on Linux (Ubuntu Linux 9.10) that
I want to write a program which is capable of printing out system properties.
I have a log file on the server which I want to check for
I want to write a class in C++ in which one of the parameter
I write a opengl code on ubuntu. I want to draw a text on

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.