]>
git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/Tcp4Dxe/SockImpl.c
2 Implementation of the Socket.
4 Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php<BR>
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Get the length of the data that can be retrieved from the socket
21 @param SockBuffer Pointer to the socket receive buffer.
22 @param IsUrg Pointer to a BOOLEAN variable. If TRUE the data is
24 @param BufLen The maximum length of the data buffer to store the
25 received data in socket layer.
27 @return The length of the data can be retreived.
32 IN SOCK_BUFFER
*SockBuffer
,
38 Process the send token.
40 @param Sock Pointer to the socket.
49 Supporting function for both SockImpl and SockInterface.
51 @param Event The Event this notify function registered to, ignored.
65 Get the length of the data that can be retrieved from the socket
68 @param SockBuffer Pointer to the socket receive buffer.
69 @param IsUrg Pointer to a BOOLEAN variable. If TRUE the data is
71 @param BufLen The maximum length of the data buffer to store the
72 received data in socket layer.
74 @return The length of the data can be retreived.
79 IN SOCK_BUFFER
*SockBuffer
,
86 TCP_RSV_DATA
*TcpRsvData
;
88 ASSERT ((SockBuffer
!= NULL
) && (IsUrg
!= NULL
) && (BufLen
> 0));
90 RcvBufEntry
= SockBufFirst (SockBuffer
);
91 ASSERT (RcvBufEntry
!= NULL
);
93 TcpRsvData
= (TCP_RSV_DATA
*) RcvBufEntry
->ProtoData
;
95 *IsUrg
= (BOOLEAN
) ((TcpRsvData
->UrgLen
> 0) ? TRUE
: FALSE
);
97 if (*IsUrg
&& TcpRsvData
->UrgLen
< RcvBufEntry
->TotalSize
) {
99 DataLen
= MIN (TcpRsvData
->UrgLen
, BufLen
);
101 if (DataLen
< TcpRsvData
->UrgLen
) {
102 TcpRsvData
->UrgLen
= TcpRsvData
->UrgLen
- DataLen
;
104 TcpRsvData
->UrgLen
= 0;
111 DataLen
= RcvBufEntry
->TotalSize
;
113 RcvBufEntry
= SockBufNext (SockBuffer
, RcvBufEntry
);
115 while ((BufLen
> DataLen
) && (RcvBufEntry
!= NULL
)) {
117 TcpRsvData
= (TCP_RSV_DATA
*) RcvBufEntry
->ProtoData
;
119 Urg
= (BOOLEAN
) ((TcpRsvData
->UrgLen
> 0) ? TRUE
: FALSE
);
125 if (*IsUrg
&& TcpRsvData
->UrgLen
< RcvBufEntry
->TotalSize
) {
127 if (TcpRsvData
->UrgLen
+ DataLen
< BufLen
) {
128 TcpRsvData
->UrgLen
= 0;
130 TcpRsvData
->UrgLen
= TcpRsvData
->UrgLen
- (BufLen
- DataLen
);
133 return MIN (TcpRsvData
->UrgLen
+ DataLen
, BufLen
);
137 DataLen
+= RcvBufEntry
->TotalSize
;
139 RcvBufEntry
= SockBufNext (SockBuffer
, RcvBufEntry
);
142 DataLen
= MIN (BufLen
, DataLen
);
148 Copy data from socket buffer to application provided receive buffer.
150 @param Sock Pointer to the socket.
151 @param TcpRxData Pointer to the application provided receive buffer.
152 @param RcvdBytes The maximum length of the data can be copied.
153 @param IsOOB If TRUE the data is OOB, FALSE the data is normal.
167 EFI_TCP4_RECEIVE_DATA
*RxData
;
168 EFI_TCP4_FRAGMENT_DATA
*Fragment
;
170 RxData
= (EFI_TCP4_RECEIVE_DATA
*) TcpRxData
;
174 ASSERT (RxData
->DataLength
>= RcvdBytes
);
176 RxData
->DataLength
= RcvdBytes
;
177 RxData
->UrgentFlag
= IsOOB
;
179 for (Index
= 0; (Index
< RxData
->FragmentCount
) && (RcvdBytes
> 0); Index
++) {
181 Fragment
= &RxData
->FragmentTable
[Index
];
182 CopyBytes
= MIN ((UINT32
) (Fragment
->FragmentLength
), RcvdBytes
);
185 Sock
->RcvBuffer
.DataQueue
,
188 Fragment
->FragmentBuffer
191 Fragment
->FragmentLength
= CopyBytes
;
192 RcvdBytes
-= CopyBytes
;
199 Get received data from the socket layer to the receive token.
201 @param Sock Pointer to the socket.
202 @param RcvToken Pointer to the application provided receive token.
204 @return The length of data received in this token.
208 SockProcessRcvToken (
210 IN OUT SOCK_IO_TOKEN
*RcvToken
213 UINT32 TokenRcvdBytes
;
214 EFI_TCP4_RECEIVE_DATA
*RxData
;
217 ASSERT (Sock
!= NULL
);
219 ASSERT (SockStream
== Sock
->Type
);
221 RxData
= RcvToken
->Packet
.RxData
;
223 TokenRcvdBytes
= SockTcpDataToRcv (
226 (UINT32
) RxData
->DataLength
230 // Copy data from RcvBuffer of socket to user
231 // provided RxData and set the fields in TCP RxData
233 SockSetTcpRxData (Sock
, RxData
, TokenRcvdBytes
, IsUrg
);
235 NetbufQueTrim (Sock
->RcvBuffer
.DataQueue
, TokenRcvdBytes
);
236 SIGNAL_TOKEN (&(RcvToken
->Token
), EFI_SUCCESS
);
238 return TokenRcvdBytes
;
243 Process the TCP send data, buffer the tcp txdata and append
244 the buffer to socket send buffer,then try to send it.
246 @param Sock Pointer to the socket.
247 @param TcpTxData Pointer to the application provided send buffer.
249 @retval EFI_SUCCESS The operation is completed successfully.
250 @retval EFI_OUT_OF_RESOURCES Failed due to resource limit.
254 SockProcessTcpSndData (
261 EFI_TCP4_TRANSMIT_DATA
*TxData
;
263 TxData
= (EFI_TCP4_TRANSMIT_DATA
*) TcpTxData
;
266 // transform this TxData into a NET_BUFFER
267 // and insert it into Sock->SndBuffer
269 SndData
= NetbufFromExt (
270 (NET_FRAGMENT
*) TxData
->FragmentTable
,
271 (UINT32
) TxData
->FragmentCount
,
278 if (NULL
== SndData
) {
279 DEBUG ((EFI_D_ERROR
, "SockKProcessSndData: Failed to"
280 " call NetBufferFromExt\n"));
282 return EFI_OUT_OF_RESOURCES
;
285 NetbufQueAppend (Sock
->SndBuffer
.DataQueue
, SndData
);
288 // notify the low layer protocol to handle this send token
290 if (TxData
->Urgent
) {
291 Status
= Sock
->ProtoHandler (Sock
, SOCK_SNDURG
, NULL
);
293 if (EFI_ERROR (Status
)) {
299 Status
= Sock
->ProtoHandler (Sock
, SOCK_SNDPUSH
, NULL
);
301 if (EFI_ERROR (Status
)) {
307 // low layer protocol should really handle the sending
308 // process when catching SOCK_SND request
310 Status
= Sock
->ProtoHandler (Sock
, SOCK_SND
, NULL
);
312 if (EFI_ERROR (Status
)) {
321 Flush the tokens in the specific token list.
323 @param Sock Pointer to the socket.
324 @param PendingTokenList Pointer to the token list to be flushed.
328 SockFlushPendingToken (
330 IN LIST_ENTRY
*PendingTokenList
333 SOCK_TOKEN
*SockToken
;
334 SOCK_COMPLETION_TOKEN
*Token
;
336 ASSERT ((Sock
!= NULL
) && (PendingTokenList
!= NULL
));
338 while (!IsListEmpty (PendingTokenList
)) {
339 SockToken
= NET_LIST_HEAD (
345 Token
= SockToken
->Token
;
346 SIGNAL_TOKEN (Token
, Sock
->SockError
);
348 RemoveEntryList (&(SockToken
->TokenList
));
349 FreePool (SockToken
);
355 Wake up the connection token while the connection is successfully established,
356 then try to process any pending send token.
358 @param Sock Pointer to the socket.
366 ASSERT (Sock
->ConnectionToken
!= NULL
);
368 SIGNAL_TOKEN (Sock
->ConnectionToken
, EFI_SUCCESS
);
369 Sock
->ConnectionToken
= NULL
;
372 // check to see if some pending send token existed?
374 SockProcessSndToken (Sock
);
380 Wake up the listen token while the connection is established successfully.
382 @param Sock Pointer to the socket.
386 SockWakeListenToken (
391 SOCK_TOKEN
*SockToken
;
392 EFI_TCP4_LISTEN_TOKEN
*ListenToken
;
394 Parent
= Sock
->Parent
;
396 ASSERT ((Parent
!= NULL
) && SOCK_IS_LISTENING (Parent
) && SOCK_IS_CONNECTED (Sock
));
398 if (!IsListEmpty (&Parent
->ListenTokenList
)) {
399 SockToken
= NET_LIST_HEAD (
400 &Parent
->ListenTokenList
,
405 ListenToken
= (EFI_TCP4_LISTEN_TOKEN
*) SockToken
->Token
;
406 ListenToken
->NewChildHandle
= Sock
->SockHandle
;
408 SIGNAL_TOKEN (&(ListenToken
->CompletionToken
), EFI_SUCCESS
);
410 RemoveEntryList (&SockToken
->TokenList
);
411 FreePool (SockToken
);
413 RemoveEntryList (&Sock
->ConnectionList
);
416 DEBUG ((EFI_D_NET
, "SockWakeListenToken: accept a socket, now conncnt is %d", Parent
->ConnCnt
));
424 Wake up the receive token while some data is received.
426 @param Sock Pointer to the socket.
435 UINT32 TokenRcvdBytes
;
436 SOCK_TOKEN
*SockToken
;
437 SOCK_IO_TOKEN
*RcvToken
;
439 ASSERT (Sock
->RcvBuffer
.DataQueue
!= NULL
);
441 RcvdBytes
= (Sock
->RcvBuffer
.DataQueue
)->BufSize
;
443 ASSERT (RcvdBytes
> 0);
445 while (RcvdBytes
> 0 && !IsListEmpty (&Sock
->RcvTokenList
)) {
447 SockToken
= NET_LIST_HEAD (
453 RcvToken
= (SOCK_IO_TOKEN
*) SockToken
->Token
;
454 TokenRcvdBytes
= SockProcessRcvToken (Sock
, RcvToken
);
456 if (0 == TokenRcvdBytes
) {
460 RemoveEntryList (&(SockToken
->TokenList
));
461 FreePool (SockToken
);
462 RcvdBytes
-= TokenRcvdBytes
;
468 Process the send token.
470 @param Sock Pointer to the socket.
474 SockProcessSndToken (
479 SOCK_TOKEN
*SockToken
;
481 SOCK_IO_TOKEN
*SndToken
;
482 EFI_TCP4_TRANSMIT_DATA
*TxData
;
485 ASSERT ((Sock
!= NULL
) && (SockStream
== Sock
->Type
));
487 FreeSpace
= SockGetFreeSpace (Sock
, SOCK_SND_BUF
);
490 // to determine if process a send token using
491 // socket layer flow control policy
493 while ((FreeSpace
>= Sock
->SndBuffer
.LowWater
) &&
494 !IsListEmpty (&Sock
->SndTokenList
)) {
496 SockToken
= NET_LIST_HEAD (
497 &(Sock
->SndTokenList
),
503 // process this token
505 RemoveEntryList (&(SockToken
->TokenList
));
507 &(Sock
->ProcessingSndTokenList
),
508 &(SockToken
->TokenList
)
512 // Proceess it in the light of SockType
514 SndToken
= (SOCK_IO_TOKEN
*) SockToken
->Token
;
515 TxData
= SndToken
->Packet
.TxData
;
517 DataLen
= (UINT32
) TxData
->DataLength
;
518 Status
= SockProcessTcpSndData (Sock
, TxData
);
520 if (EFI_ERROR (Status
)) {
524 if (DataLen
>= FreeSpace
) {
528 FreeSpace
-= DataLen
;
537 RemoveEntryList (&SockToken
->TokenList
);
538 SIGNAL_TOKEN (SockToken
->Token
, Status
);
539 FreePool (SockToken
);
544 Create a socket with initial data SockInitData.
546 @param SockInitData Pointer to the initial data of the socket.
548 @return Pointer to the newly created socket, return NULL when exception occured.
553 IN SOCK_INIT_DATA
*SockInitData
560 ASSERT ((SockInitData
!= NULL
) && (SockInitData
->ProtoHandler
!= NULL
));
561 ASSERT (SockInitData
->Type
== SockStream
);
562 ASSERT ((SockInitData
->ProtoData
!= NULL
) && (SockInitData
->DataSize
<= PROTO_RESERVED_LEN
));
564 Parent
= SockInitData
->Parent
;
566 if ((Parent
!= NULL
) && (Parent
->ConnCnt
== Parent
->BackLog
)) {
569 "SockCreate: Socket parent has "
570 "reached its connection limit with %d ConnCnt and %d BackLog\n",
578 Sock
= AllocateZeroPool (sizeof (SOCKET
));
581 DEBUG ((EFI_D_ERROR
, "SockCreate: No resource to create a new socket\n"));
585 InitializeListHead (&Sock
->Link
);
586 InitializeListHead (&Sock
->ConnectionList
);
587 InitializeListHead (&Sock
->ListenTokenList
);
588 InitializeListHead (&Sock
->RcvTokenList
);
589 InitializeListHead (&Sock
->SndTokenList
);
590 InitializeListHead (&Sock
->ProcessingSndTokenList
);
592 EfiInitializeLock (&(Sock
->Lock
), TPL_CALLBACK
);
594 Sock
->SndBuffer
.DataQueue
= NetbufQueAlloc ();
595 if (NULL
== Sock
->SndBuffer
.DataQueue
) {
596 DEBUG ((EFI_D_ERROR
, "SockCreate: No resource to allocate"
597 " SndBuffer for new socket\n"));
602 Sock
->RcvBuffer
.DataQueue
= NetbufQueAlloc ();
603 if (NULL
== Sock
->RcvBuffer
.DataQueue
) {
604 DEBUG ((EFI_D_ERROR
, "SockCreate: No resource to allocate "
605 "RcvBuffer for new socket\n"));
610 Sock
->Signature
= SOCK_SIGNATURE
;
612 Sock
->Parent
= Parent
;
613 Sock
->BackLog
= SockInitData
->BackLog
;
614 Sock
->ProtoHandler
= SockInitData
->ProtoHandler
;
615 Sock
->SndBuffer
.HighWater
= SockInitData
->SndBufferSize
;
616 Sock
->RcvBuffer
.HighWater
= SockInitData
->RcvBufferSize
;
617 Sock
->Type
= SockInitData
->Type
;
618 Sock
->DriverBinding
= SockInitData
->DriverBinding
;
619 Sock
->State
= SockInitData
->State
;
620 Sock
->CreateCallback
= SockInitData
->CreateCallback
;
621 Sock
->DestroyCallback
= SockInitData
->DestroyCallback
;
622 Sock
->Context
= SockInitData
->Context
;
624 Sock
->SockError
= EFI_ABORTED
;
625 Sock
->SndBuffer
.LowWater
= SOCK_BUFF_LOW_WATER
;
626 Sock
->RcvBuffer
.LowWater
= SOCK_BUFF_LOW_WATER
;
629 // Install protocol on Sock->SockHandle
632 &(Sock
->NetProtocol
.TcpProtocol
),
633 SockInitData
->Protocol
,
634 sizeof (EFI_TCP4_PROTOCOL
)
638 // copy the protodata into socket
640 CopyMem (Sock
->ProtoReserved
, SockInitData
->ProtoData
, SockInitData
->DataSize
);
642 Status
= gBS
->InstallMultipleProtocolInterfaces (
644 &gEfiTcp4ProtocolGuid
,
645 &(Sock
->NetProtocol
.TcpProtocol
),
649 if (EFI_ERROR (Status
)) {
650 DEBUG ((EFI_D_ERROR
, "SockCreate: Install TCP protocol in "
651 "socket failed with %r\n", Status
));
656 if (Parent
!= NULL
) {
657 ASSERT (Parent
->BackLog
> 0);
658 ASSERT (SOCK_IS_LISTENING (Parent
));
661 // need to add it into Parent->ConnectionList
662 // if the Parent->ConnCnt < Parent->BackLog
668 "SockCreate: Create a new socket and add to parent, now conncnt is %d\n",
672 InsertTailList (&Parent
->ConnectionList
, &Sock
->ConnectionList
);
675 if (Sock
->CreateCallback
!= NULL
) {
676 Status
= Sock
->CreateCallback (Sock
, Sock
->Context
);
677 if (EFI_ERROR (Status
)) {
686 if (Sock
->SockHandle
!= NULL
) {
687 gBS
->UninstallMultipleProtocolInterfaces (
689 &gEfiTcp4ProtocolGuid
,
690 &(Sock
->NetProtocol
.TcpProtocol
),
695 if (NULL
!= Sock
->SndBuffer
.DataQueue
) {
696 NetbufQueFree (Sock
->SndBuffer
.DataQueue
);
699 if (NULL
!= Sock
->RcvBuffer
.DataQueue
) {
700 NetbufQueFree (Sock
->RcvBuffer
.DataQueue
);
712 @param Sock Pointer to the socket.
720 ASSERT (SockStream
== Sock
->Type
);
723 // Flush the completion token buffered
724 // by sock and rcv, snd buffer
726 if (!SOCK_IS_UNCONFIGURED (Sock
)) {
728 SockConnFlush (Sock
);
729 SockSetState (Sock
, SO_CLOSED
);
730 Sock
->ConfigureState
= SO_UNCONFIGURED
;
734 // Destroy the RcvBuffer Queue and SendBuffer Queue
736 NetbufQueFree (Sock
->RcvBuffer
.DataQueue
);
737 NetbufQueFree (Sock
->SndBuffer
.DataQueue
);
740 // Remove it from parent connection list if needed
742 if (Sock
->Parent
!= NULL
) {
744 RemoveEntryList (&(Sock
->ConnectionList
));
745 (Sock
->Parent
->ConnCnt
)--;
749 "SockDestroy: Delete a unaccepted socket from parent"
750 "now conncnt is %d\n",
751 Sock
->Parent
->ConnCnt
)
763 Flush the sndBuffer and rcvBuffer of socket.
765 @param Sock Pointer to the socket.
775 ASSERT (Sock
!= NULL
);
778 // Clear the flag in this socket
783 // Flush the SndBuffer and RcvBuffer of Sock
785 NetbufQueFlush (Sock
->SndBuffer
.DataQueue
);
786 NetbufQueFlush (Sock
->RcvBuffer
.DataQueue
);
789 // Signal the pending token
791 if (Sock
->ConnectionToken
!= NULL
) {
792 SIGNAL_TOKEN (Sock
->ConnectionToken
, Sock
->SockError
);
793 Sock
->ConnectionToken
= NULL
;
796 if (Sock
->CloseToken
!= NULL
) {
797 SIGNAL_TOKEN (Sock
->CloseToken
, Sock
->SockError
);
798 Sock
->CloseToken
= NULL
;
801 SockFlushPendingToken (Sock
, &(Sock
->ListenTokenList
));
802 SockFlushPendingToken (Sock
, &(Sock
->RcvTokenList
));
803 SockFlushPendingToken (Sock
, &(Sock
->SndTokenList
));
804 SockFlushPendingToken (Sock
, &(Sock
->ProcessingSndTokenList
));
807 // Destroy the pending connection, if it is a listening socket
809 if (SOCK_IS_LISTENING (Sock
)) {
810 while (!IsListEmpty (&Sock
->ConnectionList
)) {
811 Child
= NET_LIST_HEAD (
812 &Sock
->ConnectionList
,
817 SockDestroyChild (Child
);
828 Set the state of the socket.
830 @param Sock Pointer to the socket.
831 @param State The new socket state to be set.
845 Clone a new socket including its associated protocol control block.
847 @param Sock Pointer to the socket to be cloned.
849 @return Pointer to the newly cloned socket. If NULL, error condition occurred.
858 SOCK_INIT_DATA InitData
;
860 InitData
.BackLog
= Sock
->BackLog
;
861 InitData
.Parent
= Sock
;
862 InitData
.State
= Sock
->State
;
863 InitData
.ProtoHandler
= Sock
->ProtoHandler
;
864 InitData
.Type
= Sock
->Type
;
865 InitData
.RcvBufferSize
= Sock
->RcvBuffer
.HighWater
;
866 InitData
.SndBufferSize
= Sock
->SndBuffer
.HighWater
;
867 InitData
.DriverBinding
= Sock
->DriverBinding
;
868 InitData
.Protocol
= &(Sock
->NetProtocol
);
869 InitData
.CreateCallback
= Sock
->CreateCallback
;
870 InitData
.DestroyCallback
= Sock
->DestroyCallback
;
871 InitData
.Context
= Sock
->Context
;
872 InitData
.ProtoData
= Sock
->ProtoReserved
;
873 InitData
.DataSize
= sizeof (Sock
->ProtoReserved
);
875 ClonedSock
= SockCreate (&InitData
);
877 if (NULL
== ClonedSock
) {
878 DEBUG ((EFI_D_ERROR
, "SockClone: no resource to create a cloned sock\n"));
882 SockSetState (ClonedSock
, SO_CONNECTING
);
883 ClonedSock
->ConfigureState
= Sock
->ConfigureState
;
890 Called by the low layer protocol to indicate the socket a connection is
893 This function just changes the socket's state to SO_CONNECTED
894 and signals the token used for connection establishment.
896 @param Sock Pointer to the socket associated with the
897 established connection.
900 SockConnEstablished (
905 ASSERT (SO_CONNECTING
== Sock
->State
);
907 SockSetState (Sock
, SO_CONNECTED
);
909 if (NULL
== Sock
->Parent
) {
910 SockWakeConnToken (Sock
);
912 SockWakeListenToken (Sock
);
920 Called by the low layer protocol to indicate the connection is closed.
922 This function flushes the socket, sets the state to SO_CLOSED and signals
925 @param Sock Pointer to the socket associated with the closed
934 if (Sock
->CloseToken
!= NULL
) {
935 SIGNAL_TOKEN (Sock
->CloseToken
, EFI_SUCCESS
);
936 Sock
->CloseToken
= NULL
;
939 SockConnFlush (Sock
);
940 SockSetState (Sock
, SO_CLOSED
);
942 if (Sock
->Parent
!= NULL
) {
943 SockDestroyChild (Sock
);
950 Called by low layer protocol to indicate that some data is sent or processed.
952 This function trims the sent data in the socket send buffer, signals the data
955 @param Sock Pointer to the socket.
956 @param Count The length of the data processed or sent, in bytes.
965 SOCK_TOKEN
*SockToken
;
966 SOCK_COMPLETION_TOKEN
*SndToken
;
968 ASSERT (!IsListEmpty (&Sock
->ProcessingSndTokenList
));
969 ASSERT (Count
<= (Sock
->SndBuffer
.DataQueue
)->BufSize
);
971 NetbufQueTrim (Sock
->SndBuffer
.DataQueue
, Count
);
974 // To check if we can signal some snd token in this socket
977 SockToken
= NET_LIST_HEAD (
978 &(Sock
->ProcessingSndTokenList
),
983 SndToken
= SockToken
->Token
;
985 if (SockToken
->RemainDataLen
<= Count
) {
987 RemoveEntryList (&(SockToken
->TokenList
));
988 SIGNAL_TOKEN (SndToken
, EFI_SUCCESS
);
989 Count
-= SockToken
->RemainDataLen
;
990 FreePool (SockToken
);
993 SockToken
->RemainDataLen
-= Count
;
999 // to judge if we can process some send token in
1000 // Sock->SndTokenList, if so process those send token
1002 SockProcessSndToken (Sock
);
1008 Called by the low layer protocol to copy some data in socket send
1009 buffer starting from the specific offset to a buffer provided by
1012 @param Sock Pointer to the socket.
1013 @param Offset The start point of the data to be copied.
1014 @param Len The length of the data to be copied.
1015 @param Dest Pointer to the destination to copy the data.
1017 @return The data size copied.
1028 ASSERT ((Sock
!= NULL
) && SockStream
== Sock
->Type
);
1030 return NetbufQueCopy (
1031 Sock
->SndBuffer
.DataQueue
,
1040 Called by the low layer protocol to deliver received data to socket layer.
1042 This function will append the data to the socket receive buffer, set ther
1043 urgent data length and then check if any receive token can be signaled.
1045 @param Sock Pointer to the socket.
1046 @param NetBuffer Pointer to the buffer that contains the received
1048 @param UrgLen The length of the urgent data in the received data.
1054 IN OUT NET_BUF
*NetBuffer
,
1058 ASSERT ((Sock
!= NULL
) && (Sock
->RcvBuffer
.DataQueue
!= NULL
) &&
1059 UrgLen
<= NetBuffer
->TotalSize
);
1061 NET_GET_REF (NetBuffer
);
1063 ((TCP_RSV_DATA
*) (NetBuffer
->ProtoData
))->UrgLen
= UrgLen
;
1065 NetbufQueAppend (Sock
->RcvBuffer
.DataQueue
, NetBuffer
);
1067 SockWakeRcvToken (Sock
);
1073 Get the length of the free space of the specific socket buffer.
1075 @param Sock Pointer to the socket.
1076 @param Which Flag to indicate which socket buffer to check,
1077 either send buffer or receive buffer.
1079 @return The length of the free space, in bytes.
1089 SOCK_BUFFER
*SockBuffer
;
1091 ASSERT ((Sock
!= NULL
) && ((SOCK_SND_BUF
== Which
) || (SOCK_RCV_BUF
== Which
)));
1093 if (SOCK_SND_BUF
== Which
) {
1094 SockBuffer
= &(Sock
->SndBuffer
);
1096 SockBuffer
= &(Sock
->RcvBuffer
);
1099 BufferCC
= (SockBuffer
->DataQueue
)->BufSize
;
1101 if (BufferCC
>= SockBuffer
->HighWater
) {
1106 return SockBuffer
->HighWater
- BufferCC
;
1112 Called by the low layer protocol to indicate that there will be no more data
1113 from the communication peer.
1115 This function set the socket's state to SO_NO_MORE_DATA and signal all queued
1116 IO tokens with the error status EFI_CONNECTION_FIN.
1118 @param Sock Pointer to the socket.
1128 SOCK_NO_MORE_DATA (Sock
);
1130 if (!IsListEmpty (&Sock
->RcvTokenList
)) {
1132 ASSERT (0 == GET_RCV_DATASIZE (Sock
));
1134 Err
= Sock
->SockError
;
1136 SOCK_ERROR (Sock
, EFI_CONNECTION_FIN
);
1138 SockFlushPendingToken (Sock
, &Sock
->RcvTokenList
);
1140 SOCK_ERROR (Sock
, Err
);
1148 Get the first buffer block in the specific socket buffer.
1150 @param Sockbuf Pointer to the socket buffer.
1152 @return Pointer to the first buffer in the queue. NULL if the queue is empty.
1157 IN SOCK_BUFFER
*Sockbuf
1160 LIST_ENTRY
*NetbufList
;
1162 NetbufList
= &(Sockbuf
->DataQueue
->BufList
);
1164 if (IsListEmpty (NetbufList
)) {
1168 return NET_LIST_HEAD (NetbufList
, NET_BUF
, List
);
1173 Get the next buffer block in the specific socket buffer.
1175 @param Sockbuf Pointer to the socket buffer.
1176 @param SockEntry Pointer to the buffer block prior to the required
1179 @return Pointer to the buffer block next to SockEntry. NULL if SockEntry is
1180 the tail or head entry.
1185 IN SOCK_BUFFER
*Sockbuf
,
1186 IN NET_BUF
*SockEntry
1189 LIST_ENTRY
*NetbufList
;
1191 NetbufList
= &(Sockbuf
->DataQueue
->BufList
);
1193 if ((SockEntry
->List
.ForwardLink
== NetbufList
) ||
1194 (SockEntry
->List
.BackLink
== &SockEntry
->List
) ||
1195 (SockEntry
->List
.ForwardLink
== &SockEntry
->List
)) {
1200 return NET_LIST_USER_STRUCT (SockEntry
->List
.ForwardLink
, NET_BUF
, List
);