]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/TcpDxe/SockInterface.c
SignedCapsulePkg/Include: Add EDKII system FMP capsule header.
[mirror_edk2.git] / NetworkPkg / TcpDxe / SockInterface.c
index ebab8c7f187d678721dec64fc42539d9d7a5bac8..21ce643a5481b62b6439408b4f8002ccca3d6b61 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Interface function of the Socket.\r
 \r
-  Copyright (c) 2009 - 2011, 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
@@ -129,7 +129,7 @@ SockBufferToken (
 }\r
 \r
 /**\r
-  Destory the socket Sock and its associated protocol control block.\r
+  Destroy the socket Sock and its associated protocol control block.\r
 \r
   @param[in, out]  Sock                 The socket to be destroyed.\r
 \r
@@ -146,11 +146,11 @@ SockDestroyChild (
 \r
   ASSERT ((Sock != NULL) && (Sock->ProtoHandler != NULL));\r
 \r
-  if (Sock->IsDestroyed) {\r
+  if (Sock->InDestroy) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
-  Sock->IsDestroyed = TRUE;\r
+  Sock->InDestroy = TRUE;\r
 \r
   Status            = EfiAcquireLockOrFail (&(Sock->Lock));\r
   if (EFI_ERROR (Status)) {\r
@@ -177,7 +177,7 @@ SockDestroyChild (
       Status)\r
       );\r
 \r
-    Sock->IsDestroyed = FALSE;\r
+    Sock->InDestroy = FALSE;\r
   } else if (SOCK_IS_CONFIGURED (Sock)) {\r
 \r
     SockConnFlush (Sock);\r
@@ -470,7 +470,7 @@ SockAccept (
       Socket->Parent->ConnCnt--;\r
 \r
       DEBUG (\r
-        (EFI_D_INFO,\r
+        (EFI_D_NET,\r
         "SockAccept: Accept a socket, now conncount is %d",\r
         Socket->Parent->ConnCnt)\r
         );\r
@@ -724,11 +724,7 @@ SockRcv (
   }\r
 \r
   if (RcvdBytes != 0) {\r
-    Status = SockProcessRcvToken (Sock, RcvToken);\r
-\r
-    if (EFI_ERROR (Status)) {\r
-      goto Exit;\r
-    }\r
+    SockProcessRcvToken (Sock, RcvToken);\r
 \r
     Status = Sock->ProtoHandler (Sock, SOCK_CONSUMED, NULL);\r
   } else {\r
@@ -880,6 +876,96 @@ Exit:
   return Status;\r
 }\r
 \r
+/**\r
+  Abort the socket associated connection, listen, transmission or receive request.\r
+\r
+  @param[in, out]  Sock        Pointer to the socket to abort.\r
+  @param[in]       Token       Pointer to a token that has been issued by\r
+                               Connect(), Accept(), Transmit() or Receive(). If\r
+                               NULL, all pending tokens issued by the four\r
+                               functions listed above will be aborted.\r
+\r
+  @retval EFI_UNSUPPORTED      The operation is not supported in the current\r
+                               implementation.\r
+**/\r
+EFI_STATUS\r
+SockCancel (\r
+  IN OUT SOCKET  *Sock,\r
+  IN     VOID    *Token\r
+  ) \r
+{\r
+  EFI_STATUS     Status;\r
+\r
+  Status    = EFI_SUCCESS;\r
+\r
+  ASSERT (SockStream == Sock->Type);\r
+\r
+  Status = EfiAcquireLockOrFail (&(Sock->Lock));\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG (\r
+      (EFI_D_ERROR,\r
+      "SockCancel: Get the access for socket failed with %r",\r
+      Status)\r
+      );\r
+\r
+    return EFI_ACCESS_DENIED;\r
+  }\r
+\r
+  if (SOCK_IS_UNCONFIGURED (Sock)) {\r
+    Status = EFI_NOT_STARTED;\r
+    goto Exit;\r
+  }\r
+  \r
+  //\r
+  // 1. Check ConnectionToken.\r
+  //\r
+  if (Token == NULL || (SOCK_COMPLETION_TOKEN *) Token == Sock->ConnectionToken) {\r
+    if (Sock->ConnectionToken != NULL) {\r
+      SIGNAL_TOKEN (Sock->ConnectionToken, EFI_ABORTED);\r
+      Sock->ConnectionToken = NULL;\r
+    }\r
+\r
+    if (Token != NULL) {\r
+      Status = EFI_SUCCESS;\r
+      goto Exit;\r
+    }\r
+  }\r
+\r
+  //\r
+  // 2. Check ListenTokenList.\r
+  //\r
+  Status = SockCancelToken (Token, &Sock->ListenTokenList);\r
+  if (Token != NULL && !EFI_ERROR (Status)) {\r
+    goto Exit;\r
+  }\r
+\r
+  //\r
+  // 3. Check RcvTokenList.\r
+  //\r
+  Status = SockCancelToken (Token, &Sock->RcvTokenList);\r
+  if (Token != NULL && !EFI_ERROR (Status)) {\r
+    goto Exit;\r
+  }\r
+  \r
+  //\r
+  // 4. Check SndTokenList.\r
+  //\r
+  Status = SockCancelToken (Token, &Sock->SndTokenList);\r
+  if (Token != NULL && !EFI_ERROR (Status)) {\r
+    goto Exit;\r
+  }\r
+\r
+  //\r
+  // 5. Check ProcessingSndTokenList.\r
+  //\r
+  Status = SockCancelToken (Token, &Sock->ProcessingSndTokenList);\r
+  \r
+Exit:\r
+  EfiReleaseLock (&(Sock->Lock));\r
+  return Status;\r
+}\r
+\r
+\r
 /**\r
   Get the mode data of the low layer protocol.\r
 \r