gvanem / Watt-32

Watt-32 TCP/IP library and samples.
https://www.watt-32.net/
18 stars 8 forks source link

C++ asio compatibility #74

Closed jwt27 closed 1 year ago

jwt27 commented 1 year ago

Hi!

I was just looking into using the C++ asio library with djgpp/watt32, but it seems we're missing a few things.

#define WATT32_NO_OLDIES
#define ASIO_DISABLE_THREADS
#include <asio.hpp>

Compiling the above test file, I see:

Missing functions:

Missing errno:

Missing signal options:

Missing ipv6 stuff:

Seems asio expects a complete ipv6 implementation, I don't see an obvious way to disable it. What's the status on that?

jwt27 commented 1 year ago

Oh, I see libc does provide readv/writev, but inc/sys/uio.h completely hides the libc header. Should have another #include_next there.

jwt27 commented 1 year ago

It compiles now, with the missing macros defined to 0. Tried building and running some of the examples too, looks like it all works.

I do think it would be nice to have a consistent definition for ECANCELED. @gvanem, how would you feel about adding it in Watt32?

gvanem commented 1 year ago

I do think it would be nice to have a consistent definition for ECANCELED

Sure, how about just:

diff --git a/util/errnos.c b/util/errnos.c
index 109ab4e..f69758a 100644
--- a/util/errnos.c
+++ b/util/errnos.c
@@ -529,6 +529,7 @@ static const char *err_tab[] = {
   "RVD related disk error (EVDBAD)",
   "Out of remote working directory stuctures (ENORMTWD)",    /* 94 */
   "Value too large (EOVERFLOW)",
+  "Operation canceled (ECANCELED)",                          /* 96 */
 };

 #define ADD_ERRNO(err_num)  add_errno (err_num, #err_num, strerror(err_num))
@@ -1111,6 +1112,12 @@ static void process (void)
 #else
   NEW_ERRNO (94);
 #endif
+
+#ifdef ECANCELED
+  ADD_ERRNO (ECANCELED);
+#else
+  NEW_ERRNO (96);
+#endif
 }

The missing support for SA_x and IPV6_y stuff would be very tricky to fix. But besides that, does your merged stuff help the issues in this PR? I'm not familiar with Boost ans Asio.

BTW, I see it is defined in both Cygwin and Andrew's djgpp distro (gcc 12.1.0). Here:
$(DJGPP)/windows/lib/gcc/i586-pc-msdosdjgpp/12.1.0/include/c++/i586-pc-msdosdjgpp/bits/error_constants.h

jwt27 commented 1 year ago

I do think it would be nice to have a consistent definition for ECANCELED

Sure, how about just:

diff --git a/util/errnos.c b/util/errnos.c
index 109ab4e..f69758a 100644
--- a/util/errnos.c
+++ b/util/errnos.c
@@ -529,6 +529,7 @@ static const char *err_tab[] = {
   "RVD related disk error (EVDBAD)",
   "Out of remote working directory stuctures (ENORMTWD)",    /* 94 */
   "Value too large (EOVERFLOW)",
+  "Operation canceled (ECANCELED)",                          /* 96 */
 };

 #define ADD_ERRNO(err_num)  add_errno (err_num, #err_num, strerror(err_num))
@@ -1111,6 +1112,12 @@ static void process (void)
 #else
   NEW_ERRNO (94);
 #endif
+
+#ifdef ECANCELED
+  ADD_ERRNO (ECANCELED);
+#else
+  NEW_ERRNO (96);
+#endif
 }

Looks good to me, thanks. And I see you already added it, great!

BTW, I see it is defined in both Cygwin and Andrew's djgpp distro (gcc 12.1.0). Here: $(DJGPP)/windows/lib/gcc/i586-pc-msdosdjgpp/12.1.0/include/c++/i586-pc-msdosdjgpp/bits/error_constants.h

I added that in case libc or watt32 ever decided to add new errnos (like right now :) ). Asio doesn't seem to need std::errc though, it has its own equivalent enum here:

https://github.com/chriskohlhoff/asio/blob/master/asio/include/asio/error.hpp

The missing support for SA_x and IPV6_y stuff would be very tricky to fix. But besides that, does your merged stuff help the issues in this PR? I'm not familiar with Boost ans Asio.

The SA_ flags can safely be defined to 0, I'm quite sure. The IPV6 stuff too probably, as long as you don't try to use it.

This is the patch I intend to submit:

https://github.com/chriskohlhoff/asio/compare/master...jwt27:asio:djgpp

jwt27 commented 1 year ago

Hm, still having some trouble. I'm trying the basic http client example from asio. What it does:

This returns EISCONN, and it gets interpreted as a failure. I think only connect() should be able to return EISCONN.

jwt27 commented 1 year ago

I changed my asio patch so that it uses ioctlsocket(): https://github.com/jwt27/asio/commit/011725021975c35563766434148d89a657b4e53a

It requires extra casts since ioctlsocket() here takes a char*, but interprets the argument as int-sized. Now I'm wondering, why is that? Maybe we can make it use void* instead?

jwt27 commented 1 year ago

This all works now, will close. Thanks!