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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:04:20+00:00 2026-05-15T05:04:20+00:00

How can I try to read data from socket with timeout? I know, select,

  • 0

How can I try to read data from socket with timeout?
I know, select, pselect, poll, has a timeout field, but using of them disables “tcp fast-path” in tcp reno stack.

The only idea I have is to use recv(fd, …, MSG_DONTWAIT) in a loop

  • 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-15T05:04:21+00:00Added an answer on May 15, 2026 at 5:04 am

    You can use the setsockopt function to set a timeout on receive operations:

    SO_RCVTIMEO

    Sets the timeout value that specifies
    the maximum amount of time an input
    function waits until it completes. It
    accepts a timeval structure with the
    number of seconds and microseconds
    specifying the limit on how long to
    wait for an input operation to
    complete. If a receive operation has
    blocked for this much time without
    receiving additional data, it shall
    return with a partial count or errno
    set to [EAGAIN] or [EWOULDBLOCK] if no
    data is received. The default for this
    option is zero, which indicates that a
    receive operation shall not time out.
    This option takes a timeval structure.
    Note that not all implementations
    allow this option to be set.

    // LINUX
    struct timeval tv;
    tv.tv_sec = timeout_in_seconds;
    tv.tv_usec = 0;
    setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv, sizeof tv);
    
    // WINDOWS
    DWORD timeout = timeout_in_seconds * 1000;
    setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof timeout);
    
    // MAC OS X (identical to Linux)
    struct timeval tv;
    tv.tv_sec = timeout_in_seconds;
    tv.tv_usec = 0;
    setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv, sizeof tv);
    

    Reportedly on Windows this should be done before calling bind. I have verified by experiment that it can be done either before or after bind on Linux and OS X.

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

Sidebar

Ask A Question

Stats

  • Questions 541k
  • Answers 541k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your original code with two nested loops is not very… May 17, 2026 at 3:02 am
  • Editorial Team
    Editorial Team added an answer You need to be sure to restart your app after… May 17, 2026 at 3:02 am
  • Editorial Team
    Editorial Team added an answer using System.Linq; string s = string.Join(";", myDict.Select(x => x.Key +… May 17, 2026 at 3:02 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am trying to read binary data from sys.stdin using Python 2.7 on Windows
I am having issues reading data from a socket. Supposedly, there is a server
I have a Java (6) application which uses Hibernate (V3.3.2) to read data from
My code fetches CSV data from a PHP page using httplib. When I open
I'm writing web application where I need to push data from server to the
I implemented a TCP Client using a thread opening a socket to a server
Scenario: I have an application that pulls data from a SQL database as well
Here, i have coded to get data from DB. I want to store the
I can't understand what sort of exceptions I should handle 'here and now', and
A situation I have under Windows XP (SP3) has been driving me nuts, and

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.