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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:08:42+00:00 2026-06-02T16:08:42+00:00

I am calling read function to catch received packets if available. When there is

  • 0

I am calling read function to catch received packets if available. When there is no packet to get, i’m getting errno EAGAIN, but when network is disconnected I am also getting EAGAIN, so I am not able to difference both scenarios.

    while ( ((n = read(sockfd, &(buffer[pos]), 1)) > 0) and not messageFound) {

            //reading byte by byte
            if (n == 1) {
               // Some stuff.. 
            }
        }

// Never returning 0, but when returning negative values:
        if (n < 0){
            qDebug()<< "Read error #" << errno << ": " << strerror(errno);
            if(errno != EAGAIN){ // It is always this error, so it's never entering here
                qDebug()<< "Disconnected. Reason #" << errno << ": " << strerror(errno);
                *connected = false;
            }
        }

Is there any way of checking if socket has been disconnected, or know if there is some packet available before calling read? (I tried with select but doesn’t seem to work)

  • 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-02T16:08:42+00:00Added an answer on June 2, 2026 at 4:08 pm

    For POSIX sockets, the difference between closed connection and no data ready is in the return value. When a connection is closed, the return value is 0, when there is no data it has a negative value (see man page)

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

Sidebar

Related Questions

Is there any performance gain in calling C code from Objective-C? I've read somewhere
I want to read a function's name from the console, and then calling it
i'm having problems calling a delphi function from C# (attempted to read or write
So i've read around that instead of calling a event directly with if (SomeEvent
I'm calling a WebService with HttpWebRequest.Create method and read it with StreamReader, (below method
How to read strings from the MyResource.resx file from c#. I am not calling
Calling image = Image.open(data) image.thumbnail((36,36), Image.NEAREST) will maintain the aspect ratio. But I need
Calling the ajax called URL works well without ajax eg. http://localhost/ci/controller/method/param_value . But using
I noticed that calling the printf function (with cl_intel_printf extension), the same variable of
I've came into a need of calling a server-side function from a javscript function.

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.