]>
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 | |
a88c3163 | 21 | The sendto routine queues data to the network for transmission.\r |
22 | This routine is typically used for SOCK_DGRAM sockets that are shared\r | |
23 | between multiple machine where it is required to specify the target\r | |
24 | system address when sending the data.\r | |
25 | \r | |
d7ce7006 | 26 | The\r |
27 | <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/send.html">POSIX</a>\r | |
28 | documentation is available online.\r | |
29 | \r | |
30 | @param [in] s Socket file descriptor returned from ::socket.\r | |
31 | \r | |
32 | @param [in] buffer Address of a buffer containing the data to send.\r | |
7dc13291 | 33 | \r |
d7ce7006 | 34 | @param [in] length Length of the buffer in bytes.\r |
35 | \r | |
36 | @param [in] flags Message control flags\r | |
37 | \r | |
38 | @param [in] to Remote system address\r | |
39 | \r | |
40 | @param [in] tolen Length of remote system address structure\r | |
41 | \r | |
a88c3163 | 42 | @return This routine returns the number of data bytes that were\r |
d7ce7006 | 43 | sent and -1 when an error occurs. In the case of\r |
a88c3163 | 44 | an error, ::errno contains more details.\r |
d7ce7006 | 45 | \r |
46 | **/\r | |
47 | ssize_t\r | |
48 | sendto (\r | |
49 | int s,\r | |
50 | const void * buffer,\r | |
51 | size_t length,\r | |
52 | int flags,\r | |
53 | const struct sockaddr * to,\r | |
54 | socklen_t tolen\r | |
55 | )\r | |
56 | {\r | |
a88c3163 | 57 | BOOLEAN bBlocking;\r |
d7ce7006 | 58 | ssize_t LengthInBytes;\r |
59 | CONST UINT8 * pData;\r | |
60 | struct __filedes * pDescriptor;\r | |
61 | EFI_SOCKET_PROTOCOL * pSocketProtocol;\r | |
62 | EFI_STATUS Status;\r | |
63 | \r | |
64 | //\r | |
65 | // Assume failure\r | |
66 | //\r | |
67 | LengthInBytes = -1;\r | |
68 | \r | |
69 | //\r | |
70 | // Locate the context for this socket\r | |
71 | //\r | |
72 | pSocketProtocol = BslFdToSocketProtocol ( s,\r | |
73 | &pDescriptor,\r | |
74 | &errno );\r | |
75 | if ( NULL != pSocketProtocol ) {\r | |
a88c3163 | 76 | //\r |
77 | // Determine if the operation is blocking\r | |
78 | //\r | |
79 | bBlocking = (BOOLEAN)( 0 == ( pDescriptor->Oflags & O_NONBLOCK ));\r | |
80 | \r | |
d7ce7006 | 81 | //\r |
82 | // Send the data using the socket\r | |
83 | //\r | |
84 | pData = buffer;\r | |
85 | do {\r | |
86 | errno = 0;\r | |
a88c3163 | 87 | Status = pSocketProtocol->pfnTransmit ( pSocketProtocol,\r |
88 | flags,\r | |
89 | length,\r | |
90 | pData,\r | |
91 | (size_t *)&LengthInBytes,\r | |
92 | to,\r | |
93 | tolen,\r | |
94 | &errno );\r | |
486aace4 | 95 | if ( EFI_ERROR ( Status ) && ( EFI_NOT_READY != Status )) {\r |
d7ce7006 | 96 | LengthInBytes = -1;\r |
97 | break;\r | |
98 | }\r | |
99 | \r | |
100 | //\r | |
101 | // Account for the data sent\r | |
102 | //\r | |
103 | pData += LengthInBytes;\r | |
104 | length -= LengthInBytes;\r | |
a88c3163 | 105 | } while (( 0 != length ) && ( EFI_NOT_READY == Status ) && bBlocking );\r |
d7ce7006 | 106 | }\r |
107 | \r | |
108 | //\r | |
109 | // Return the number of data bytes sent, -1 for errors\r | |
110 | //\r | |
111 | return (INT32)LengthInBytes;\r | |
112 | }\r |