More cancellation points

This commit is contained in:
Gregory Nutt 2016-12-09 15:17:58 -06:00
parent 70de0ee39f
commit 16be9b332e
8 changed files with 83 additions and 27 deletions

View file

@ -6180,7 +6180,8 @@ returned to indicate the error:
</p>
<p>
The <code>pthread_cleanup_push()</code> function will push the specified cancellation cleanup handler routine onto the calling thread's cancellation cleanup stack.
</p>
<p>
The cancellation cleanup handler will be popped from the cancellation cleanup stack and invoked with the argument arg when:
</p>
<p>

View file

@ -43,26 +43,6 @@
#include <assert.h>
#include <errno.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Type Declarations
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/

View file

@ -1,7 +1,7 @@
/****************************************************************************
* net/socket/accept.c
*
* Copyright (C) 2007-2012, 2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2012, 2015-2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -48,6 +48,7 @@
#include <assert.h>
#include <debug.h>
#include <nuttx/pthread.h>
#include <arch/irq.h>
#include "tcp/tcp.h"
@ -132,6 +133,10 @@ int psock_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
DEBUGASSERT(psock != NULL);
/* Treat as a cancellation point */
enter_cancellation_point();
/* Is the socket a stream? */
if (psock->s_type != SOCK_STREAM)
@ -269,6 +274,8 @@ int psock_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
newsock->s_flags |= _SF_CONNECTED;
newsock->s_flags &= ~_SF_CLOSED;
leave_cancellation_point();
return OK;
errout_after_accept:
@ -276,6 +283,7 @@ errout_after_accept:
errout:
set_errno(errcode);
leave_cancellation_point();
return ERROR;
}
@ -355,6 +363,10 @@ int accept(int sockfd, FAR struct sockaddr *addr, FAR socklen_t *addrlen)
int errcode;
int ret;
/* accept() is a cancellation point */
enter_cancellation_point();
/* Verify that the sockfd corresponds to valid, allocated socket */
if (psock == NULL || psock->s_crefs <= 0)
@ -402,9 +414,11 @@ int accept(int sockfd, FAR struct sockaddr *addr, FAR socklen_t *addrlen)
/* The errno value has already been set */
sockfd_release(newfd);
leave_cancellation_point();
return ERROR;
}
leave_cancellation_point();
return newfd;
errout_with_socket:
@ -412,6 +426,7 @@ errout_with_socket:
errout:
set_errno(errcode);
leave_cancellation_point();
return ERROR;
}

View file

@ -51,6 +51,7 @@
#include <arch/irq.h>
#include <nuttx/semaphore.h>
#include <nuttx/pthread.h>
#include <nuttx/net/net.h>
#include <nuttx/net/netdev.h>
#include <nuttx/net/udp.h>
@ -516,6 +517,10 @@ int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr,
#endif
int errcode;
/* Treat as a cancellation point */
enter_cancellation_point();
/* Verify that the psock corresponds to valid, allocated socket */
if (!psock || psock->s_crefs <= 0)
@ -663,10 +668,12 @@ int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr,
goto errout;
}
leave_cancellation_point();
return OK;
errout:
set_errno(errcode);
leave_cancellation_point();
return ERROR;
}
@ -741,13 +748,21 @@ errout:
int connect(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen)
{
int ret;
/* accept() is a cancellation point */
enter_cancellation_point();
/* Get the underlying socket structure */
FAR struct socket *psock = sockfd_socket(sockfd);
/* Then let psock_connect() do all of the work */
return psock_connect(psock, addr, addrlen);
ret = psock_connect(psock, addr, addrlen);
leave_cancellation_point();
return ret;
}
#endif /* CONFIG_NET */

View file

@ -71,6 +71,8 @@
ssize_t recv(int sockfd, FAR void *buf, size_t len, int flags)
{
/* recv is a cancellation point, but that can all be handled by recvfrom */
return recvfrom(sockfd, buf, len, flags, NULL, 0);
}

View file

@ -57,6 +57,7 @@
#include <nuttx/clock.h>
#include <nuttx/semaphore.h>
#include <nuttx/pthread.h>
#include <nuttx/net/net.h>
#include <nuttx/net/iob.h>
#include <nuttx/net/netdev.h>
@ -1851,6 +1852,10 @@ ssize_t psock_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
ssize_t ret;
int errcode;
/* Treat as a cancellation point */
enter_cancellation_point();
/* Verify that non-NULL pointers were passed */
#ifdef CONFIG_DEBUG_FEATURES
@ -2013,10 +2018,12 @@ ssize_t psock_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
/* Success return */
leave_cancellation_point();
return ret;
errout:
set_errno(errcode);
leave_cancellation_point();
return ERROR;
}
@ -2076,6 +2083,11 @@ ssize_t recvfrom(int sockfd, FAR void *buf, size_t len, int flags,
FAR struct sockaddr *from, FAR socklen_t *fromlen)
{
FAR struct socket *psock;
ssize_t ret;
/* recvfrom() is a cancellation point */
enter_cancellation_point();
/* Get the underlying socket structure */
@ -2083,7 +2095,9 @@ ssize_t recvfrom(int sockfd, FAR void *buf, size_t len, int flags,
/* Then let psock_recvfrom() do all of the work */
return psock_recvfrom(psock, buf, len, flags, from, fromlen);
ret = psock_recvfrom(psock, buf, len, flags, from, fromlen);
leave_cancellation_point();
return ret;
}
#endif /* CONFIG_NET */

View file

@ -1,7 +1,7 @@
/****************************************************************************
* net/socket/send.c
*
* Copyright (C) 2007-2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2014, 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -43,6 +43,8 @@
#include <sys/socket.h>
#include <errno.h>
#include <nuttx/pthread.h>
#include "tcp/tcp.h"
#include "udp/udp.h"
#include "pkt/pkt.h"
@ -122,6 +124,10 @@ ssize_t psock_send(FAR struct socket *psock, FAR const void *buf, size_t len,
{
int ret;
/* Treat as a cancellation point */
enter_cancellation_point();
switch (psock->s_type)
{
#if defined(CONFIG_NET_PKT)
@ -192,6 +198,7 @@ ssize_t psock_send(FAR struct socket *psock, FAR const void *buf, size_t len,
break;
}
leave_cancellation_point();
return ret;
}
@ -261,5 +268,20 @@ ssize_t psock_send(FAR struct socket *psock, FAR const void *buf, size_t len,
ssize_t send(int sockfd, FAR const void *buf, size_t len, int flags)
{
return psock_send(sockfd_socket(sockfd), buf, len, flags);
FAR struct socket *psock;
ssize_t ret;
/* send() is a cancellation point */
enter_cancellation_point();
/* Get the underlying socket structure */
psock = sockfd_socket(sockfd);
/* And let psock_send do all of the work */
ret = psock_send(psock, buf, len, flags, to, tolen);
leave_cancellation_point();
return ret;
}

View file

@ -309,6 +309,11 @@ ssize_t sendto(int sockfd, FAR const void *buf, size_t len, int flags,
FAR const struct sockaddr *to, socklen_t tolen)
{
FAR struct socket *psock;
ssize_t ret;
/* sendto() is a cancellation point */
enter_cancellation_point();
/* Get the underlying socket structure */
@ -316,5 +321,7 @@ ssize_t sendto(int sockfd, FAR const void *buf, size_t len, int flags,
/* And let psock_sendto do all of the work */
return psock_sendto(psock, buf, len, flags, to, tolen);
ret = psock_sendto(psock, buf, len, flags, to, tolen);
leave_cancellation_point();
return ret;
}