mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-02-21 00:07:36 +08:00
Cygwin: AF_UNIX: setsockopt: align SO_RCVBUF/SO_SNDBUF to Linux
The incoming size is doubled and must not be less than 256. Fold both options into one code block. Fix indentation.
This commit is contained in:
parent
b54240b08a
commit
3bd0df5170
@ -2056,21 +2056,28 @@ fhandler_socket_unix::setsockopt (int level, int optname, const void *optval,
|
||||
break;
|
||||
|
||||
case SO_RCVBUF:
|
||||
if (optlen < (socklen_t) sizeof (int))
|
||||
{
|
||||
set_errno (EINVAL);
|
||||
return -1;
|
||||
}
|
||||
rmem (*(int *) optval);
|
||||
break;
|
||||
|
||||
case SO_SNDBUF:
|
||||
if (optlen < (socklen_t) sizeof (int))
|
||||
{
|
||||
set_errno (EINVAL);
|
||||
return -1;
|
||||
}
|
||||
wmem (*(int *) optval);
|
||||
{
|
||||
if (optlen < (socklen_t) sizeof (int))
|
||||
{
|
||||
set_errno (EINVAL);
|
||||
return -1;
|
||||
}
|
||||
/* As on Linux double value and make sure it's not too small */
|
||||
int val = *(int *) optval;
|
||||
|
||||
if (val > 0 && val < INT_MAX / 2)
|
||||
val *= 2;
|
||||
if (val < 256)
|
||||
{
|
||||
set_errno (EINVAL);
|
||||
return -1;
|
||||
}
|
||||
if (optname == SO_RCVBUF)
|
||||
rmem (*(int *) optval);
|
||||
else
|
||||
wmem (*(int *) optval);
|
||||
}
|
||||
break;
|
||||
|
||||
case SO_RCVTIMEO:
|
||||
@ -2083,10 +2090,10 @@ fhandler_socket_unix::setsockopt (int level, int optname, const void *optval,
|
||||
if (!timeval_to_ms ((struct timeval *) optval,
|
||||
(optname == SO_RCVTIMEO) ? rcvtimeo ()
|
||||
: sndtimeo ()))
|
||||
{
|
||||
set_errno (EDOM);
|
||||
return -1;
|
||||
}
|
||||
{
|
||||
set_errno (EDOM);
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
Loading…
x
Reference in New Issue
Block a user