alarm()

This is a discussion on alarm() within the C Programming forums, part of the General Programming Boards category; Hi I'm trying to implement a timeout for my class, but I can't find a really good example to base ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    103

    alarm()

    Hi I'm trying to implement a timeout for my class, but I can't find a really good example to base it off, can anyone point me to one?

    I want to be able to start a timer at a send and should it hit 5 secs I want to resend until i get an acknowledge from where I am sending to. thanks.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,254
    I'm assuming you are using sockets (from the send comment).

    What you need is something like this:
    Code:
    send(...); /* send the data */
    int ret = select(...); /* use select to figure out when a response has been received.  Set select timeout to 5 seconds. */
    if(ret == 0)
    {
        /* select timed out, so no response was received within 5 seconds. */
    }
    else if(ret > 0)
    {
        /* Got something back */
        recv(...);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mini Alarm System
    By peckitt99 in forum Windows Programming
    Replies: 4
    Last Post: 04-23-2008, 01:08 AM
  2. clarification: behavior of type_info::before
    By Sebastiani in forum C++ Programming
    Replies: 11
    Last Post: 04-04-2008, 07:53 PM
  3. alarm pipe
    By jacktibet in forum C Programming
    Replies: 2
    Last Post: 08-28-2003, 03:02 AM
  4. Replies: 23
    Last Post: 01-31-2003, 03:13 AM
  5. ANN: The Fourth Contest: Alarm Clock, sign up here
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 59
    Last Post: 08-10-2002, 01:24 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21