timer

This is a discussion on timer within the C Programming forums, part of the General Programming Boards category; Hi, I am working on a socket programming code and I need to modify part of it. In the code ...

  1. #1
    GhH
    GhH is offline
    Registered User
    Join Date
    Sep 2011
    Posts
    2

    timer

    Hi,
    I am working on a socket programming code and I need to modify part of it. In the code there is a line where a process receives a message :

    receive(source, buf);

    When a process receives a message, I don't want to deliver the message immediately, what I want is to deliver it at sometime later (with some delay).
    do you know how I can do it? I tried the sleep() but it is not what I want, since when the process is asleep,it does not receive next messages until sleep time is elapsed. I think I should use timers, like start a timer when a message is received, and after the timer is expired I deliver the message, and I need to start a timer for each message. I don't know how to do this and which timers I should use. I f anybody can explain this to me, it will be a great help!

    thanks a lot!
    Ghazale

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Ok, what you want to do is stuff your message into a linked list of buffers, then get back to receiving.
    In a separate thread have a timer running that sends one buffer from the list every tick...

    Assuming Windows...CreateThread function (Windows) SetTimer function (Windows)

    Assuming Linux... well someone else will know that for sure.

  3. #3
    GhH
    GhH is offline
    Registered User
    Join Date
    Sep 2011
    Posts
    2
    but I don't want to send one buffer from the list every tick, I want to send each buffer after some (and different) delay, any idea how to do that? let's say I receive message 1 at t1 and message 2 at t2, I want to deliver message 1 at t1+delay1 and message 2 at t2+delay2

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    To be honest I have no idea how or why you would want to do that...

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    man select


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    Perhaps by delaying the message, the OP is trying to generate some kind of echo effect.

    It certainly seems to have a resonant feel about it
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c# timer from
    By jackofcyber in forum C# Programming
    Replies: 5
    Last Post: 04-16-2010, 07:08 AM
  2. Help with timer
    By NeMewSys in forum C++ Programming
    Replies: 4
    Last Post: 05-21-2008, 09:47 AM
  3. Timer use?
    By Djanvk in forum C++ Programming
    Replies: 2
    Last Post: 03-11-2005, 01:50 PM
  4. need help with a timer
    By revelation437 in forum C++ Programming
    Replies: 10
    Last Post: 03-27-2003, 10:25 AM
  5. how to set timer
    By marianne in forum C Programming
    Replies: 1
    Last Post: 02-12-2003, 09:21 PM

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