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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:58:20+00:00 2026-05-24T19:58:20+00:00

I’m trying to find better methods to handle the events of a polled socket

  • 0

I’m trying to find better methods to handle the events of a polled socket (fd). I’m stuck on this to exploit the poll() function with a different pollfd like this:

#define out std::cout
#define el std::endl
#define line(string) out<<string<<el
class int_t
{
    private:
        int _int;
        int _owner;
    public:
        operator int() const;
        int_t();
        int_t(const int& in);
        int_t& operator=(const int& in);
        int_t operator|(const int& in) const;
        int_t operator&(const int& in) const;
        /*
        ...
        ...
        */
        void setowner(const int& fd);
        ~int_t();
};
int_t::operator int() const
{
    return this->_int;
}
int_t::int_t()
{
    this->_int = 0;
    this->_owner = 0;
}
int_t::int_t(const int& in)
{
    this->_int = in;
    this->_owner = 0;
}
int_t& int_t::operator=(const int& in)
{
    line("operator '=' called"<<" owner:"<<this->_owner);
    this->_int = in;
    return *this;
}
int_t int_t::operator|(const int& in) const
{
    line("operator '|' called"<<" owner:"<<this->_owner);
    return (this->_int|in);
}
int_t int_t::operator&(const int& in) const
{
    line("operator '&' with arg called"<<" owner:"<<this->_owner);
    return (this->_int&in);
}
/*
...
...
*/
void int_t::setowner(const int& fd)
{
    this->_owner = fd;
}
int_t::~int_t()
{
    this->_int = 0;
}
struct pollfd_other
{
    // Valgrind returns me an error when i changing the type of the `revent` only
    // but when i changing the type of the `event` and `revent` works without error
    // and `poll()` gets the flags normally from the `event` if ill put for example
    // a `POLLIN` flag.
    int fd;
    int_t events;
    int_t revents;
    void setowner(const int& pollfdowner){
        this->fd = pollfdowner;
        this->revents.setowner(pollfdowner);
    } 
};
int main(int argc,char* argv[])
{
    Server server;
    pollfd_other pfd[1];
    pfd[0].setowner(server.socket);
    ::poll(reinterpret_cast<pollfd*>(&pfd),1,-1);
    // ...
}

The class int_t works very well as an integer and struct pollfd_other … but the poll() doesn’t access it like a class to invoke the operators …

The purpose of this is to create a thread when an operator will be invoked on the revents member of the struct pollfd_other.

There is any other method to do something like this? Suggestions are welcomed …

  • 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-24T19:58:21+00:00Added an answer on May 24, 2026 at 7:58 pm

    That looks very convoluted. If you want to encapsulate the poll functionality in an object, don’t encapsulate an int, encapsulate the poll. Something like this:

    class poller_callback {
        public:
            void handle_pollin(int fd) = 0;
    };
    
    class poller {
        public:
            poller(const vector<int>& fds);
            void do_poll(const poller_callback& c)
            {
                // poll(&pfd, ...);
                if(fd[i].revents & POLLIN) {
                    c.handle_pollin(fd[i].fd);
                }
            }
    };
    
    int main(void)
    {
        my_poller_callback my_handler;
        // get fds
        poller my_poller(fds);
        do_poll(my_handler);
        // ...
        return 0;
    }
    

    This is how I’d do it. Have a class that encapsulates poll(), which is parameterized on what it should do on events. poller_callback is an interface for objects that handle events. You can then write my_poller_callback which, in its handle_pollin, creates the thread.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.