]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/TcpDxe/SockImpl.c
NetworkPkg: Support TCP Cancel function
[mirror_edk2.git] / NetworkPkg / TcpDxe / SockImpl.c
index f94155640229fcced1441755c0e5665817b276dc..35e0f6a662d1b28a1fb96a4460f98228ca22e9e5 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implementation of the Socket.\r
 \r
-  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -574,6 +574,71 @@ SockWakeRcvToken (
   }\r
 }\r
 \r
+/**\r
+  Cancel the tokens in the specific token list.\r
+\r
+  @param[in]       Token                 Pointer to the Token. If NULL, all tokens \r
+                                         in SpecifiedTokenList will be canceled.  \r
+  @param[in, out]  SpecifiedTokenList    Pointer to the token list to be checked.\r
+  \r
+  @retval EFI_SUCCESS          Cancel the tokens in the specific token listsuccessfully.\r
+  @retval EFI_NOT_FOUND        The Token is not found in SpecifiedTokenList.\r
+  \r
+**/\r
+EFI_STATUS\r
+SockCancelToken (\r
+  IN     SOCK_COMPLETION_TOKEN  *Token,\r
+  IN OUT LIST_ENTRY             *SpecifiedTokenList\r
+  )\r
+{\r
+  EFI_STATUS     Status;\r
+  LIST_ENTRY     *Entry;\r
+  LIST_ENTRY     *Next;\r
+  SOCK_TOKEN     *SockToken;\r
+\r
+  Status    = EFI_SUCCESS;\r
+  Entry     = NULL;\r
+  Next      = NULL;\r
+  SockToken = NULL;\r
+\r
+  if (IsListEmpty (SpecifiedTokenList) && Token != NULL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  \r
+  //\r
+  // Iterate through the SpecifiedTokenList.\r
+  //\r
+  Entry = SpecifiedTokenList->ForwardLink;\r
+  while (Entry != SpecifiedTokenList) {\r
+    SockToken = NET_LIST_USER_STRUCT (Entry, SOCK_TOKEN, TokenList);\r
+    \r
+    if (Token == NULL) {\r
+      SIGNAL_TOKEN (SockToken->Token, EFI_ABORTED);\r
+      RemoveEntryList (&SockToken->TokenList);\r
+      FreePool (SockToken);\r
+      \r
+      Entry = SpecifiedTokenList->ForwardLink;\r
+      Status = EFI_SUCCESS;\r
+    } else {\r
+      if (Token == (VOID *) SockToken->Token) {\r
+        SIGNAL_TOKEN (Token, EFI_ABORTED);\r
+        RemoveEntryList (&(SockToken->TokenList));\r
+        FreePool (SockToken);\r
+        \r
+        return EFI_SUCCESS;\r
+      }\r
+\r
+      Status = EFI_NOT_FOUND;\r
+      \r
+      Entry = Entry->ForwardLink;\r
+    } \r
+  }\r
+\r
+  ASSERT (IsListEmpty (SpecifiedTokenList) || Token != NULL);\r
+  \r
+  return Status;\r
+}\r
+\r
 /**\r
   Create a socket with initial data SockInitData.\r
 \r