Setting timeout for read api

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Swaroop

    #1

    Setting timeout for read api

    PLS HELP..I am working on socket programming as part of my final year
    project. I want to know how to set a timeout on read api that reads
    from a socket. Is it possible using SIGALRM signal?Will setting
    O_NONBLOCK flag of the socket help? Is there any other way to do it?

  • Paul Rubin

    #2
    Re: Setting timeout for read api

    "Swaroop" <tifosi_416@ind iatimes.com> writes:[color=blue]
    > PLS HELP..I am working on socket programming as part of my final year
    > project. I want to know how to set a timeout on read api that reads
    > from a socket. Is it possible using SIGALRM signal?Will setting
    > O_NONBLOCK flag of the socket help? Is there any other way to do it?[/color]

    You could do it with sigalrm but more common is to set a timeout on
    the socket (see the settimeout method in the doc). You could also use
    select with a timeout, and not read until the select tells you that
    data is available.

    Comment

    • David Schwartz

      #3
      Re: Setting timeout for read api


      "Paul Rubin" <http://phr.cx@NOSPAM.i nvalid> wrote in message
      news:7xpsl2mydo .fsf@ruckus.bro uhaha.com...
      [color=blue]
      > "Swaroop" <tifosi_416@ind iatimes.com> writes:[/color]
      [color=blue][color=green]
      >> PLS HELP..I am working on socket programming as part of my final year
      >> project. I want to know how to set a timeout on read api that reads
      >> from a socket. Is it possible using SIGALRM signal?Will setting
      >> O_NONBLOCK flag of the socket help? Is there any other way to do it?[/color][/color]
      [color=blue]
      > You could do it with sigalrm but more common is to set a timeout on
      > the socket (see the settimeout method in the doc). You could also use
      > select with a timeout, and not read until the select tells you that
      > data is available.[/color]

      Just don't forget to set the socket non-blocking.

      DS


      Comment

      Working...