Added EOPNOTSUPP and better error handling in accept.
This commit is contained in:
parent
c39a693274
commit
d24a880003
3 changed files with 23 additions and 6 deletions
|
@ -102,6 +102,7 @@ extern int errno; /* place where the error numbers go */
|
||||||
#define EMSGSIZE (_SIGN 73) /* Message too long */
|
#define EMSGSIZE (_SIGN 73) /* Message too long */
|
||||||
#define ENOTSOCK (_SIGN 74) /* Socket operation on non-socket */
|
#define ENOTSOCK (_SIGN 74) /* Socket operation on non-socket */
|
||||||
#define ENOPROTOOPT (_SIGN 75) /* Protocol not available */
|
#define ENOPROTOOPT (_SIGN 75) /* Protocol not available */
|
||||||
|
#define EOPNOTSUPP (_SIGN 76) /* Operation not supported */
|
||||||
|
|
||||||
/* The following are not POSIX errors, but they can still happen.
|
/* The following are not POSIX errors, but they can still happen.
|
||||||
* All of these are generated by the kernel and relate to message passing.
|
* All of these are generated by the kernel and relate to message passing.
|
||||||
|
|
|
@ -85,6 +85,7 @@ const char *_sys_errlist[] = {
|
||||||
"Message too long", /* EMSGSIZE */
|
"Message too long", /* EMSGSIZE */
|
||||||
"Socket operation on non-socket", /* ENOTSOCK */
|
"Socket operation on non-socket", /* ENOTSOCK */
|
||||||
"Protocol not available", /* ENOPROTOOPT */
|
"Protocol not available", /* ENOPROTOOPT */
|
||||||
|
"Operation not supported", /* EOPNOTSUPP */
|
||||||
};
|
};
|
||||||
|
|
||||||
const int _sys_nerr = sizeof(_sys_errlist) / sizeof(_sys_errlist[0]);
|
const int _sys_nerr = sizeof(_sys_errlist) / sizeof(_sys_errlist[0]);
|
||||||
|
|
|
@ -23,15 +23,30 @@ int accept(int socket, struct sockaddr *_RESTRICT address,
|
||||||
socklen_t *_RESTRICT address_len)
|
socklen_t *_RESTRICT address_len)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
|
nwio_udpopt_t udpopt;
|
||||||
|
|
||||||
r= _tcp_accept(socket, address, address_len);
|
r= _tcp_accept(socket, address, address_len);
|
||||||
return r;
|
if (r != -1 || (errno != ENOTTY && errno != EBADIOCTL))
|
||||||
|
return r;
|
||||||
|
|
||||||
#if DEBUG
|
/* Unfortunately, we have to return EOPNOTSUPP for a socket that
|
||||||
fprintf(stderr, "accept: not implemented for fd %d\n", socket);
|
* does not support accept (such as a UDP socket) and ENOTSOCK for
|
||||||
#endif
|
* filedescriptors that do not refer to a socket.
|
||||||
errno= ENOSYS;
|
*/
|
||||||
return -1;
|
r= ioctl(socket, NWIOGUDPOPT, &udpopt);
|
||||||
|
if (r == 0)
|
||||||
|
{
|
||||||
|
/* UDP socket */
|
||||||
|
errno= EOPNOTSUPP;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if ((errno == ENOTTY || errno == EBADIOCTL))
|
||||||
|
{
|
||||||
|
errno= ENOTSOCK;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _tcp_accept(int socket, struct sockaddr *_RESTRICT address,
|
static int _tcp_accept(int socket, struct sockaddr *_RESTRICT address,
|
||||||
|
|
Loading…
Reference in a new issue