0

Who can tell how to use wake_up() in gwan?

// tell G-WAN when to run a script again (for the same request)
// type: WK_MS | WK_FD
#define WK_MS 1  // milliseconds
#define WK_FD 2  // file descriptor
void wake_up(char *argv[], int delay_or_fd, int type);

Is it used to replace sleep()?

k.k. lou
  • 1,805
  • 2
  • 13
  • 16

1 Answers1

1

Look at the examples using these functions - be careful though, the last time I tested them, they didn't work (this has probably been fixed already or might have been a usage error on my part, but nevertheless if you're going to use them, try the examples first and see if they work).

In a nutshell:

with WK_MS this behaves close to the sleep function, with the difference, that your function is called again after the time elapsed (as opposed to continuing where you called it), and execution is continued after the wake_up call. So it's more like "execute me again after X ms".

with WK_FD your script should be called again as soon as there is new data on the provided file descriptor (useful for e.g. tailing a self built log mechanism or theoretically for realtime communications like websockets, but I never got CLIENT_SOCKET working with this, so be careful to check whatever you pass if it's really a file descriptor beforehand)

griffin
  • 1,261
  • 8
  • 24
  • Thanks to griffin. Your sharing is useful. If it means "call me again to execute", is it implied that the script is returned and memories are released to system first, before calling the same script again? How about the connection, is it closed too? When the script is re-called, is it start at the first line or where just under the wake_up function? thanks – k.k. lou Jun 04 '13 at 06:40
  • 1. No 2. Should depend on your return code - again: look into the provided examples, you will see how it works there pretty well (look for `return RC_NOHEADERS + RC_STREAMING;` ) 3. as said, the main function is called again, so "start at the first line" in your terms. – griffin Jun 04 '13 at 10:05