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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:56:32+00:00 2026-05-28T02:56:32+00:00

Assume a TCP socket on the local linux host is in a connected state

  • 0

Assume a TCP socket on the local linux host is in a connected state with a remote host. The local host is using epoll_wait to be notified of events on the socket with the remote host.

If the remote host were to call:

 shutdown(s,SHUT_WR);

on its connected socket to indicate it is done transmitting, what event(s) will epoll_wait return on the local host for its socket?

I’m assuming EPOLLIN would always get returned and a subsequent recv call would return 0 to indicate the remote side has finished tranmitting.

What about EPOLLHUP or EPOLLRDHUP? (And what is the difference between these two events)?

Or even EPOLLERR ?

If the remote host calls “close” instead of “shutdown”, does the answer to any of the above change?

  • 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-28T02:56:33+00:00Added an answer on May 28, 2026 at 2:56 am

    I’m answering this myself after doing the heavy lifting to find the answer.

    A socket listening for epoll events will typically receive an EPOLLRDHUP (in addition to EPOLLIN) event flag upon the remote peer calling close or shutdown(SHUT_WR). This does not neccessarily mean the socket is dead. Subsequent calls to recv() will return any unread data on the socket and eventually “0” will be returned to indicate EOF. It may even be possible to send data back if the remote peer only did a half-close of its socket.

    The one notable exception is if the remote peer is using the SO_LINGER option enabled on its socket with a linger value of “0”. The result of closing such a socket may result in a TCP RST getting sent instead of a FIN. From what I’ve read, a connection reset event will generate either a EPOLLHUP or EPOLLERR. (I haven’t had time to confirm, but it makes sense).

    There is some documentation to suggest there are older Linux implementations that don’t support EPOLLRDHUP, as such EPOLLHUP gets generated instead.

    And for what it is worth, in my particular case, I found that it is not too interesting to have code that special cases EPOLLHUP or EPOLLRDHUP events. Instead, just treat these events the same as EPOLLIN/EPOLLOUT and call recv() (or send() as appropriate). But pay close attention to return codes returned back from recv() and send().

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

Sidebar

Related Questions

I'm writing a program using Java non-blocking socket and TCP. I understand that TCP
Assume a legacy Linux application listening on a UNIX domain socket /tmp/foo . In
Assume the following code where sock is a handle to TCP socket that was
I'm downloading 6kB of data from a test instrument connected via TCP socket. I'm
Assume two Cassandra nodes running on hosts A and B respectively. Which TCP and/or
I'm writing a C/C++ client-server program under Linux. Assume a message m is to
I've encountered an issue when sending large segments of data through a TCP socket,
Assume I have simple protocol implemented over TCP, where each message is made up
I want to create a tcp connection to a web server using information that
Assume that, I have a TCP connection that doing heavy data transmitting on my

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.