/** @file\r
+ Interface function of the Socket.\r
\r
-Copyright (c) 2005 - 2006, Intel Corporation<BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
http://opensource.org/licenses/bsd-license.php<BR>\r
\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 Sock The socket to be destroyed.\r
\r
IN SOCKET *Sock\r
)\r
{\r
- EFI_STATUS Status;\r
+ EFI_STATUS Status;\r
+ TCP4_PROTO_DATA *ProtoData;\r
+ TCP_CB *Tcb;\r
+ VOID *SockProtocol;\r
\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
+ ProtoData = (TCP4_PROTO_DATA *) Sock->ProtoReserved;\r
+ Tcb = ProtoData->TcpPcb;\r
+\r
+ ASSERT (Tcb != NULL);\r
+\r
+ //\r
+ // Close the IP protocol.\r
+ //\r
+ gBS->CloseProtocol (\r
+ Tcb->IpInfo->ChildHandle,\r
+ &gEfiIp4ProtocolGuid,\r
+ ProtoData->TcpService->IpIo->Image,\r
+ Sock->SockHandle\r
+ );\r
+\r
+ if (Sock->DestroyCallback != NULL) {\r
+ Sock->DestroyCallback (Sock, Sock->Context);\r
+ }\r
+\r
+ //\r
+ // Retrieve the protocol installed on this sock\r
+ //\r
+ Status = gBS->OpenProtocol (\r
+ Sock->SockHandle,\r
+ &gEfiTcp4ProtocolGuid,\r
+ &SockProtocol,\r
+ Sock->DriverBinding,\r
+ Sock->SockHandle,\r
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+ );\r
+\r
+ if (EFI_ERROR (Status)) {\r
+\r
+ DEBUG ((EFI_D_ERROR, "SockDestroyChild: Open protocol installed "\r
+ "on socket failed with %r\n", Status));\r
+ }\r
+\r
+ //\r
+ // Uninstall the protocol installed on this sock\r
+ // in the light of Sock->SockType\r
+ //\r
+ gBS->UninstallMultipleProtocolInterfaces (\r
+ Sock->SockHandle,\r
+ &gEfiTcp4ProtocolGuid,\r
+ SockProtocol,\r
+ NULL\r
+ );\r
\r
Status = EfiAcquireLockOrFail (&(Sock->Lock));\r
if (EFI_ERROR (Status)) {\r
DEBUG ((EFI_D_ERROR, "SockDestroyChild: Protocol detach socket"\r
" failed with %r\n", Status));\r
\r
- Sock->IsDestroyed = FALSE;\r
+ Sock->InDestroy = FALSE;\r
} else if (SOCK_IS_CONFIGURED (Sock)) {\r
\r
SockConnFlush (Sock);\r
)\r
{\r
SOCKET *Sock;\r
+ VOID *SockProtocol;\r
EFI_STATUS Status;\r
\r
//\r
DEBUG ((EFI_D_ERROR, "SockCreateChild: Get the lock to "\r
"access socket failed with %r\n", Status));\r
\r
- SockDestroy (Sock);\r
- return NULL;\r
+ goto ERROR;\r
}\r
//\r
// inform the protocol layer to attach the socket\r
// with a new protocol control block\r
//\r
Status = Sock->ProtoHandler (Sock, SOCK_ATTACH, NULL);\r
+ EfiReleaseLock (&(Sock->Lock));\r
if (EFI_ERROR (Status)) {\r
\r
DEBUG ((EFI_D_ERROR, "SockCreateChild: Protocol failed to"\r
" attach a socket with %r\n", Status));\r
\r
- SockDestroy (Sock);\r
- Sock = NULL;\r
+ goto ERROR;\r
}\r
\r
- EfiReleaseLock (&(Sock->Lock));\r
return Sock;\r
+\r
+ERROR:\r
+\r
+ if (Sock->DestroyCallback != NULL) {\r
+ Sock->DestroyCallback (Sock, Sock->Context);\r
+ }\r
+\r
+ gBS->OpenProtocol (\r
+ Sock->SockHandle,\r
+ &gEfiTcp4ProtocolGuid,\r
+ &SockProtocol,\r
+ Sock->DriverBinding,\r
+ Sock->SockHandle,\r
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+ );\r
+ //\r
+ // Uninstall the protocol installed on this sock\r
+ //\r
+ gBS->UninstallMultipleProtocolInterfaces (\r
+ Sock->SockHandle,\r
+ &gEfiTcp4ProtocolGuid,\r
+ SockProtocol,\r
+ NULL\r
+ );\r
+ SockDestroy (Sock);\r
+ return NULL;\r
}\r
\r
\r
SOCKET *Socket;\r
EFI_EVENT Event;\r
\r
- ASSERT (SOCK_STREAM == Sock->Type);\r
+ ASSERT (SockStream == Sock->Type);\r
\r
Status = EfiAcquireLockOrFail (&(Sock->Lock));\r
if (EFI_ERROR (Status)) {\r
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
SOCK_TOKEN *SockToken;\r
UINT32 DataLen;\r
\r
- ASSERT (SOCK_STREAM == Sock->Type);\r
+ ASSERT (SockStream == Sock->Type);\r
\r
Status = EfiAcquireLockOrFail (&(Sock->Lock));\r
if (EFI_ERROR (Status)) {\r
"Snd Data\n", Status));\r
\r
RemoveEntryList (&(SockToken->TokenList));\r
- gBS->FreePool (SockToken);\r
+ FreePool (SockToken);\r
}\r
}\r
\r
EFI_STATUS Status;\r
EFI_EVENT Event;\r
\r
- ASSERT (SOCK_STREAM == Sock->Type);\r
+ ASSERT (SockStream == Sock->Type);\r
\r
Status = EfiAcquireLockOrFail (&(Sock->Lock));\r
if (EFI_ERROR (Status)) {\r
}\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
{\r
EFI_STATUS Status;\r
\r
- ASSERT (SOCK_STREAM == Sock->Type);\r
+ ASSERT (SockStream == Sock->Type);\r
\r
Status = EfiAcquireLockOrFail (&(Sock->Lock));\r
if (EFI_ERROR (Status)) {\r
EFI_STATUS Status;\r
EFI_EVENT Event;\r
\r
- ASSERT (SOCK_STREAM == Sock->Type);\r
+ ASSERT (SockStream == Sock->Type);\r
\r
Status = EfiAcquireLockOrFail (&(Sock->Lock));\r
if (EFI_ERROR (Status)) {\r