Add Socket Libraries.
Add Posix functions for porting compatibility.
Fix compliance issues with ISO/IEC 9899:199409
New Functions:
setenv(), fparseln(), GetFileNameFromPath(), rename(),
realpath(), setprogname(), getprogname(), strlcat(), strlcpy(),
strsep(), setitimer(), getitimer(), timegm(), getopt(), basename(),
mkstemp(), ffs(), vsnprintf(), snprintf(), getpass(), usleep(), select(),
writev(), strcasecmp(), getcwd(), chdir(), tcgetpgrp(), getpgrp(), gettimeofday(),
bcopy(),
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12061 6f19259b-4bc3-4df7-8a09-765794883524
2011-07-30 02:30:44 +02:00
|
|
|
/** @file
|
|
|
|
Implement the sendto API.
|
|
|
|
|
|
|
|
Copyright (c) 2011, Intel Corporation
|
|
|
|
All rights reserved. This program and the accompanying materials
|
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <SocketInternals.h>
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Send data using a network connection.
|
|
|
|
|
2011-10-01 01:02:35 +02:00
|
|
|
The sendto routine queues data to the network for transmission.
|
|
|
|
This routine is typically used for SOCK_DGRAM sockets that are shared
|
|
|
|
between multiple machine where it is required to specify the target
|
|
|
|
system address when sending the data.
|
|
|
|
|
Add Socket Libraries.
Add Posix functions for porting compatibility.
Fix compliance issues with ISO/IEC 9899:199409
New Functions:
setenv(), fparseln(), GetFileNameFromPath(), rename(),
realpath(), setprogname(), getprogname(), strlcat(), strlcpy(),
strsep(), setitimer(), getitimer(), timegm(), getopt(), basename(),
mkstemp(), ffs(), vsnprintf(), snprintf(), getpass(), usleep(), select(),
writev(), strcasecmp(), getcwd(), chdir(), tcgetpgrp(), getpgrp(), gettimeofday(),
bcopy(),
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12061 6f19259b-4bc3-4df7-8a09-765794883524
2011-07-30 02:30:44 +02:00
|
|
|
The
|
|
|
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/send.html">POSIX</a>
|
|
|
|
documentation is available online.
|
|
|
|
|
|
|
|
@param [in] s Socket file descriptor returned from ::socket.
|
|
|
|
|
|
|
|
@param [in] buffer Address of a buffer containing the data to send.
|
2011-08-06 01:57:34 +02:00
|
|
|
|
Add Socket Libraries.
Add Posix functions for porting compatibility.
Fix compliance issues with ISO/IEC 9899:199409
New Functions:
setenv(), fparseln(), GetFileNameFromPath(), rename(),
realpath(), setprogname(), getprogname(), strlcat(), strlcpy(),
strsep(), setitimer(), getitimer(), timegm(), getopt(), basename(),
mkstemp(), ffs(), vsnprintf(), snprintf(), getpass(), usleep(), select(),
writev(), strcasecmp(), getcwd(), chdir(), tcgetpgrp(), getpgrp(), gettimeofday(),
bcopy(),
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12061 6f19259b-4bc3-4df7-8a09-765794883524
2011-07-30 02:30:44 +02:00
|
|
|
@param [in] length Length of the buffer in bytes.
|
|
|
|
|
|
|
|
@param [in] flags Message control flags
|
|
|
|
|
|
|
|
@param [in] to Remote system address
|
|
|
|
|
|
|
|
@param [in] tolen Length of remote system address structure
|
|
|
|
|
2011-10-01 01:02:35 +02:00
|
|
|
@return This routine returns the number of data bytes that were
|
Add Socket Libraries.
Add Posix functions for porting compatibility.
Fix compliance issues with ISO/IEC 9899:199409
New Functions:
setenv(), fparseln(), GetFileNameFromPath(), rename(),
realpath(), setprogname(), getprogname(), strlcat(), strlcpy(),
strsep(), setitimer(), getitimer(), timegm(), getopt(), basename(),
mkstemp(), ffs(), vsnprintf(), snprintf(), getpass(), usleep(), select(),
writev(), strcasecmp(), getcwd(), chdir(), tcgetpgrp(), getpgrp(), gettimeofday(),
bcopy(),
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12061 6f19259b-4bc3-4df7-8a09-765794883524
2011-07-30 02:30:44 +02:00
|
|
|
sent and -1 when an error occurs. In the case of
|
2011-10-01 01:02:35 +02:00
|
|
|
an error, ::errno contains more details.
|
Add Socket Libraries.
Add Posix functions for porting compatibility.
Fix compliance issues with ISO/IEC 9899:199409
New Functions:
setenv(), fparseln(), GetFileNameFromPath(), rename(),
realpath(), setprogname(), getprogname(), strlcat(), strlcpy(),
strsep(), setitimer(), getitimer(), timegm(), getopt(), basename(),
mkstemp(), ffs(), vsnprintf(), snprintf(), getpass(), usleep(), select(),
writev(), strcasecmp(), getcwd(), chdir(), tcgetpgrp(), getpgrp(), gettimeofday(),
bcopy(),
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12061 6f19259b-4bc3-4df7-8a09-765794883524
2011-07-30 02:30:44 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
ssize_t
|
|
|
|
sendto (
|
|
|
|
int s,
|
|
|
|
const void * buffer,
|
|
|
|
size_t length,
|
|
|
|
int flags,
|
|
|
|
const struct sockaddr * to,
|
|
|
|
socklen_t tolen
|
|
|
|
)
|
|
|
|
{
|
2011-10-01 01:02:35 +02:00
|
|
|
BOOLEAN bBlocking;
|
Add Socket Libraries.
Add Posix functions for porting compatibility.
Fix compliance issues with ISO/IEC 9899:199409
New Functions:
setenv(), fparseln(), GetFileNameFromPath(), rename(),
realpath(), setprogname(), getprogname(), strlcat(), strlcpy(),
strsep(), setitimer(), getitimer(), timegm(), getopt(), basename(),
mkstemp(), ffs(), vsnprintf(), snprintf(), getpass(), usleep(), select(),
writev(), strcasecmp(), getcwd(), chdir(), tcgetpgrp(), getpgrp(), gettimeofday(),
bcopy(),
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12061 6f19259b-4bc3-4df7-8a09-765794883524
2011-07-30 02:30:44 +02:00
|
|
|
ssize_t LengthInBytes;
|
|
|
|
CONST UINT8 * pData;
|
|
|
|
struct __filedes * pDescriptor;
|
|
|
|
EFI_SOCKET_PROTOCOL * pSocketProtocol;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Assume failure
|
|
|
|
//
|
|
|
|
LengthInBytes = -1;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Locate the context for this socket
|
|
|
|
//
|
|
|
|
pSocketProtocol = BslFdToSocketProtocol ( s,
|
|
|
|
&pDescriptor,
|
|
|
|
&errno );
|
|
|
|
if ( NULL != pSocketProtocol ) {
|
2011-10-01 01:02:35 +02:00
|
|
|
//
|
|
|
|
// Determine if the operation is blocking
|
|
|
|
//
|
|
|
|
bBlocking = (BOOLEAN)( 0 == ( pDescriptor->Oflags & O_NONBLOCK ));
|
|
|
|
|
Add Socket Libraries.
Add Posix functions for porting compatibility.
Fix compliance issues with ISO/IEC 9899:199409
New Functions:
setenv(), fparseln(), GetFileNameFromPath(), rename(),
realpath(), setprogname(), getprogname(), strlcat(), strlcpy(),
strsep(), setitimer(), getitimer(), timegm(), getopt(), basename(),
mkstemp(), ffs(), vsnprintf(), snprintf(), getpass(), usleep(), select(),
writev(), strcasecmp(), getcwd(), chdir(), tcgetpgrp(), getpgrp(), gettimeofday(),
bcopy(),
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12061 6f19259b-4bc3-4df7-8a09-765794883524
2011-07-30 02:30:44 +02:00
|
|
|
//
|
|
|
|
// Send the data using the socket
|
|
|
|
//
|
|
|
|
pData = buffer;
|
|
|
|
do {
|
|
|
|
errno = 0;
|
2011-10-01 01:02:35 +02:00
|
|
|
Status = pSocketProtocol->pfnTransmit ( pSocketProtocol,
|
|
|
|
flags,
|
|
|
|
length,
|
|
|
|
pData,
|
|
|
|
(size_t *)&LengthInBytes,
|
|
|
|
to,
|
|
|
|
tolen,
|
|
|
|
&errno );
|
2011-08-03 19:45:52 +02:00
|
|
|
if ( EFI_ERROR ( Status ) && ( EFI_NOT_READY != Status )) {
|
Add Socket Libraries.
Add Posix functions for porting compatibility.
Fix compliance issues with ISO/IEC 9899:199409
New Functions:
setenv(), fparseln(), GetFileNameFromPath(), rename(),
realpath(), setprogname(), getprogname(), strlcat(), strlcpy(),
strsep(), setitimer(), getitimer(), timegm(), getopt(), basename(),
mkstemp(), ffs(), vsnprintf(), snprintf(), getpass(), usleep(), select(),
writev(), strcasecmp(), getcwd(), chdir(), tcgetpgrp(), getpgrp(), gettimeofday(),
bcopy(),
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12061 6f19259b-4bc3-4df7-8a09-765794883524
2011-07-30 02:30:44 +02:00
|
|
|
LengthInBytes = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Account for the data sent
|
|
|
|
//
|
|
|
|
pData += LengthInBytes;
|
|
|
|
length -= LengthInBytes;
|
2011-10-01 01:02:35 +02:00
|
|
|
} while (( 0 != length ) && ( EFI_NOT_READY == Status ) && bBlocking );
|
Add Socket Libraries.
Add Posix functions for porting compatibility.
Fix compliance issues with ISO/IEC 9899:199409
New Functions:
setenv(), fparseln(), GetFileNameFromPath(), rename(),
realpath(), setprogname(), getprogname(), strlcat(), strlcpy(),
strsep(), setitimer(), getitimer(), timegm(), getopt(), basename(),
mkstemp(), ffs(), vsnprintf(), snprintf(), getpass(), usleep(), select(),
writev(), strcasecmp(), getcwd(), chdir(), tcgetpgrp(), getpgrp(), gettimeofday(),
bcopy(),
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12061 6f19259b-4bc3-4df7-8a09-765794883524
2011-07-30 02:30:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Return the number of data bytes sent, -1 for errors
|
|
|
|
//
|
|
|
|
return (INT32)LengthInBytes;
|
|
|
|
}
|