summaryrefslogtreecommitdiffstats
path: root/NetworkPkg/TcpDxe/SockInterface.c
diff options
context:
space:
mode:
authorJiaxin Wu <jiaxin.wu@intel.com>2016-05-31 22:17:26 +0800
committerJiaxin Wu <jiaxin.wu@intel.com>2016-06-13 11:51:35 +0800
commit5ffe214ae95be9cb3dfca3d1dc254ad9f1f6fe45 (patch)
tree1e5f61611a66924aeac4d34af8bb3479daff63b2 /NetworkPkg/TcpDxe/SockInterface.c
parent3b5624b01454ed0ce1ae2089cc5b091a9cd07ed2 (diff)
downloadedk2-5ffe214ae95be9cb3dfca3d1dc254ad9f1f6fe45.tar.gz
edk2-5ffe214ae95be9cb3dfca3d1dc254ad9f1f6fe45.tar.bz2
edk2-5ffe214ae95be9cb3dfca3d1dc254ad9f1f6fe45.zip
NetworkPkg: Support TCP Cancel function
This path is used to support TCP Cancel function to abort an asynchronous connection, listen, transmission or receive request. If any TCP CompletionToken is not signaled, it should not be closed directly by calling CloseEvent (Still in the TCP TokenList). If not, any exception behavior may be triggered. We should cancel it by calling Tcp->Cancel() first. In such a case, TCP Cancel function is necessary. Cc: Ye Ting <ting.ye@intel.com> Cc: Fu Siyuan <siyuan.fu@intel.com> Cc: Zhang Lubo <lubo.zhang@intel.com> Cc: Hegde Nagaraj P <nagaraj-p.hegde@hpe.com> Cc: Gary Lin <glin@suse.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com> Reviewed-by: Gary Lin <glin@suse.com> Reviewed-by: Hegde Nagaraj P <nagaraj-p.hegde@hpe.com> Reviewed-by: Ye Ting <ting.ye@intel.com> Tested-by: Gary Lin <glin@suse.com> Tested-by: Hegde Nagaraj P <nagaraj-p.hegde@hpe.com>
Diffstat (limited to 'NetworkPkg/TcpDxe/SockInterface.c')
-rw-r--r--NetworkPkg/TcpDxe/SockInterface.c92
1 files changed, 91 insertions, 1 deletions
diff --git a/NetworkPkg/TcpDxe/SockInterface.c b/NetworkPkg/TcpDxe/SockInterface.c
index 1f3524bc1b..1ae0c64b10 100644
--- a/NetworkPkg/TcpDxe/SockInterface.c
+++ b/NetworkPkg/TcpDxe/SockInterface.c
@@ -1,7 +1,7 @@
/** @file
Interface function of the Socket.
- Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
@@ -877,6 +877,96 @@ Exit:
}
/**
+ Abort the socket associated connection, listen, transmission or receive request.
+
+ @param[in, out] Sock Pointer to the socket to abort.
+ @param[in] Token Pointer to a token that has been issued by
+ Connect(), Accept(), Transmit() or Receive(). If
+ NULL, all pending tokens issued by the four
+ functions listed above will be aborted.
+
+ @retval EFI_UNSUPPORTED The operation is not supported in the current
+ implementation.
+**/
+EFI_STATUS
+SockCancel (
+ IN OUT SOCKET *Sock,
+ IN VOID *Token
+ )
+{
+ EFI_STATUS Status;
+
+ Status = EFI_SUCCESS;
+
+ ASSERT (SockStream == Sock->Type);
+
+ Status = EfiAcquireLockOrFail (&(Sock->Lock));
+ if (EFI_ERROR (Status)) {
+ DEBUG (
+ (EFI_D_ERROR,
+ "SockCancel: Get the access for socket failed with %r",
+ Status)
+ );
+
+ return EFI_ACCESS_DENIED;
+ }
+
+ if (SOCK_IS_UNCONFIGURED (Sock)) {
+ Status = EFI_NOT_STARTED;
+ goto Exit;
+ }
+
+ //
+ // 1. Check ConnectionToken.
+ //
+ if (Token == NULL || (SOCK_COMPLETION_TOKEN *) Token == Sock->ConnectionToken) {
+ if (Sock->ConnectionToken != NULL) {
+ SIGNAL_TOKEN (Sock->ConnectionToken, EFI_ABORTED);
+ Sock->ConnectionToken = NULL;
+ }
+
+ if (Token != NULL) {
+ Status = EFI_SUCCESS;
+ goto Exit;
+ }
+ }
+
+ //
+ // 2. Check ListenTokenList.
+ //
+ Status = SockCancelToken (Token, &Sock->ListenTokenList);
+ if (Token != NULL && !EFI_ERROR (Status)) {
+ goto Exit;
+ }
+
+ //
+ // 3. Check RcvTokenList.
+ //
+ Status = SockCancelToken (Token, &Sock->RcvTokenList);
+ if (Token != NULL && !EFI_ERROR (Status)) {
+ goto Exit;
+ }
+
+ //
+ // 4. Check SndTokenList.
+ //
+ Status = SockCancelToken (Token, &Sock->SndTokenList);
+ if (Token != NULL && !EFI_ERROR (Status)) {
+ goto Exit;
+ }
+
+ //
+ // 5. Check ProcessingSndTokenList.
+ //
+ Status = SockCancelToken (Token, &Sock->ProcessingSndTokenList);
+
+Exit:
+ EfiReleaseLock (&(Sock->Lock));
+ return Status;
+}
+
+
+/**
Get the mode data of the low layer protocol.
@param[in] Sock Pointer to the socket to get mode data from.