Function silc_packet_wait
SYNOPSIS
int silc_packet_wait(void *waiter, int timeout,
SilcPacket *return_packet)
DESCRIPTION
A special function that can be used to wait for a packet to arrive.
This function will block the calling process or thread until either
a packet is received into the `return_packet' pointer or the specified
timeout value `timeout', which is in milliseconds, will expire. If
the timeout is 0, no timeout exist. Before calling this function the
silc_packet_wait_init must be called. The caller is responsible for
freeing the returned packet with silc_packet_free.
This function can be used for example from a thread that wants to
block until SILC packet has been received.
Returns 1 when packet was received, 0 if timeout occurred and -1 if
error occurred.
EXAMPLE
static int foo_read_data(FooContext c)
{
SilcPacket packet;
void *waiter;
...
// Will wait for private message packets
if (c->initialized == FALSE) {
waiter = silc_packet_wait_init(stream,
SILC_PACKET_PRIVATE_MESSAGE, -1);
c->initialized = TRUE;
}
...
// Wait here until private message packet is received
if ((silc_packet_wait(waiter, 0, &packet)) < 0)
return -1;
... process packet ...
return 1;
}
|