]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/BsdSocketLib/send.c
Add Socket Libraries.
[mirror_edk2.git] / StdLib / BsdSocketLib / send.c
CommitLineData
d7ce7006 1/** @file\r
2 Implement the send API.\r
3\r
4 Copyright (c) 2011, Intel Corporation\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <SocketInternals.h>\r
16\r
17\r
18/**\r
19 Send data using a network connection.\r
20\r
21 The ::send routine queues data to the network for transmission.\r
22 The\r
23 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/send.html">POSIX</a>\r
24 documentation is available online.\r
25\r
26 @param [in] s Socket file descriptor returned from ::socket.\r
27\r
28 @param [in] buffer Address of a buffer containing the data to send.\r
29 \r
30 @param [in] length Length of the buffer in bytes.\r
31\r
32 @param [in] flags Message control flags\r
33\r
34 @returns ::send returns the number of data bytes that were\r
35 sent and -1 when an error occurs. In the case of\r
36 an error, errno contains more details.\r
37\r
38 **/\r
39ssize_t\r
40send (\r
41 int s,\r
42 CONST void * buffer,\r
43 size_t length,\r
44 int flags\r
45 )\r
46{\r
47 ssize_t LengthInBytes;\r
48 CONST UINT8 * pData;\r
49 struct __filedes * pDescriptor;\r
50 EFI_SOCKET_PROTOCOL * pSocketProtocol;\r
51 EFI_STATUS Status;\r
52\r
53 //\r
54 // Assume failure\r
55 //\r
56 LengthInBytes = -1;\r
57\r
58 //\r
59 // Locate the context for this socket\r
60 //\r
61 pSocketProtocol = BslFdToSocketProtocol ( s,\r
62 &pDescriptor,\r
63 &errno );\r
64 if ( NULL != pSocketProtocol ) {\r
65 //\r
66 // Send the data using the socket\r
67 //\r
68 pData = buffer;\r
69 do {\r
70 errno = 0;\r
71 Status = pSocketProtocol->pfnSend ( pSocketProtocol,\r
72 flags,\r
73 length,\r
74 pData,\r
75 (size_t *)&LengthInBytes,\r
76 NULL,\r
77 0,\r
78 &errno );\r
79 if ( EFI_ERROR ( Status )) {\r
80 LengthInBytes = -1;\r
81 break;\r
82 }\r
83\r
84 //\r
85 // Account for the data sent\r
86 //\r
87 pData += LengthInBytes;\r
88 length -= LengthInBytes;\r
89 // TODO: Add non-blocking check\r
90 } while (( 0 != length ) && ( EFI_NOT_READY == Status ));\r
91 }\r
92\r
93 //\r
94 // Return the number of data bytes sent, -1 for errors\r
95 //\r
96 return (INT32)LengthInBytes;\r
97}\r