Added EOPNOTSUPP and better error handling in accept.

This commit is contained in:
Philip Homburg 2006-09-14 13:48:41 +00:00
parent c39a693274
commit d24a880003
3 changed files with 23 additions and 6 deletions

View file

@ -102,6 +102,7 @@ extern int errno; /* place where the error numbers go */
#define EMSGSIZE (_SIGN 73) /* Message too long */
#define ENOTSOCK (_SIGN 74) /* Socket operation on non-socket */
#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.
* All of these are generated by the kernel and relate to message passing.

View file

@ -85,6 +85,7 @@ const char *_sys_errlist[] = {
"Message too long", /* EMSGSIZE */
"Socket operation on non-socket", /* ENOTSOCK */
"Protocol not available", /* ENOPROTOOPT */
"Operation not supported", /* EOPNOTSUPP */
};
const int _sys_nerr = sizeof(_sys_errlist) / sizeof(_sys_errlist[0]);

View file

@ -23,15 +23,30 @@ int accept(int socket, struct sockaddr *_RESTRICT address,
socklen_t *_RESTRICT address_len)
{
int r;
nwio_udpopt_t udpopt;
r= _tcp_accept(socket, address, address_len);
return r;
if (r != -1 || (errno != ENOTTY && errno != EBADIOCTL))
return r;
#if DEBUG
fprintf(stderr, "accept: not implemented for fd %d\n", socket);
#endif
errno= ENOSYS;
return -1;
/* Unfortunately, we have to return EOPNOTSUPP for a socket that
* does not support accept (such as a UDP socket) and ENOTSOCK for
* filedescriptors that do not refer to a socket.
*/
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,