Espressif ESP32-S2 Programming Manual page 1437

Table of Contents

Advertisement

Chapter 4. API Guides
• select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
struct timeval *timeout) has exception descriptor indicating that the socket has an error. For more
information, see
select()
Socket API Errors
The error detection
• We can know that the socket API fails according to its return value.
Get the error reason code
• When socket API fails, the return value doesn' t contain the failure reason and the application can get the
error reason code by accessing errno. Different values indicate different meanings. For more information,
see
<Socket Error Reason
Example:
int
err;
int
sockfd;
if
(sockfd
=
socket(AF_INET,SOCK_STREAM,0)
//
the error code
err
=
errno;
return
err;
}
select() Errors
The error detection
• Socket error when select() has exception descriptor
Get the error reason code
• If the select indicates that the socket fails, we can't get the error reason code by accessing errno, in-
stead we should call getsockopt() to get the failure reason code. Because select() has exception
descriptor, the error code will not be given to errno.
Note: getsockopt function prototype int getsockopt(int s, int level, int optname,
void *optval, socklen_t *optlen). Its function is to get the current value of the option of any type,
any state socket, and store the result in optval. For example, when you get the error code on a socket, you can get it
by getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &err, &optlen).
Example:
int
err;
if
(select(sockfd
+
err
=
errno;
return
err;
}
else
{
if
(FD_ISSET(sockfd, &exfds)) {
//
select() exception
int
optlen
=
getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &err, &optlen);
return
err;
}
}
Socket Error Reason Code
of standard POSIX/C error codes,
esp32/blob/master/newlib/libc/include/sys/errno.h>
newlib/platform_include/errno.h
Espressif Systems
Errors.
Code>.
is
obtained
from
errno
1, NULL, NULL, &exfds, &tval)
set
using getsockopt()
sizeof(int);
Below is a list of common error codes.
please see newlib errno.h <https://github.com/espressif/newlib-
Submit Document Feedback
<
0) {
<=
0) {
and
the
platform-specific
1426
For more detailed list
extensions
Release v4.4

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32-S2 and is the answer not in the manual?

Questions and answers

Table of Contents

Save PDF