Update the sockets library code
* Passes conformance and functional tests. * Builds with GCC 4.4 compiler. Signed-off by: lpleahy git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12497 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@@ -57,7 +57,7 @@
|
||||
address for the file
|
||||
@param [in] pErrno Address of the errno variable
|
||||
|
||||
@return A pointer to the socket protocol structure or NULL if
|
||||
@return A pointer to the EFI_SOCKET_PROTOCOL structure or NULL if
|
||||
an invalid file descriptor was passed in.
|
||||
|
||||
**/
|
||||
@@ -71,13 +71,17 @@ BslFdToSocketProtocol (
|
||||
/**
|
||||
Close the socket
|
||||
|
||||
@param [in] pDescriptor Descriptor address for the file
|
||||
The BslSocketClose routine is called indirectly from the close file
|
||||
system routine. This routine closes the socket and returns the
|
||||
status to the caller.
|
||||
|
||||
@param[in] pDescriptor Descriptor address for the file
|
||||
|
||||
@return This routine returns 0 upon success and -1 upon failure.
|
||||
In the case of failure, errno contains more information.
|
||||
In the case of failure, ::errno contains more information.
|
||||
|
||||
**/
|
||||
INT32
|
||||
int
|
||||
BslSocketClose (
|
||||
struct __filedes * pDescriptor
|
||||
);
|
||||
@@ -85,9 +89,9 @@ BslSocketClose (
|
||||
/**
|
||||
Worker routine to close the socket.
|
||||
|
||||
@param [in] pSocketProtocol Socket protocol structure address
|
||||
@param[in] pSocketProtocol Socket protocol structure address
|
||||
|
||||
@param [in] pErrno Address of the errno variable
|
||||
@param[in] pErrno Address of the ::errno variable
|
||||
|
||||
@retval EFI_SUCCESS Successfully closed the socket
|
||||
|
||||
@@ -133,12 +137,18 @@ BslSocketProtocolToFd (
|
||||
/**
|
||||
Read support routine for sockets
|
||||
|
||||
The BslSocketRead routine is called indirectly by the read file
|
||||
system routine. This routine is typically used for SOCK_STREAM
|
||||
because it waits for receive data from the target system specified
|
||||
in the ::connect call.
|
||||
|
||||
@param [in] pDescriptor Descriptor address for the file
|
||||
@param [in] pOffset File offset
|
||||
@param [in] LengthInBytes Number of bytes to read
|
||||
@param [in] pBuffer Address of the buffer to receive the data
|
||||
|
||||
@return The number of bytes read or -1 if an error occurs.
|
||||
In the case of an error, ::errno contains more details.
|
||||
|
||||
**/
|
||||
ssize_t
|
||||
@@ -158,6 +168,7 @@ BslSocketRead (
|
||||
@param [in] pBuffer Address of the data
|
||||
|
||||
@return The number of bytes written or -1 if an error occurs.
|
||||
In the case of an error, ::errno contains more details.
|
||||
|
||||
**/
|
||||
ssize_t
|
||||
@@ -175,7 +186,7 @@ BslSocketWrite (
|
||||
|
||||
@param [in] pErrno Address of the errno variable
|
||||
|
||||
@return A pointer to the socket protocol structure or NULL if
|
||||
@return A pointer to the EFI_SOCKET_PROTOCOL structure or NULL if
|
||||
an invalid file descriptor was passed in.
|
||||
|
||||
**/
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/** @file
|
||||
/*
|
||||
Definitions for the socket library functions that are used internally.
|
||||
|
||||
Copyright (c) 2011, Intel Corporation
|
||||
@@ -10,33 +10,33 @@
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
*/
|
||||
|
||||
#ifndef _SOCKLIB_INTERNALS_H_
|
||||
#define _SOCKLIB_INTERNALS_H_
|
||||
|
||||
void _sethosthtent(int);
|
||||
void _endhosthtent(void);
|
||||
void _sethostdnsent(int);
|
||||
void _endhostdnsent(void);
|
||||
void _setnethtent(int);
|
||||
void _endnethtent(void);
|
||||
void _setnetdnsent(int);
|
||||
void _endnetdnsent(void);
|
||||
void _sethosthtent (int);
|
||||
void _endhosthtent (void);
|
||||
void _sethostdnsent (int);
|
||||
void _endhostdnsent (void);
|
||||
void _setnethtent (int);
|
||||
void _endnethtent (void);
|
||||
void _setnetdnsent (int);
|
||||
void _endnetdnsent (void);
|
||||
|
||||
struct hostent * _gethostbyhtname(const char *, int);
|
||||
struct hostent * _gethostbydnsname(const char *, int);
|
||||
struct hostent * _gethostbynisname(const char *, int);
|
||||
struct hostent * _gethostbyhtaddr(const char *, int, int);
|
||||
struct hostent * _gethostbydnsaddr(const char *, int, int);
|
||||
struct hostent * _gethostbynisaddr(const char *, int, int);
|
||||
struct netent * _getnetbyhtname(const char *);
|
||||
struct netent * _getnetbydnsname(const char *);
|
||||
struct netent * _getnetbynisname(const char *);
|
||||
struct netent * _getnetbyhtaddr(unsigned long, int);
|
||||
struct netent * _getnetbydnsaddr(unsigned long, int);
|
||||
struct netent * _getnetbynisaddr(unsigned long, int);
|
||||
void _map_v4v6_address(const char *src, char *dst);
|
||||
void _map_v4v6_hostent(struct hostent *hp, char **bp, int *len);
|
||||
struct hostent * _gethostbyhtname (const char *, int);
|
||||
struct hostent * _gethostbydnsname (const char *, int);
|
||||
struct hostent * _gethostbynisname (const char *, int);
|
||||
struct hostent * _gethostbyhtaddr (const char *, int, int);
|
||||
struct hostent * _gethostbydnsaddr (const char *, int, int);
|
||||
struct hostent * _gethostbynisaddr (const char *, int, int);
|
||||
struct netent * _getnetbyhtname (const char *);
|
||||
struct netent * _getnetbydnsname (const char *);
|
||||
struct netent * _getnetbynisname (const char *);
|
||||
struct netent * _getnetbyhtaddr (unsigned long, int);
|
||||
struct netent * _getnetbydnsaddr (unsigned long, int);
|
||||
struct netent * _getnetbynisaddr (unsigned long, int);
|
||||
void _map_v4v6_address (const char *src, char *dst);
|
||||
void _map_v4v6_hostent (struct hostent *hp, char **bp, int *len);
|
||||
#endif
|
||||
|
||||
|
@@ -16,29 +16,30 @@
|
||||
|
||||
|
||||
/**
|
||||
Worker routine for ::Accept and ::AcceptNB
|
||||
Worker routine for ::accept and ::AcceptNB
|
||||
|
||||
@param [in] s Socket file descriptor returned from ::socket.
|
||||
@param [in] s Socket file descriptor returned from ::socket.
|
||||
|
||||
@param [in] bBlocking TRUE if this is a blocking call
|
||||
@param [in] address Address of a buffer to receive the remote network address.
|
||||
@param [in] bBlockingAllowed TRUE if this is a blocking call
|
||||
@param [in] address Address of a buffer to receive the remote network address.
|
||||
|
||||
@param [in, out] address_len Address of a buffer containing the Length in bytes
|
||||
of the remote network address buffer. Upon return,
|
||||
contains the length of the remote network address.
|
||||
|
||||
@return ::accept returns zero if successful and -1 when an error occurs.
|
||||
In the case of an error, errno contains more details.
|
||||
@return AcceptWork returns zero if successful and -1 when an error occurs.
|
||||
In the case of an error, ::errno contains more details.
|
||||
|
||||
**/
|
||||
int
|
||||
AcceptWork (
|
||||
int s,
|
||||
BOOLEAN bBlocking,
|
||||
BOOLEAN bBlockingAllowed,
|
||||
struct sockaddr * address,
|
||||
socklen_t * address_len
|
||||
)
|
||||
{
|
||||
BOOLEAN bBlocking;
|
||||
INT32 NewSocketFd;
|
||||
struct __filedes * pDescriptor;
|
||||
EFI_SOCKET_PROTOCOL * pNewSocket;
|
||||
@@ -58,8 +59,10 @@ AcceptWork (
|
||||
&errno );
|
||||
if ( NULL != pSocketProtocol ) {
|
||||
//
|
||||
// TODO: Update bBlocking by anding with check for NON_BLOCKING
|
||||
// Determine if the operation is blocking
|
||||
//
|
||||
bBlocking = (BOOLEAN)( 0 == ( pDescriptor->Oflags & O_NONBLOCK ));
|
||||
bBlocking &= bBlockingAllowed;
|
||||
|
||||
//
|
||||
// Attempt to accept a new network connection
|
||||
@@ -75,12 +78,14 @@ AcceptWork (
|
||||
//
|
||||
// Convert the protocol to a socket
|
||||
//
|
||||
NewSocketFd = BslSocketProtocolToFd ( pNewSocket, &errno );
|
||||
if ( -1 == NewSocketFd ) {
|
||||
//
|
||||
// Close the socket
|
||||
//
|
||||
BslSocketCloseWork ( pNewSocket, NULL );
|
||||
if ( !EFI_ERROR ( Status )) {
|
||||
NewSocketFd = BslSocketProtocolToFd ( pNewSocket, &errno );
|
||||
if ( -1 == NewSocketFd ) {
|
||||
//
|
||||
// Close the socket
|
||||
//
|
||||
BslSocketCloseWork ( pNewSocket, NULL );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,9 +99,10 @@ AcceptWork (
|
||||
/**
|
||||
Accept a network connection.
|
||||
|
||||
The ::accept routine waits for a network connection to the socket.
|
||||
It is able to return the remote network address to the caller if
|
||||
requested. The
|
||||
The accept routine waits for a network connection to the socket.
|
||||
It returns the remote network address to the caller if requested.
|
||||
|
||||
The
|
||||
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/accept.html">POSIX</a>
|
||||
documentation is available online.
|
||||
|
||||
@@ -108,8 +114,8 @@ AcceptWork (
|
||||
of the remote network address buffer. Upon return,
|
||||
contains the length of the remote network address.
|
||||
|
||||
@return ::accept returns zero if successful and -1 when an error occurs.
|
||||
In the case of an error, errno contains more details.
|
||||
@return The accept routine returns zero if successful and -1 when an error occurs.
|
||||
In the case of an error, ::errno contains more details.
|
||||
|
||||
**/
|
||||
int
|
||||
@@ -127,9 +133,7 @@ accept (
|
||||
|
||||
|
||||
/**
|
||||
Non blocking version of accept.
|
||||
|
||||
See ::accept
|
||||
Non blocking version of ::accept.
|
||||
|
||||
@param [in] s Socket file descriptor returned from ::socket.
|
||||
|
||||
@@ -140,7 +144,7 @@ accept (
|
||||
contains the length of the remote network address.
|
||||
|
||||
@return This routine returns zero if successful and -1 when an error occurs.
|
||||
In the case of an error, errno contains more details.
|
||||
In the case of an error, ::errno contains more details.
|
||||
|
||||
**/
|
||||
int
|
||||
|
@@ -18,9 +18,11 @@
|
||||
/**
|
||||
Bind a name to a socket.
|
||||
|
||||
The ::bind routine connects a name to a socket on the local machine. The
|
||||
The bind routine connects a name (network address) to a socket on the local machine.
|
||||
|
||||
The
|
||||
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html">POSIX</a>
|
||||
documentation for the bind routine is available online for reference.
|
||||
documentation is available online.
|
||||
|
||||
@param[in] s Socket file descriptor returned from ::socket.
|
||||
|
||||
@@ -37,6 +39,7 @@
|
||||
@param[in] namelen Specifies the length in bytes of the sockaddr structure.
|
||||
|
||||
@return The bind routine returns zero (0) if successful and -1 upon failure.
|
||||
In the case of an error, ::errno contains more information.
|
||||
|
||||
**/
|
||||
int
|
||||
|
@@ -20,7 +20,7 @@
|
||||
|
||||
@param[in] pSocketProtocol Socket protocol structure address
|
||||
|
||||
@param[in] pErrno Address of the errno variable
|
||||
@param[in] pErrno Address of the ::errno variable
|
||||
|
||||
@retval EFI_SUCCESS Successfully closed the socket
|
||||
|
||||
@@ -83,10 +83,14 @@ BslSocketCloseWork (
|
||||
/**
|
||||
Close the socket
|
||||
|
||||
The BslSocketClose routine is called indirectly from the close file
|
||||
system routine. This routine closes the socket and returns the
|
||||
status to the caller.
|
||||
|
||||
@param[in] pDescriptor Descriptor address for the file
|
||||
|
||||
@return This routine returns 0 upon success and -1 upon failure.
|
||||
In the case of failure, errno contains more information.
|
||||
In the case of failure, ::errno contains more information.
|
||||
|
||||
**/
|
||||
int
|
||||
|
@@ -18,11 +18,8 @@
|
||||
/**
|
||||
Connect to a remote system via the network.
|
||||
|
||||
The ::connect routine attempts to establish a connection to a
|
||||
The connect routine attempts to establish a connection to a
|
||||
socket on the local or remote system using the specified address.
|
||||
The
|
||||
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html">POSIX</a>
|
||||
documentation is available online.
|
||||
|
||||
There are three states associated with a connection:
|
||||
<ul>
|
||||
@@ -30,23 +27,27 @@
|
||||
<li>Connection in progress</li>
|
||||
<li>Connected</li>
|
||||
</ul>
|
||||
In the "Not connected" state, calls to ::connect start the connection
|
||||
In the initial "Not connected" state, calls to connect start the connection
|
||||
processing and update the state to "Connection in progress". During
|
||||
the "Connection in progress" state, connect polls for connection completion
|
||||
and moves the state to "Connected" after the connection is established.
|
||||
Note that these states are only visible when the file descriptor is marked
|
||||
with O_NONBLOCK. Also, the POLL_WRITE bit is set when the connection
|
||||
with O_NONBLOCK. Also, the POLLOUT bit is set when the connection
|
||||
completes and may be used by poll or select as an indicator to call
|
||||
connect again.
|
||||
|
||||
The
|
||||
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html">POSIX</a>
|
||||
documentation is available online.
|
||||
|
||||
@param [in] s Socket file descriptor returned from ::socket.
|
||||
|
||||
@param [in] address Network address of the remote system
|
||||
|
||||
@param [in] address_len Length of the remote network address
|
||||
|
||||
@return ::connect returns zero if successful and -1 when an error occurs.
|
||||
In the case of an error, errno contains more details.
|
||||
@return This routine returns zero if successful and -1 when an error occurs.
|
||||
In the case of an error, ::errno contains more details.
|
||||
|
||||
**/
|
||||
int
|
||||
@@ -70,9 +71,9 @@ connect (
|
||||
&errno );
|
||||
if ( NULL != pSocketProtocol ) {
|
||||
//
|
||||
// TODO: Check for NON_BLOCKING
|
||||
// Determine if the operation is blocking
|
||||
//
|
||||
bBlocking = TRUE;
|
||||
bBlocking = (BOOLEAN)( 0 == ( pDescriptor->Oflags & O_NONBLOCK ));
|
||||
|
||||
//
|
||||
// Attempt to connect to a remote system
|
||||
|
@@ -15,4 +15,7 @@
|
||||
#include <sys/errno.h>
|
||||
|
||||
|
||||
/**
|
||||
Variable that contains additional error information when an API call fails.
|
||||
**/
|
||||
int errno;
|
||||
|
@@ -18,7 +18,8 @@
|
||||
/**
|
||||
Get the remote address
|
||||
|
||||
The ::getpeername routine retrieves the remote system address from the socket.
|
||||
The getpeername routine retrieves the remote system address from the socket.
|
||||
|
||||
The
|
||||
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/getpeername.html#">POSIX</a>
|
||||
documentation is available online.
|
||||
@@ -29,8 +30,8 @@
|
||||
|
||||
@param [in] address_len Length of the remote network address structure
|
||||
|
||||
@return ::getpeername returns zero (0) if successful or -1 when an error occurs.
|
||||
In the case of an error, errno contains more details.
|
||||
@return This routine returns zero (0) if successful or -1 when an error occurs.
|
||||
In the case of an error, ::errno contains more details.
|
||||
|
||||
**/
|
||||
int
|
||||
|
@@ -18,7 +18,8 @@
|
||||
/**
|
||||
Get the local socket address.
|
||||
|
||||
The ::getsockname routine retrieves the local system address from the socket.
|
||||
The getsockname routine retrieves the local system address from the socket.
|
||||
|
||||
The
|
||||
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html#">POSIX</a>
|
||||
documentation is available online.
|
||||
@@ -29,8 +30,8 @@
|
||||
|
||||
@param [in] address_len Length of the local network address structure
|
||||
|
||||
@return ::getsockname returns zero (0) if successful or -1 when an error occurs.
|
||||
In the case of an error, errno contains more details.
|
||||
@return This routine returns zero (0) if successful or -1 when an error occurs.
|
||||
In the case of an error, ::errno contains more details.
|
||||
|
||||
**/
|
||||
int
|
||||
|
@@ -18,6 +18,10 @@
|
||||
/**
|
||||
Get the socket options
|
||||
|
||||
The
|
||||
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html#">POSIX</a>
|
||||
documentation is available online.
|
||||
|
||||
@param [in] s Socket file descriptor returned from ::socket.
|
||||
@param [in] level Option protocol level
|
||||
@param [in] option_name Name of the option
|
||||
@@ -25,8 +29,8 @@
|
||||
@param [in,out] option_len Length of the buffer in bytes,
|
||||
upon return length of the option value in bytes
|
||||
|
||||
@retval Zero (0) upon success
|
||||
@retval Minus one (-1) upon failure, errno set with additional error information
|
||||
@return This routine returns zero (0) if successful or -1 when an error occurs.
|
||||
In the case of an error, ::errno contains more details.
|
||||
|
||||
**/
|
||||
int
|
||||
|
@@ -18,20 +18,23 @@
|
||||
/**
|
||||
Establish the known port to listen for network connections.
|
||||
|
||||
The ::listen routine places the port into a state that enables connection
|
||||
The listen routine places the port into a state that enables connection
|
||||
attempts. Connections are placed into FIFO order in a queue to be serviced
|
||||
by the application. The application calls the ::accept routine to remove
|
||||
the next connection from the queue and get the associated socket. The
|
||||
the next connection from the queue and get the associated socket.
|
||||
|
||||
The
|
||||
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html">POSIX</a>
|
||||
documentation for the bind routine is available online for reference.
|
||||
documentation is available online.
|
||||
|
||||
@param [in] s Socket file descriptor returned from ::socket.
|
||||
|
||||
@param [in] backlog backlog specifies the maximum FIFO depth for the connections
|
||||
waiting for the application to call accept. Connection attempts
|
||||
waiting for the application to call ::accept. Connection attempts
|
||||
received while the queue is full are refused.
|
||||
|
||||
@return The listen routine returns zero (0) if successful and -1 upon failure.
|
||||
@return This routine returns zero (0) if successful or -1 when an error occurs.
|
||||
In the case of an error, ::errno contains more details.
|
||||
|
||||
**/
|
||||
int
|
||||
|
@@ -18,12 +18,18 @@
|
||||
/**
|
||||
Read support routine for sockets
|
||||
|
||||
The BslSocketRead routine is called indirectly by the read file
|
||||
system routine. This routine is typically used for SOCK_STREAM
|
||||
because it waits for receive data from the target system specified
|
||||
in the ::connect call.
|
||||
|
||||
@param [in] pDescriptor Descriptor address for the file
|
||||
@param [in] pOffset File offset
|
||||
@param [in] LengthInBytes Number of bytes to read
|
||||
@param [in] pBuffer Address of the buffer to receive the data
|
||||
|
||||
@return The number of bytes read or -1 if an error occurs.
|
||||
In the case of an error, ::errno contains more details.
|
||||
|
||||
**/
|
||||
ssize_t
|
||||
|
@@ -18,8 +18,12 @@
|
||||
/**
|
||||
Receive data from a network connection.
|
||||
|
||||
The ::recv routine waits for receive data from a remote network
|
||||
connection. The
|
||||
The recv routine waits for receive data from a remote network
|
||||
connection. This routine is typically used for SOCK_STREAM
|
||||
because it waits for receive data from the target system specified
|
||||
in the ::connect call.
|
||||
|
||||
The
|
||||
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/recv.html">POSIX</a>
|
||||
documentation is available online.
|
||||
|
||||
@@ -31,9 +35,9 @@
|
||||
|
||||
@param [in] flags Message control flags
|
||||
|
||||
@return ::recv returns the number of valid bytes in the buffer,
|
||||
@return This routine returns the number of valid bytes in the buffer,
|
||||
zero if no data was received, and -1 when an error occurs.
|
||||
In the case of an error, errno contains more details.
|
||||
In the case of an error, ::errno contains more details.
|
||||
|
||||
**/
|
||||
ssize_t
|
||||
|
@@ -18,8 +18,12 @@
|
||||
/**
|
||||
Receive data from a network connection and return the remote system's address.
|
||||
|
||||
The ::recvfrom routine waits for receive data from a remote network
|
||||
connection. The
|
||||
The recvfrom routine waits for receive data from a remote network
|
||||
connection. This routine is typically called for SOCK_DGRAM sockets
|
||||
when the socket is being shared by multiple remote systems and it is
|
||||
important to get the remote system address for a response.
|
||||
|
||||
The
|
||||
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/recv.html">POSIX</a>
|
||||
documentation is available online.
|
||||
|
||||
@@ -35,9 +39,9 @@
|
||||
|
||||
@param [in] address_len Length of the remote network address structure
|
||||
|
||||
@return ::recvfrom returns the number of valid bytes in the buffer,
|
||||
@return This routine returns the number of valid bytes in the buffer,
|
||||
zero if no data was received, and -1 when an error occurs.
|
||||
In the case of an error, errno contains more details.
|
||||
In the case of an error, ::errno contains more details.
|
||||
|
||||
**/
|
||||
ssize_t
|
||||
|
@@ -767,7 +767,7 @@ read_len:
|
||||
errno = 0;
|
||||
fromlen = sizeof(struct sockaddr_in);
|
||||
resplen = (int)recvfrom(s, (char*)ans, anssiz, 0,
|
||||
(struct sockaddr *)&from, &fromlen);
|
||||
(struct sockaddr *)&from, (socklen_t *)&fromlen);
|
||||
if (resplen <= 0) {
|
||||
Perror(stderr, "recvfrom", errno);
|
||||
res_close();
|
||||
|
@@ -18,7 +18,10 @@
|
||||
/**
|
||||
Send data using a network connection.
|
||||
|
||||
The ::send routine queues data to the network for transmission.
|
||||
The send routine queues data to the network for transmission.
|
||||
This routine is typically used for SOCK_STREAM sockets where the target
|
||||
system was specified in the ::connect call.
|
||||
|
||||
The
|
||||
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/send.html">POSIX</a>
|
||||
documentation is available online.
|
||||
@@ -31,9 +34,9 @@
|
||||
|
||||
@param [in] flags Message control flags
|
||||
|
||||
@return ::send returns the number of data bytes that were
|
||||
@return This routine returns the number of data bytes that were
|
||||
sent and -1 when an error occurs. In the case of
|
||||
an error, errno contains more details.
|
||||
an error, ::errno contains more details.
|
||||
|
||||
**/
|
||||
ssize_t
|
||||
|
@@ -18,7 +18,11 @@
|
||||
/**
|
||||
Send data using a network connection.
|
||||
|
||||
The ::send routine queues data to the network for transmission.
|
||||
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.
|
||||
|
||||
The
|
||||
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/send.html">POSIX</a>
|
||||
documentation is available online.
|
||||
@@ -35,9 +39,9 @@
|
||||
|
||||
@param [in] tolen Length of remote system address structure
|
||||
|
||||
@return ::send returns the number of data bytes that were
|
||||
@return This routine returns the number of data bytes that were
|
||||
sent and -1 when an error occurs. In the case of
|
||||
an error, errno contains more details.
|
||||
an error, ::errno contains more details.
|
||||
|
||||
**/
|
||||
ssize_t
|
||||
@@ -50,6 +54,7 @@ sendto (
|
||||
socklen_t tolen
|
||||
)
|
||||
{
|
||||
BOOLEAN bBlocking;
|
||||
ssize_t LengthInBytes;
|
||||
CONST UINT8 * pData;
|
||||
struct __filedes * pDescriptor;
|
||||
@@ -68,20 +73,25 @@ sendto (
|
||||
&pDescriptor,
|
||||
&errno );
|
||||
if ( NULL != pSocketProtocol ) {
|
||||
//
|
||||
// Determine if the operation is blocking
|
||||
//
|
||||
bBlocking = (BOOLEAN)( 0 == ( pDescriptor->Oflags & O_NONBLOCK ));
|
||||
|
||||
//
|
||||
// Send the data using the socket
|
||||
//
|
||||
pData = buffer;
|
||||
do {
|
||||
errno = 0;
|
||||
Status = pSocketProtocol->pfnSend ( pSocketProtocol,
|
||||
flags,
|
||||
length,
|
||||
pData,
|
||||
(size_t *)&LengthInBytes,
|
||||
to,
|
||||
tolen,
|
||||
&errno );
|
||||
Status = pSocketProtocol->pfnTransmit ( pSocketProtocol,
|
||||
flags,
|
||||
length,
|
||||
pData,
|
||||
(size_t *)&LengthInBytes,
|
||||
to,
|
||||
tolen,
|
||||
&errno );
|
||||
if ( EFI_ERROR ( Status ) && ( EFI_NOT_READY != Status )) {
|
||||
LengthInBytes = -1;
|
||||
break;
|
||||
@@ -92,8 +102,7 @@ sendto (
|
||||
//
|
||||
pData += LengthInBytes;
|
||||
length -= LengthInBytes;
|
||||
// TODO: Add non-blocking check
|
||||
} while (( 0 != length ) && ( EFI_NOT_READY == Status ));
|
||||
} while (( 0 != length ) && ( EFI_NOT_READY == Status ) && bBlocking );
|
||||
}
|
||||
|
||||
//
|
||||
|
@@ -97,7 +97,7 @@ Returns:
|
||||
// Create a zero terminated string for name
|
||||
//
|
||||
memcpy ( pName, name, namelen );
|
||||
pName [ namelen ] = 0;
|
||||
pName[ namelen ] = 0;
|
||||
|
||||
//
|
||||
// Set the environment variable
|
||||
|
@@ -18,14 +18,18 @@
|
||||
/**
|
||||
Set the socket options
|
||||
|
||||
The
|
||||
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html">POSIX</a>
|
||||
documentation is available online.
|
||||
|
||||
@param [in] s Socket file descriptor returned from ::socket.
|
||||
@param [in] level Option protocol level
|
||||
@param [in] option_name Name of the option
|
||||
@param [in] option_value Buffer containing the option value
|
||||
@param [in] option_len Length of the value in bytes
|
||||
|
||||
@retval Zero (0) upon success
|
||||
@retval Minus one (-1) upon failure, errno set with additional error information
|
||||
@return This routine returns zero (0) upon success and -1 when an error occurs.
|
||||
In the case of an error, ::errno contains more details.
|
||||
|
||||
**/
|
||||
int
|
||||
|
@@ -18,7 +18,8 @@
|
||||
/**
|
||||
Shutdown the socket receive and transmit operations
|
||||
|
||||
The ::shutdown routine stops socket receive and transmit operations.
|
||||
The shutdown routine stops socket receive and transmit operations.
|
||||
|
||||
The
|
||||
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/shutdown.html">POSIX</a>
|
||||
documentation is available online.
|
||||
@@ -27,8 +28,8 @@
|
||||
|
||||
@param [in] how Which operations to shutdown
|
||||
|
||||
@return ::shutdown returns the zero (0) if successful or -1 when an
|
||||
error occurs. In the latter case, errno contains more details.
|
||||
@return This routine returns the zero (0) if successful or -1 when an
|
||||
error occurs. In the latter case, ::errno contains more details.
|
||||
|
||||
**/
|
||||
int
|
||||
|
@@ -15,6 +15,12 @@
|
||||
#include <SocketInternals.h>
|
||||
|
||||
|
||||
/**
|
||||
File system interface for the socket layer.
|
||||
|
||||
This data structure defines the routines for the various
|
||||
file system functions associated with the socket layer.
|
||||
**/
|
||||
const struct fileops SocketOperations = {
|
||||
BslSocketClose, // close
|
||||
BslSocketRead, // read
|
||||
@@ -47,7 +53,7 @@ const struct fileops SocketOperations = {
|
||||
address for the file
|
||||
@param [in] pErrno Address of the errno variable
|
||||
|
||||
@return A pointer to the socket protocol structure or NULL if
|
||||
@return A pointer to the EFI_SOCKET_PROTOCOL structure or NULL if
|
||||
an invalid file descriptor was passed in.
|
||||
|
||||
**/
|
||||
@@ -79,7 +85,7 @@ BslFdToSocketProtocol (
|
||||
//
|
||||
// Get the descriptor for the file
|
||||
//
|
||||
pDescriptor = &gMD->fdarray [ s ];
|
||||
pDescriptor = &gMD->fdarray[ s ];
|
||||
|
||||
//
|
||||
// Validate that the descriptor is associated with sockets
|
||||
@@ -125,7 +131,7 @@ BslSocketProtocolToFd (
|
||||
// Locate a file descriptor
|
||||
//
|
||||
FileDescriptor = FindFreeFD ( VALID_CLOSED );
|
||||
if( FileDescriptor < 0 ) {
|
||||
if ( FileDescriptor < 0 ) {
|
||||
//
|
||||
// All available FDs are in use
|
||||
//
|
||||
@@ -135,7 +141,7 @@ BslSocketProtocolToFd (
|
||||
//
|
||||
// Initialize the file descriptor
|
||||
//
|
||||
pDescriptor = &gMD->fdarray [ FileDescriptor ];
|
||||
pDescriptor = &gMD->fdarray[ FileDescriptor ];
|
||||
pDescriptor->f_offset = 0;
|
||||
pDescriptor->f_flag = 0;
|
||||
pDescriptor->f_iflags = DTYPE_SOCKET;
|
||||
@@ -162,28 +168,33 @@ BslSocketProtocolToFd (
|
||||
/**
|
||||
Creates an endpoint for network communication.
|
||||
|
||||
The ::Socket routine initializes the communication endpoint by providing
|
||||
the support for the socket library function ::socket. The
|
||||
The socket routine initializes the communication endpoint and returns a
|
||||
file descriptor.
|
||||
|
||||
The
|
||||
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html">POSIX</a>
|
||||
documentation for the socket routine is available online for reference.
|
||||
documentation is available online.
|
||||
|
||||
@param [in] domain Select the family of protocols for the client or server
|
||||
application.
|
||||
application. The supported values are:
|
||||
<ul>
|
||||
<li>AF_INET - Version 4 UEFI network stack</li>
|
||||
</ul>
|
||||
|
||||
@param [in] type Specifies how to make the network connection. The following values
|
||||
are supported:
|
||||
<ul>
|
||||
<li>
|
||||
SOCK_DGRAM - Connect to UDP, provides a datagram service that is
|
||||
manipulated by recvfrom and sendto.
|
||||
</li>
|
||||
<li>
|
||||
SOCK_STREAM - Connect to TCP, provides a byte stream
|
||||
that is manipluated by read, recv, send and write.
|
||||
</li>
|
||||
<li>
|
||||
SOCK_SEQPACKET - Connect to TCP, provides sequenced packet stream
|
||||
that is manipulated by read, recv, send and write.
|
||||
</li>
|
||||
<li>
|
||||
SOCK_DGRAM - Connect to UDP, provides a datagram service that is
|
||||
manipulated by recvfrom and sendto.
|
||||
SOCK_RAW - Connect to IP, provides a datagram service that
|
||||
is manipulated by recvfrom and sendto.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@@ -192,9 +203,14 @@ BslSocketProtocolToFd (
|
||||
<ul>
|
||||
<li>IPPROTO_TCP</li> - This value must be combined with SOCK_STREAM.</li>
|
||||
<li>IPPROTO_UDP</li> - This value must be combined with SOCK_DGRAM.</li>
|
||||
<li>0 - 254</li> - An assigned
|
||||
<a href="http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xml">protocol number</a>
|
||||
is combined with SOCK_RAW.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@return This routine returns a file descriptor for the socket.
|
||||
@return This routine returns a file descriptor for the socket. If an error
|
||||
occurs -1 is returned and ::errno contains more details.
|
||||
|
||||
**/
|
||||
INT32
|
||||
@@ -226,8 +242,7 @@ socket (
|
||||
type,
|
||||
protocol,
|
||||
&errno );
|
||||
if ( !EFI_ERROR ( Status ))
|
||||
{
|
||||
if ( !EFI_ERROR ( Status )) {
|
||||
//
|
||||
// Build the file descriptor for the socket
|
||||
//
|
||||
@@ -250,7 +265,7 @@ socket (
|
||||
|
||||
@param [in] pErrno Address of the errno variable
|
||||
|
||||
@return A pointer to the socket protocol structure or NULL if
|
||||
@return A pointer to the EFI_SOCKET_PROTOCOL structure or NULL if
|
||||
an invalid file descriptor was passed in.
|
||||
|
||||
**/
|
||||
|
@@ -24,6 +24,7 @@
|
||||
@param [in] pBuffer Address of the data
|
||||
|
||||
@return The number of bytes written or -1 if an error occurs.
|
||||
In the case of an error, ::errno contains more details.
|
||||
|
||||
**/
|
||||
ssize_t
|
||||
|
Reference in New Issue
Block a user