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

The Archive Base Latest Questions

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

I wrote a small TCP servers with socket() + POLLIN poll() + recv() +

  • 0

I wrote a small TCP servers with socket() + POLLIN poll() + recv() + send(), but I don’t know when to use POLLOUT poll or select writefds to poll on writable event.

Can anyone give me an example of the real usage of POLLOUT?

  • 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-10T10:59:28+00:00Added an answer on June 10, 2026 at 10:59 am

    The usual pattern is to use non-blocking file descriptors with poll() like this:

    • When getting ready to poll(),
      • Always set POLLIN because you are always interested in reading what the other end of the socket has send you.
        • Except if you have a large backlog of incoming data and you intentionally want to make the other end wait before sending more.
      • Set POLLOUT only if you have outstanding data to send to the other end.
    • Upon return from poll(), if it indicates that data is available to read,
      • read it and do something with it
    • Upon return from poll(), if it indicates that the socket is writable,
      • Try sending your outstanding data.
        • If you managed to write all of it, you’re not going to set POLLOUT next time through the loop
        • If you only managed to send some of it (or none of it) then keep the rest for later. You will set POLLOUT the next time through the loop.
    • When you have new data to send (either in response to data you read or in response to some external event), you have two choices:
      • Eagerly try to send some of it right away. You may successfully send none, some, or all of it. Just like with the previous case, keep the portion of the data that wasn’t written for next time and plan to set POLLOUT the next time through the loop only if there was some data left.
      • Just keep a hold on the data and plan to set POLLOUT the next time through the loop. (This choice is often easier to program because you only need to handle writing data in one place in your loop but on the other hand it delays writing the data until the next time through the loop.)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote two small java programs: a TCP client which sends many lines of
I wrote a small express.js based web app. I serve a manifest.webapp but express.js
I wrote some small apps using .NET 3.5 but now I am stuck with
I wrote a small tcp client using boost::asio, providing the following function: typedef boost::function<void(const
I am attempted to write a small asynchronous socket library that I can use
I have just started to learn twisted and wrote a small tcp server/client using
I am new to jquery . I wrote small piece of code <div id=tablediv><table><tr><td><h2>Select
I wrote two small applications (a client and a server) to test UDP communication
I wrote a small test program for flipperview. I have 3 views. I call
I wrote a small internal web app using (a subset of) pylons . As

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.