How to awake blocked socket read?

Y

Yim

In below codes,
After 10 seconds, function t() was called. So far everything is ok.
Then I want to awake blocked read(). So want to exit program.
In t(), how to do?
(in t(), close(sockfd) don't awake read());

#include <time.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>

#include <unistd.h>
#include <pthread.h>

void start (void);
void stop (void);
void t (union sigval sigval);
timer_t timer;

int main (void)
{
start ();
//
// socket, listen, bind, accept
//
read(sockfd, buf, 1024);
stop ();
return EXIT_SUCCESS;
}

void start ()
{
struct itimerspec itimer = { { 0 , 0 }, { 10, 0 } }; //
interval(sec, nanosec) value(sec, nanosec)
struct sigevent sigev;

memset (&sigev, 0, sizeof (struct sigevent));
sigev.sigev_value.sival_int = 1;
sigev.sigev_notify = SIGEV_THREAD;
sigev.sigev_notify_attributes = NULL;
sigev.sigev_notify_function = t;

if (timer_create (CLOCK_REALTIME, &sigev, &timer) < 0)
{
fprintf (stderr, "[%d]: %s\n", __LINE__, strerror (errno));
exit (errno);
}

if (timer_settime (timer, 0, &itimer, NULL) < 0)
{
fprintf (stderr, "[%d]: %s\n", __LINE__, strerror (errno));
exit (errno);
}
}

void stop (void)
{
if (timer_delete (timer) < 0)
{
fprintf (stderr, "[%d]: %s\n", __LINE__, strerror (errno));
exit (errno);
}
}

void t (union sigval sigval)
{
printf ("timer_nr=%02d pid=%d pthread_self=%ld\n",
sigval.sival_int, getpid (), pthread_self ());
// what code should I do write to awake bolcked read in main()?
}
 
J

Joona I Palaste

Yim said:
In below codes,
After 10 seconds, function t() was called. So far everything is ok.
Then I want to awake blocked read(). So want to exit program.
In t(), how to do?
(in t(), close(sockfd) don't awake read());

Your question depends on system-specific extensions and is thus
off-topic on comp.lang.c. Please ask in comp.unix.programmer or a
newsgroup dedicated to your own system.

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"The large yellow ships hung in the sky in exactly the same way that bricks
don't."
- Douglas Adams
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top