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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:47:53+00:00 2026-05-22T17:47:53+00:00

Using the C sockets library on a Linux system… When I make a call

  • 0

Using the C sockets library on a Linux system…

When I make a call to accept( ) it always returns an integer. STDIN is 0. Usually my first accept call returns 3. They increment after that.

I was wondering; how does accept( ) determine which integer is next? If, after 2 more accept( ) calls, I have 3, 4, and 5 assigned to connected clients; what happens when 4 disconnects? Is the next integer 4 or is it 6?

If someone could shed some light on this I sure would appreciate 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-22T17:47:54+00:00Added an answer on May 22, 2026 at 5:47 pm

    It uses the next currently unopen file descriptor, the same as open() and other system calls that return file descriptors; dup2() is something of an exception to the pattern. (A file descriptor might not be open but might still be unavailable for reuse if it was part of a network connection that has not been completely cleaned up yet, for example.) (Update: struck out text reinstates original version of answer. If a file descriptor is closed, it is available for reuse. There might be issues with reusing a socket address because of FIN-WAIT states in TCP/IP – but a socket address is not the file descriptor.)

    If you have descriptors 1-5 open, then close 4, the next open-like operation will return 4.

    There might be security-conscious systems where this is not the pattern, but it is unlikely. One reason is that there is correct code for handling I/O redirection that relies on closing standard input (file descriptor 0) and the next open-like operation reusing the file descriptor; repeat for standard output (file descriptor 1).

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

Sidebar

Related Questions

I am implementing a small library to make the use of System.Net.Sockets.Socket easier. It
I'm using C#.Net and the Socket class from the System.Net.Sockets namespace. I'm using the
When I create a socket using accept() and make a FILE out of it
I would like to implement a client-server architecture running on Linux using sockets and
I'm working on a library that is currently using standard tcp sockets. An end
I'm using C# .net library System.Speech to implement my ASR app ( BTW, I've
From http://msdn.microsoft.com/en-us/library/bbx2eya8.aspx it looks like, that this type of sockets are using more than
I am using boost::asio to make a socket network. The library has a number
I wrote two simple programs server and a client using sockets in C++ (Linux).
I'm using sockets to read all incoming SMS : `smsAddr.SetTextMatch(KNullDesC8);` The ones that belong

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.