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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:32:45+00:00 2026-05-11T18:32:45+00:00

If I got a file descriptor (socket fd), how to check this fd is

  • 0

If I got a file descriptor (socket fd), how to check this fd is avaiable for read/write?
In my situation, the client has connected to server and we know the fd.
However, the server will disconnect the socket, are there any clues to check it ?

  • 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-11T18:32:45+00:00Added an answer on May 11, 2026 at 6:32 pm

    You want fcntl() to check for read/write settings on the fd:

    #include <unistd.h>
    #include <fcntl.h>
    
    int    r;
    
    r = fcntl(fd, F_GETFL);
    if (r == -1)
            /* Error */
    if (r & O_RDONLY)
        /* Read Only */
    else if (r & O_WRONLY)
        /* Write Only */
    else if (r & O_RDWR)
        /* Read/Write */
    

    But this is a separate issue from when the socket is no longer connected. If you are already using select() or poll() then you’re almost there. poll() will return status nicely if you specify POLLERR in events and check for it in revents.

    If you’re doing normal blocking I/O then just handle the read/write errors as they come in and recover gracefully.

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

Sidebar

Related Questions

on master file got ... <div id=nav-main> <asp:Menu ID=Menu1 runat=server DataSourceID=SiteMapDataSource1 Orientation=Horizontal Width=573px CssClass=menu-main
I got some file sample.mt from client, and when i open info, it reveals
I've got a file (test.txt) which contains 1234567. However when I try to read
I am read from a file like this: #include <stdio.h> int main() { FILE
I've got an assignment to write a server program that accepts multiple clients. I'm
My problem is that using ifstream read and fread on a file descriptor don't
If I know that input to my program will come from a file descriptor
I've got an API that is called with a file descriptor as an argument,
I got a descriptor for a TCP socket in the following manner : int
Given this stack trace snippet Caused by: java.net.SocketException: Software caused connection abort: socket write

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.