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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:17:39+00:00 2026-05-30T18:17:39+00:00

The server that Im working on (which is a Unix C multi-threaded non-block socket

  • 0

The server that Im working on (which is a Unix C multi-threaded non-block socket server) need to receive a file from a client and broadcast it to all the other clients connected to the server.

Everything is working at the exception that Im having a hard time to determine when a file is done transferring… since Im using non-block socket Im having the issue that sometimes during the file transfer recv return -1 (which I was assuming was the end of the file) then the next pass more bytes comes in.

I try to hack the whole thing putting “END” at the end of the stream. However, sometimes when multiple files are sent in a row the “END” is part of the same recv buffer as the beginning of the next file. Or even worst, sometimes I end up with a buffer that finish with EN and the next pass the D comes in.

What would be the best approach to avoid the situations mentioned above, I don’t really want that each time I receive some bytes from the socket loop the whole accumulated buffer to check if “END” is part of it then cut appropriately… Im sure there’s a better solution to this right?

Thanks in advance!

  • 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-30T18:17:41+00:00Added an answer on May 30, 2026 at 6:17 pm

    The most simpe case EJP is referring to, the case where you take the closing of the socket by the other end as end-of-file, could look like the following:

    {
      ssize_t sizeRead = 0;
    
      while (sizeRead = recv(...)) {
        if (0 > sizeRead) { /* recv() failed */
          if ((EGAGAIN == errno) ¦¦ (EWOULDBLOCK == errno)) { /* retry the recv() on those two kinds of error */
            usleep(1) /* optional */
            continue;
          }
          else
            break;
        }
    
        ... /* process the data read ... */
      }
    
      if (0 > sizeRead) {
        /* There had been an error during recv() */
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a product that runs an SQL server which allows some
I have been working on designing a file server that could take the load
I am working on a client-server application that uses boost::serialization library for it's serialization
I am working on a website which is hosted on a server that has
I'm downloading a perl CGI file from a Linux web server. It has Unix
I host a small development server on my system. From that working directory I
I am working on a Customer Server Control that extends another control. There is
I'm working with a SQL Server DB that's got tables spread across multiple schemas
I'm working with a OPC Server control that stores data tags as variant types,
I'm working on an email solution in SQL Server ONLY that will use Database

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.