summaryrefslogtreecommitdiffstats
path: root/StdLib/BsdSocketLib
diff options
context:
space:
mode:
authorlpleahy <lpleahy@6f19259b-4bc3-4df7-8a09-765794883524>2011-09-30 23:02:35 +0000
committerlpleahy <lpleahy@6f19259b-4bc3-4df7-8a09-765794883524>2011-09-30 23:02:35 +0000
commita88c31639bb24c73383a4528a5b77066e805148b (patch)
tree058801cd8687b0a0c6f82459b56b2ad3beb43bf4 /StdLib/BsdSocketLib
parentdf7499fcc1fbd6c825cabf19bbed379688416125 (diff)
downloadedk2-a88c31639bb24c73383a4528a5b77066e805148b.tar.gz
edk2-a88c31639bb24c73383a4528a5b77066e805148b.tar.bz2
edk2-a88c31639bb24c73383a4528a5b77066e805148b.zip
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
Diffstat (limited to 'StdLib/BsdSocketLib')
-rw-r--r--StdLib/BsdSocketLib/SocketInternals.h25
-rw-r--r--StdLib/BsdSocketLib/Socklib_internals.h48
-rw-r--r--StdLib/BsdSocketLib/accept.c50
-rw-r--r--StdLib/BsdSocketLib/bind.c7
-rw-r--r--StdLib/BsdSocketLib/close.c8
-rw-r--r--StdLib/BsdSocketLib/connect.c21
-rw-r--r--StdLib/BsdSocketLib/errno.c3
-rw-r--r--StdLib/BsdSocketLib/getpeername.c7
-rw-r--r--StdLib/BsdSocketLib/getsockname.c7
-rw-r--r--StdLib/BsdSocketLib/getsockopt.c8
-rw-r--r--StdLib/BsdSocketLib/listen.c13
-rw-r--r--StdLib/BsdSocketLib/read.c6
-rw-r--r--StdLib/BsdSocketLib/recv.c12
-rw-r--r--StdLib/BsdSocketLib/recvfrom.c12
-rw-r--r--StdLib/BsdSocketLib/res_send.c2
-rw-r--r--StdLib/BsdSocketLib/send.c9
-rw-r--r--StdLib/BsdSocketLib/sendto.c35
-rw-r--r--StdLib/BsdSocketLib/sethostname.c2
-rw-r--r--StdLib/BsdSocketLib/setsockopt.c8
-rw-r--r--StdLib/BsdSocketLib/shutdown.c7
-rw-r--r--StdLib/BsdSocketLib/socket.c51
-rw-r--r--StdLib/BsdSocketLib/write.c1
22 files changed, 212 insertions, 130 deletions
diff --git a/StdLib/BsdSocketLib/SocketInternals.h b/StdLib/BsdSocketLib/SocketInternals.h
index 8fbd8420dc..1b19869c0d 100644
--- a/StdLib/BsdSocketLib/SocketInternals.h
+++ b/StdLib/BsdSocketLib/SocketInternals.h
@@ -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.
**/
diff --git a/StdLib/BsdSocketLib/Socklib_internals.h b/StdLib/BsdSocketLib/Socklib_internals.h
index 802aaebcc6..3e0119fd18 100644
--- a/StdLib/BsdSocketLib/Socklib_internals.h
+++ b/StdLib/BsdSocketLib/Socklib_internals.h
@@ -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
diff --git a/StdLib/BsdSocketLib/accept.c b/StdLib/BsdSocketLib/accept.c
index 25ae1b5861..4f0dbac5f9 100644
--- a/StdLib/BsdSocketLib/accept.c
+++ b/StdLib/BsdSocketLib/accept.c
@@ -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
diff --git a/StdLib/BsdSocketLib/bind.c b/StdLib/BsdSocketLib/bind.c
index c1bf64e9e4..f544c94a47 100644
--- a/StdLib/BsdSocketLib/bind.c
+++ b/StdLib/BsdSocketLib/bind.c
@@ -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
diff --git a/StdLib/BsdSocketLib/close.c b/StdLib/BsdSocketLib/close.c
index 2a9fda4930..3dfeb2bf18 100644
--- a/StdLib/BsdSocketLib/close.c
+++ b/StdLib/BsdSocketLib/close.c
@@ -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
diff --git a/StdLib/BsdSocketLib/connect.c b/StdLib/BsdSocketLib/connect.c
index 92fc75bdb0..aa4df57d9f 100644
--- a/StdLib/BsdSocketLib/connect.c
+++ b/StdLib/BsdSocketLib/connect.c
@@ -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
diff --git a/StdLib/BsdSocketLib/errno.c b/StdLib/BsdSocketLib/errno.c
index 360609bd80..2f81506b7a 100644
--- a/StdLib/BsdSocketLib/errno.c
+++ b/StdLib/BsdSocketLib/errno.c
@@ -15,4 +15,7 @@
#include <sys/errno.h>
+/**
+ Variable that contains additional error information when an API call fails.
+**/
int errno;
diff --git a/StdLib/BsdSocketLib/getpeername.c b/StdLib/BsdSocketLib/getpeername.c
index 37e6d1eab6..5991099274 100644
--- a/StdLib/BsdSocketLib/getpeername.c
+++ b/StdLib/BsdSocketLib/getpeername.c
@@ -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
diff --git a/StdLib/BsdSocketLib/getsockname.c b/StdLib/BsdSocketLib/getsockname.c
index e8d1d55bb3..11614493db 100644
--- a/StdLib/BsdSocketLib/getsockname.c
+++ b/StdLib/BsdSocketLib/getsockname.c
@@ -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
diff --git a/StdLib/BsdSocketLib/getsockopt.c b/StdLib/BsdSocketLib/getsockopt.c
index eac10544de..47b7c6fb34 100644
--- a/StdLib/BsdSocketLib/getsockopt.c
+++ b/StdLib/BsdSocketLib/getsockopt.c
@@ -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
diff --git a/StdLib/BsdSocketLib/listen.c b/StdLib/BsdSocketLib/listen.c
index 193444a25c..7c6d5f3d39 100644
--- a/StdLib/BsdSocketLib/listen.c
+++ b/StdLib/BsdSocketLib/listen.c
@@ -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
diff --git a/StdLib/BsdSocketLib/read.c b/StdLib/BsdSocketLib/read.c
index 6f8d42974b..293c101463 100644
--- a/StdLib/BsdSocketLib/read.c
+++ b/StdLib/BsdSocketLib/read.c
@@ -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
diff --git a/StdLib/BsdSocketLib/recv.c b/StdLib/BsdSocketLib/recv.c
index 91f07cb08a..0ad7252c44 100644
--- a/StdLib/BsdSocketLib/recv.c
+++ b/StdLib/BsdSocketLib/recv.c
@@ -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
diff --git a/StdLib/BsdSocketLib/recvfrom.c b/StdLib/BsdSocketLib/recvfrom.c
index ce230231dc..20b3f4a916 100644
--- a/StdLib/BsdSocketLib/recvfrom.c
+++ b/StdLib/BsdSocketLib/recvfrom.c
@@ -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
diff --git a/StdLib/BsdSocketLib/res_send.c b/StdLib/BsdSocketLib/res_send.c
index 82addc9745..0b887e79d0 100644
--- a/StdLib/BsdSocketLib/res_send.c
+++ b/StdLib/BsdSocketLib/res_send.c
@@ -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();
diff --git a/StdLib/BsdSocketLib/send.c b/StdLib/BsdSocketLib/send.c
index 0bbed5ac33..439d8081c1 100644
--- a/StdLib/BsdSocketLib/send.c
+++ b/StdLib/BsdSocketLib/send.c
@@ -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
diff --git a/StdLib/BsdSocketLib/sendto.c b/StdLib/BsdSocketLib/sendto.c
index 5311ce6022..2fb7737c30 100644
--- a/StdLib/BsdSocketLib/sendto.c
+++ b/StdLib/BsdSocketLib/sendto.c
@@ -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;
@@ -69,19 +74,24 @@ sendto (
&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 );
}
//
diff --git a/StdLib/BsdSocketLib/sethostname.c b/StdLib/BsdSocketLib/sethostname.c
index 7863e8ce45..eb9d914c63 100644
--- a/StdLib/BsdSocketLib/sethostname.c
+++ b/StdLib/BsdSocketLib/sethostname.c
@@ -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
diff --git a/StdLib/BsdSocketLib/setsockopt.c b/StdLib/BsdSocketLib/setsockopt.c
index 74c948c783..64f3a35911 100644
--- a/StdLib/BsdSocketLib/setsockopt.c
+++ b/StdLib/BsdSocketLib/setsockopt.c
@@ -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
diff --git a/StdLib/BsdSocketLib/shutdown.c b/StdLib/BsdSocketLib/shutdown.c
index c3df1ee519..76831a502b 100644
--- a/StdLib/BsdSocketLib/shutdown.c
+++ b/StdLib/BsdSocketLib/shutdown.c
@@ -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
diff --git a/StdLib/BsdSocketLib/socket.c b/StdLib/BsdSocketLib/socket.c
index e78329291c..4f49777b51 100644
--- a/StdLib/BsdSocketLib/socket.c
+++ b/StdLib/BsdSocketLib/socket.c
@@ -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_STREAM - Connect to TCP, provides a byte stream
- that is manipluated by read, recv, send and write.
+ SOCK_DGRAM - Connect to UDP, provides a datagram service that is
+ manipulated by recvfrom and sendto.
</li>
<li>
- SOCK_SEQPACKET - Connect to TCP, provides sequenced packet stream
- that is manipulated by read, recv, send and write.
+ SOCK_STREAM - Connect to TCP, provides a byte stream
+ that is manipluated 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.
**/
diff --git a/StdLib/BsdSocketLib/write.c b/StdLib/BsdSocketLib/write.c
index f6f50006af..1f8ad004b5 100644
--- a/StdLib/BsdSocketLib/write.c
+++ b/StdLib/BsdSocketLib/write.c
@@ -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