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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:41:47+00:00 2026-06-12T04:41:47+00:00

send() shall return the number of bytes sent or error code, but all examples

  • 0

send() shall return the number of bytes sent or error code, but all examples that I found check it only with error codes, but not with the number of bytes sent.

//typical example
int cnt=send(s,query,strlen(query),0);
if (cnt < 0) return(NULL);
//Hey, what about cnt < strlen(query)?
  • 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-12T04:41:49+00:00Added an answer on June 12, 2026 at 4:41 am

    Q: Does “send()” always return the whole buffer?

    A: No, not necessarily.

    From Beej’s Guide:
    * http://beej.us/guide/bgnet/html/multi/syscalls.html#sendrecv

    send() returns the number of bytes actually sent out—this might be
    less than the number you told it to send! See, sometimes you tell it
    to send a whole gob of data and it just can’t handle it. It’ll fire
    off as much of the data as it can, and trust you to send the rest
    later. Remember, if the value returned by send() doesn’t match the
    value in len, it’s up to you to send the rest of the string. The good
    news is this: if the packet is small (less than 1K or so) it will
    probably manage to send the whole thing all in one go. Again, -1 is
    returned on error, and errno is set to the error number.

    Q: Does “recv()” always read the whole buffer?

    A: No, absolutely not. You should never assume the buffer you’ve received is “the whole message”. Or assume the message you receive is from one, single message.

    Here’s a good, short explanation. It’s for Microsoft/C#, but it’s applicable to all sockets I/O, in any language:

    • http://blogs.msdn.com/b/joncole/archive/2006/03/20/simple-message-framing-sample-for-tcp-socket.aspx
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I send 2 bytes of app data on the socket(blocking) every 10 seconds, but
I have a small script that shall redirect to another page when return is
I am trying to send an e-mail from a cron using CakePHP shell but
In Python code, I frequently send commands to the shell and read the response
My laptop has a number pad, but it does not have a NumLock key,
I have a suite of small Java app that all compiles/packages to <name-of-the-app>.jar and
I am writing a VB.NET app that has a piece which needs to send
I have a small script that I wrote to send an email out to
I'm working with gnump and have a function that must return mpz_t . So
I am writing a small app in which android device tries to send a

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.