From 16be9b332ef1db7588fec602023d13d35fb4b7cf Mon Sep 17 00:00:00 2001
From: Gregory Nutt
Date: Fri, 9 Dec 2016 15:17:58 -0600
Subject: [PATCH] More cancellation points
---
Documentation/NuttxUserGuide.html | 3 ++-
libc/unistd/lib_usleep.c | 20 --------------------
net/socket/accept.c | 17 ++++++++++++++++-
net/socket/connect.c | 17 ++++++++++++++++-
net/socket/recv.c | 2 ++
net/socket/recvfrom.c | 16 +++++++++++++++-
net/socket/send.c | 26 ++++++++++++++++++++++++--
net/socket/sendto.c | 9 ++++++++-
8 files changed, 83 insertions(+), 27 deletions(-)
diff --git a/Documentation/NuttxUserGuide.html b/Documentation/NuttxUserGuide.html
index 59e1b76f4f..ada2c6d9e1 100644
--- a/Documentation/NuttxUserGuide.html
+++ b/Documentation/NuttxUserGuide.html
@@ -6180,7 +6180,8 @@ returned to indicate the error:
The pthread_cleanup_push()
function will push the specified cancellation cleanup handler routine onto the calling thread's cancellation cleanup stack.
-
+
+
The cancellation cleanup handler will be popped from the cancellation cleanup stack and invoked with the argument arg when:
diff --git a/libc/unistd/lib_usleep.c b/libc/unistd/lib_usleep.c
index 5b72bbdcdf..4e3d4cdb0c 100644
--- a/libc/unistd/lib_usleep.c
+++ b/libc/unistd/lib_usleep.c
@@ -43,26 +43,6 @@
#include
#include
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Type Declarations
- ****************************************************************************/
-
-/****************************************************************************
- * Public Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
/****************************************************************************
* Public Functions
****************************************************************************/
diff --git a/net/socket/accept.c b/net/socket/accept.c
index a01f69f6c6..ed6d35fa09 100644
--- a/net/socket/accept.c
+++ b/net/socket/accept.c
@@ -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
*
* Redistribution and use in source and binary forms, with or without
@@ -48,6 +48,7 @@
#include
#include
+#include
#include
#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;
}
diff --git a/net/socket/connect.c b/net/socket/connect.c
index 6b83184fd9..3bb98d9899 100644
--- a/net/socket/connect.c
+++ b/net/socket/connect.c
@@ -51,6 +51,7 @@
#include
#include
+#include
#include
#include
#include
@@ -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 */
diff --git a/net/socket/recv.c b/net/socket/recv.c
index 412ed6e0d0..2e590c0b71 100644
--- a/net/socket/recv.c
+++ b/net/socket/recv.c
@@ -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);
}
diff --git a/net/socket/recvfrom.c b/net/socket/recvfrom.c
index e8a029b099..e45bacd032 100644
--- a/net/socket/recvfrom.c
+++ b/net/socket/recvfrom.c
@@ -57,6 +57,7 @@
#include
#include
+#include
#include
#include
#include
@@ -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 */
diff --git a/net/socket/send.c b/net/socket/send.c
index 60b19ab296..269de0882b 100644
--- a/net/socket/send.c
+++ b/net/socket/send.c
@@ -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
*
* Redistribution and use in source and binary forms, with or without
@@ -43,6 +43,8 @@
#include
#include
+#include
+
#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;
}
diff --git a/net/socket/sendto.c b/net/socket/sendto.c
index 79eb93e68f..26f88f6bdb 100644
--- a/net/socket/sendto.c
+++ b/net/socket/sendto.c
@@ -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;
}