]>
Commit | Line | Data |
---|---|---|
d7ce7006 | 1 | /** @file\r |
2 | Implement the sendto 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 | |
7dc13291 | 29 | \r |
d7ce7006 | 30 | @param [in] length Length of the buffer in bytes.\r |
31 | \r | |
32 | @param [in] flags Message control flags\r | |
33 | \r | |
34 | @param [in] to Remote system address\r | |
35 | \r | |
36 | @param [in] tolen Length of remote system address structure\r | |
37 | \r | |
7dc13291 | 38 | @return ::send returns the number of data bytes that were\r |
d7ce7006 | 39 | sent and -1 when an error occurs. In the case of\r |
40 | an error, errno contains more details.\r | |
41 | \r | |
42 | **/\r | |
43 | ssize_t\r | |
44 | sendto (\r | |
45 | int s,\r | |
46 | const void * buffer,\r | |
47 | size_t length,\r | |
48 | int flags,\r | |
49 | const struct sockaddr * to,\r | |
50 | socklen_t tolen\r | |
51 | )\r | |
52 | {\r | |
53 | ssize_t LengthInBytes;\r | |
54 | CONST UINT8 * pData;\r | |
55 | struct __filedes * pDescriptor;\r | |
56 | EFI_SOCKET_PROTOCOL * pSocketProtocol;\r | |
57 | EFI_STATUS Status;\r | |
58 | \r | |
59 | //\r | |
60 | // Assume failure\r | |
61 | //\r | |
62 | LengthInBytes = -1;\r | |
63 | \r | |
64 | //\r | |
65 | // Locate the context for this socket\r | |
66 | //\r | |
67 | pSocketProtocol = BslFdToSocketProtocol ( s,\r | |
68 | &pDescriptor,\r | |
69 | &errno );\r | |
70 | if ( NULL != pSocketProtocol ) {\r | |
71 | //\r | |
72 | // Send the data using the socket\r | |
73 | //\r | |
74 | pData = buffer;\r | |
75 | do {\r | |
76 | errno = 0;\r | |
77 | Status = pSocketProtocol->pfnSend ( pSocketProtocol,\r | |
78 | flags,\r | |
79 | length,\r | |
80 | pData,\r | |
81 | (size_t *)&LengthInBytes,\r | |
82 | to,\r | |
83 | tolen,\r | |
84 | &errno );\r | |
486aace4 | 85 | if ( EFI_ERROR ( Status ) && ( EFI_NOT_READY != Status )) {\r |
d7ce7006 | 86 | LengthInBytes = -1;\r |
87 | break;\r | |
88 | }\r | |
89 | \r | |
90 | //\r | |
91 | // Account for the data sent\r | |
92 | //\r | |
93 | pData += LengthInBytes;\r | |
94 | length -= LengthInBytes;\r | |
95 | // TODO: Add non-blocking check\r | |
96 | } while (( 0 != length ) && ( EFI_NOT_READY == Status ));\r | |
97 | }\r | |
98 | \r | |
99 | //\r | |
100 | // Return the number of data bytes sent, -1 for errors\r | |
101 | //\r | |
102 | return (INT32)LengthInBytes;\r | |
103 | }\r |