Cancel UDP recvfrom in C on Unix
Posted
by hora
on Stack Overflow
See other posts from Stack Overflow
or by hora
Published on 2010-03-16T04:47:55Z
Indexed on
2010/03/16
5:16 UTC
Read the original article
Hit count: 352
I'm just starting to learn how network programming in C works, and I've written a small program that sends messages to and from a UNIX terminal. I'm using pthreads in my program, one of which essentially just waits on recvfrom()
to receive a message.
However, I want to be able to close all threads properly if the users chooses to quit the program. The way I have it set up right now, a different thread just cancels the thread waiting on recvfrom, but I'm worried this might not be a good idea since I'm leaving sockets unclosed and I'm not freeing all the memory I allocated.
Is there a way to cancel a recvfrom()
call, or some way to run a certain routine upon cancelling a pthread?
Thanks.
© Stack Overflow or respective owner