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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:03:59+00:00 2026-06-10T11:03:59+00:00

I’ve run into a rather strange problem: I use select() in order to determine

  • 0

I’ve run into a rather strange problem:

I use select() in order to determine if a socket becomes readable. However, whenever a client connects, I get a segfault when I call FD_ISSET() to check if a given socket is present in the fd_set.

/* [...] */

while( /* condition */ ){

    timeout.tv_sec = 0;
    timeout.tv_usec = SELECT_TIMEOUT;

    //this simply fills sockets with some file descriptors (passed in by clients - both parameters are passed by reference)
    maxfd = this->build_fd_set( clients, sockets );

    //wait until something relevant happens
    readableCount = select( maxfd + 1, &sockets, (fd_set*)NULL, (fd_set*)NULL, &timeout );

    if( readableCount > 0 ){
        //Some sockets have become readable

         printf( "\nreadable: %d, sockfd: %d, maxfd: %d\n",
                readableCount, this->sockfd, maxfd );

        //Check if listening socket has pending connections
        // SEGFAULT OCCURS HERE
        if( FD_ISSET( this->sockfd, &sockets ) ) {

            DBG printf( "new connection incoming" );

            this->handle_new_connection( clients );

            /* [...] */
        }else {
            // Data is pending on some socket
            /* [...] */
        }
    }else if( readableCount < 0 ) {
        //An error occured
        /* [...] */
        return;
    }else {
        // select has timed out
        /* [...] */
    }

}

EDIT:
Yeah, sorry for the sparse info: I’ve updated the code.

this->sock_fd is set up to be a descriptor for a listening socket, created usingthis->sockfd = socket( AF_UNIX, SOCK_STREAM, 0 ); and then made listening via listen( this->sockfd, ACCEPT_BACKLOG ).

build_fd_set:

int SvcServer::build_fd_set( const vector<int>& clients, fd_set& sockets ) {

    //build up the socket set
    FD_ZERO( &sockets );
    FD_SET( this->sockfd, &sockets ); //listening socket is always part of the set

    int maxfd = this->sockfd;
    //Add all currently connected sockets to the list
    for( vector<int>::const_iterator it = clients.begin() ; it != clients.end() ; ++it )     {
        FD_SET( *it, &sockets );
        maxfd = max( maxfd, *it );
    }

    return maxfd;
}

It really doesn’t matter what clients is, it’ just empty and meant to be filled once clients connect, which is not happening since the whole thing segfaults on the first incoming connection.

Also, here’s some sample output:

readable: 1, sockfd: 3, maxfd: 3
Segmentation fault

The things I can derive here are:

  • The call to select() works, readable is set correctly
  • Also sockfd and maxfd are valid descriptors.

I’m afraid I can’t provide you with any debugging info (e.g. gdb) since I’m cross compiling and gdb is not available on the platform I’m compiling to.

  • 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-10T11:04:01+00:00Added an answer on June 10, 2026 at 11:04 am

    Nevermind, I figured it out. * stupid me *

    Turns out, the segfault was never actually occuring at the suspected position, the last printf before the segfault never got shown because it stdout wasn’t flushed. The actual segfault occured a little later and was (of course) my mistake.

    thx nevertheless

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I would like to run a str_replace or preg_replace which looks for certain words
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.