From 5ffe214ae95be9cb3dfca3d1dc254ad9f1f6fe45 Mon Sep 17 00:00:00 2001 From: Jiaxin Wu Date: Tue, 31 May 2016 22:17:26 +0800 Subject: 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 Cc: Fu Siyuan Cc: Zhang Lubo Cc: Hegde Nagaraj P Cc: Gary Lin Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jiaxin Wu Reviewed-by: Gary Lin Reviewed-by: Hegde Nagaraj P Reviewed-by: Ye Ting Tested-by: Gary Lin Tested-by: Hegde Nagaraj P --- NetworkPkg/TcpDxe/SockImpl.c | 67 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) (limited to 'NetworkPkg/TcpDxe/SockImpl.c') diff --git a/NetworkPkg/TcpDxe/SockImpl.c b/NetworkPkg/TcpDxe/SockImpl.c index f941556402..35e0f6a662 100644 --- a/NetworkPkg/TcpDxe/SockImpl.c +++ b/NetworkPkg/TcpDxe/SockImpl.c @@ -1,7 +1,7 @@ /** @file Implementation of the Socket. - Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -574,6 +574,71 @@ SockWakeRcvToken ( } } +/** + Cancel the tokens in the specific token list. + + @param[in] Token Pointer to the Token. If NULL, all tokens + in SpecifiedTokenList will be canceled. + @param[in, out] SpecifiedTokenList Pointer to the token list to be checked. + + @retval EFI_SUCCESS Cancel the tokens in the specific token listsuccessfully. + @retval EFI_NOT_FOUND The Token is not found in SpecifiedTokenList. + +**/ +EFI_STATUS +SockCancelToken ( + IN SOCK_COMPLETION_TOKEN *Token, + IN OUT LIST_ENTRY *SpecifiedTokenList + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Entry; + LIST_ENTRY *Next; + SOCK_TOKEN *SockToken; + + Status = EFI_SUCCESS; + Entry = NULL; + Next = NULL; + SockToken = NULL; + + if (IsListEmpty (SpecifiedTokenList) && Token != NULL) { + return EFI_NOT_FOUND; + } + + // + // Iterate through the SpecifiedTokenList. + // + Entry = SpecifiedTokenList->ForwardLink; + while (Entry != SpecifiedTokenList) { + SockToken = NET_LIST_USER_STRUCT (Entry, SOCK_TOKEN, TokenList); + + if (Token == NULL) { + SIGNAL_TOKEN (SockToken->Token, EFI_ABORTED); + RemoveEntryList (&SockToken->TokenList); + FreePool (SockToken); + + Entry = SpecifiedTokenList->ForwardLink; + Status = EFI_SUCCESS; + } else { + if (Token == (VOID *) SockToken->Token) { + SIGNAL_TOKEN (Token, EFI_ABORTED); + RemoveEntryList (&(SockToken->TokenList)); + FreePool (SockToken); + + return EFI_SUCCESS; + } + + Status = EFI_NOT_FOUND; + + Entry = Entry->ForwardLink; + } + } + + ASSERT (IsListEmpty (SpecifiedTokenList) || Token != NULL); + + return Status; +} + /** Create a socket with initial data SockInitData. -- cgit v1.2.3