Skip to content

add a workaround to mingw / libstdc++ issue 68307 #479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

cbeck88
Copy link

@cbeck88 cbeck88 commented Nov 12, 2015

This is a follow up to issue #478 .

After discussion with mingw folks they agree that it's a problem but it's
not clear exactly how they are going to fix it and how easily a patch
would be available downstream, i.e. if it would require building mingw
from sources instead of just getting it from some linux package manager.
Since it requires patching libstdc++ apparently, I tend to assume it could
take a while.

Therefore my plan in my project is to take websocketpp in-tree and insert
a workaround which would be noninvasive and not change behavior for
other platforms.

I decided to cookup something using SFINAE that detects if the
lib::asio::errc enum is missing the value it is supposed to have, and replace
the websocketpp check for equality with this, with false when it is missing.

I thought I would send this patch upstream for your review, to see what you
think etc. I guess if you are only interested to target strictly conforming C++11
implementations then you might not want to carry the patch, but anyway it's
for you to decide.

This is a workaround to some standard non-conformance defect in
libstdc++ headers for mingw. Although the C++11 standard requires
that `std::errc::operation_canceled` is an enumerator value of
`std::errc` in `<system_error>`, and asio library uses std::errc
when compiled as standalone, mingw apparently doesn't use all the
std::errc signals, and doesn't define any of the enumerators that
it doesn't use.

Presumably mingw instead packs these signals into some different
error codes or something, it's not entirely clear. Regardless,
even if there are some low-level issues in mingw implementations
of sockets, websocketpp is a bit higher level library and one
would think that we should be able to try to run websocketpp over
any given sockets implementation and at least get it to compile.

This patch is a polyfill so that if for whatever reason the host
system fails to define this error code symbol, websocketpp will
just return false whenever testing if an error code matches it,
as a form of special support for mingw. (Or any other toolchain
that happens to have a similar bug -- there is no ifdef going on
here.)

In preliminary tests, websocketpp examples seem to work fine with
this patch when compiled with the mingw-w64 toolchain from ubuntu
trusty repo, with Asio standalone and C++11 standard, when
running in wine on my machine.
@cbrunschen
Copy link

cbrunschen commented Nov 8, 2016

Hi,

I'm trying to use websocketpp (version 0.7.0) in MAME, but I think I'm hitting this issue:

mamedev/mame#1625

https://tea-ci.org/mamedev/mame/3509

i.e., when compiling on mingw, I get the error that this pull request is intended to fix:

In file included from ../../../../../3rdparty/websocketpp/websocketpp/config/asio_no_tls.hpp:32:0,
from ../../../../../src/osd/modules/webserver/webserver_websocketpp.cpp:18:
../../../../../3rdparty/websocketpp/websocketpp/transport/asio/endpoint.hpp: In member function 'void websocketpp::transport::asio::endpoint::handle_accept(websocketpp::transport::accept_handler, const error_code&)':
../../../../../3rdparty/websocketpp/websocketpp/transport/asio/endpoint.hpp:811:28: error: 'operation_canceled' is not a member of 'std::errc'
if (asio_ec == lib::asio::errc::operation_canceled) {

@cbeck88
Copy link
Author

cbeck88 commented Jan 14, 2017

Hi, as a follow up, Jonathan Wakely has merged a fix for this into libstdc++ trunk. He says it might be backported to gcc 5.4 and 5.3: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71444

I did not test myself if this fixes websocketpp cross-compilation.

wch added a commit to rstudio/websocket that referenced this pull request May 30, 2018
wch added a commit to rstudio/websocket that referenced this pull request May 30, 2018
wch added a commit to rstudio/websocket that referenced this pull request Jul 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants