aboutsummaryrefslogtreecommitdiffstats
path: root/Source/charon/socket.c
diff options
context:
space:
mode:
authorJan Hutter <jhutter@hsr.ch>2005-11-07 13:58:57 +0000
committerJan Hutter <jhutter@hsr.ch>2005-11-07 13:58:57 +0000
commit36c2c2824a5ac52d04554c3233e2a45ae3403ef9 (patch)
treeeb1ff1932574326b02b84ee659337be59c45d3f3 /Source/charon/socket.c
parent95f8c9aaaac0f2e2db57e9a9af862e19b18b4eaf (diff)
downloadstrongswan-36c2c2824a5ac52d04554c3233e2a45ae3403ef9.tar.bz2
strongswan-36c2c2824a5ac52d04554c3233e2a45ae3403ef9.tar.xz
- added cancelation point on receive
Diffstat (limited to 'Source/charon/socket.c')
-rw-r--r--Source/charon/socket.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/Source/charon/socket.c b/Source/charon/socket.c
index 563f2b7a4..f89822511 100644
--- a/Source/charon/socket.c
+++ b/Source/charon/socket.c
@@ -24,6 +24,7 @@
#include "socket.h"
+#include <pthread.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
@@ -54,12 +55,23 @@ struct private_socket_s{
status_t receiver(private_socket_t *this, packet_t **packet)
{
char buffer[MAX_PACKET];
-
+ int oldstate;
packet_t *pkt = packet_create(AF_INET);
+
+ /* add packet destroy handler for cancellation, enable cancellation */
+ pthread_cleanup_push((void(*)(void*))pkt->destroy, (void*)pkt);
+ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
+
/* do the read */
pkt->data.len = recvfrom(this->socket_fd, buffer, MAX_PACKET, 0,
&(pkt->source), &(pkt->sockaddr_len));
+
+ /* reset cancellation, remove packet destroy handler (without executing) */
+ pthread_setcancelstate(oldstate, NULL);
+ pthread_cleanup_pop(0);
+
+
/* TODO: get senders destination address, using
* IP_PKTINFO and recvmsg */