public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r11-8916] libstdc++: Use <sys/socket.h> features conditionally [PR 100285]
Date: Tue, 24 Aug 2021 16:01:03 +0000 (GMT)	[thread overview]
Message-ID: <20210824160103.099713857C66@sourceware.org> (raw)

https://gcc.gnu.org/g:f9325e99bbc83f975ce423efaaaded73400b08e3

commit r11-8916-gf9325e99bbc83f975ce423efaaaded73400b08e3
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Apr 30 14:25:25 2021 +0100

    libstdc++: Use <sys/socket.h> features conditionally [PR 100285]
    
    This makes the uses of getsockopt and setsockopt in
    <experimental/socket> conditional on the availability of <sys/socket.h>.
    
    It also fixes a test to check for <sys/socket.h> instead of <socket.h>.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/100285
            * include/experimental/socket (__basic_socket_impl::set_option)
            (__basic_socket_impl::get_option) [!_GLIBCXX_HAVE_SYS_SOCKET_H]:
            Just set error code.
            * testsuite/experimental/net/socket/socket_base.cc: CHeck
            for <sys/socket.h> not <socket.h>.
    
    (cherry picked from commit 0d501c338548152f9d2728d383eec3e9cef16784)

Diff:
---
 libstdc++-v3/include/experimental/socket                      | 8 ++++++++
 libstdc++-v3/testsuite/experimental/net/socket/socket_base.cc | 4 ++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/experimental/socket b/libstdc++-v3/include/experimental/socket
index bf6a8c87e67..9db4a245ccf 100644
--- a/libstdc++-v3/include/experimental/socket
+++ b/libstdc++-v3/include/experimental/socket
@@ -622,6 +622,7 @@ inline namespace v1
 	void
 	set_option(const _SettableSocketOption& __option, error_code& __ec)
 	{
+# ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
 	  int __result = ::setsockopt(_M_sockfd, __option.level(_M_protocol),
 				      __option.name(_M_protocol),
 				      __option.data(_M_protocol),
@@ -630,12 +631,16 @@ inline namespace v1
 	    __ec.assign(errno, generic_category());
 	  else
 	    __ec.clear();
+#else
+	  __ec = std::make_error_code(std::errc::not_supported);
+#endif
 	}
 
       template<typename _GettableSocketOption>
 	void
 	get_option(_GettableSocketOption& __option, error_code& __ec) const
 	{
+# ifdef _GLIBCXX_HAVE_SYS_SOCKET_H
 	  int __result = ::getsockopt(_M_sockfd, __option.level(_M_protocol),
 				      __option.name(_M_protocol),
 				      __option.data(_M_protocol),
@@ -644,6 +649,9 @@ inline namespace v1
 	    __ec.assign(errno, generic_category());
 	  else
 	    __ec.clear();
+#else
+	  __ec = std::make_error_code(std::errc::not_supported);
+#endif
 	}
 
       template<typename _IoControlCommand>
diff --git a/libstdc++-v3/testsuite/experimental/net/socket/socket_base.cc b/libstdc++-v3/testsuite/experimental/net/socket/socket_base.cc
index 1c02c5a09da..f957b6c92f6 100644
--- a/libstdc++-v3/testsuite/experimental/net/socket/socket_base.cc
+++ b/libstdc++-v3/testsuite/experimental/net/socket/socket_base.cc
@@ -129,7 +129,7 @@ void check_integer_sockopt()
 
 void test_option_types()
 {
-#if __has_include(<socket.h>)
+#if __has_include(<sys/socket.h>)
   check_boolean_sockopt<S::broadcast>();
 
   check_boolean_sockopt<S::debug>();
@@ -174,7 +174,7 @@ void test_option_types()
 
 void test_constants()
 {
-#if __has_include(<socket.h>)
+#if __has_include(<sys/socket.h>)
   static_assert( is_enum<S::shutdown_type>::value, "" );
   static_assert( S::shutdown_receive != S::shutdown_send, "" );
   static_assert( S::shutdown_receive != S::shutdown_both, "" );


                 reply	other threads:[~2021-08-24 16:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210824160103.099713857C66@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).