curl-library
Re: Using libcurl on top of lwip on POSIX embedded platform (take 2)
Date: Fri, 16 Mar 2012 14:00:34 +0100
Daniel Stenberg wrote:
> On Thu, 15 Mar 2012, Mason wrote:
>
>> I have almost (I hope!) succeeded in generating libcurl on top of lwip
>> for a (mostly) POSIX sh-superh-elf platform.
>
> Nice!
:-)
>> As far as I can tell, in libcurl, fcntl is only called on sockets (in
>> nonblock.c). Therefore I think it should be possible to have libcurl call
>> lwip_fcntl instead of fcntl when lwip is used.
>
>> Proposed patch (general, untested, idea)
>
>> +#ifdef USE_LWIPSOCK
>> +#define fcntl lwip_fcntl
>> +#endif
>
> Seems fine. Possibly you can move that to setup_once.h where you do the
> sclose() definition so that the lwip specific defines are made at a single
> spot in the code.
("sclose" stand for socket close, right?)
In the above solution, #define fcntl lwip_fcntl must occur AFTER
the inclusion of fcntl.h
Looking at nonblock.c, the inclusion order is:
"setup.h"
<fcntl.h>
"nonblock.h"
Is there a guarantee that setup.h will never include setup_once.h,
directly or indirectly? Perhaps it is safer to define an sfcntl
(socket fcntl) macro along with sclose.
Proposed patch (will test ASAP)
(May I ask why there are two pairs of parenthesis around
the parameter?)
--- setup_once.h.orig 2011-11-04 23:32:57.000000000 +0100
+++ setup_once.h 2012-03-16 13:25:38.156250000 +0100
@@ -239,10 +239,18 @@
# define sclose(x) closesocket((x))
#elif defined(HAVE_CLOSESOCKET_CAMEL)
# define sclose(x) CloseSocket((x))
+#elif defined(USE_LWIPSOCK)
+# define sclose(x) lwip_close((x))
#else
# define sclose(x) close((x))
#endif
+#if defined(USE_LWIPSOCK)
+# define sfcntl lwip_fcntl
+#else
+# define sfcntl fcntl
+#endif
+
/*
* Uppercase macro versions of ANSI/ISO is*() functions/macros which
* avoid negative number inputs with argument byte codes > 127.
--- nonblock.c.orig 2011-11-04 23:32:56.000000000 +0100
+++ nonblock.c 2012-03-16 13:32:55.515625000 +0100
@@ -61,11 +61,11 @@
/* most recent unix versions */
int flags;
- flags = fcntl(sockfd, F_GETFL, 0);
+ flags = sfcntl(sockfd, F_GETFL, 0);
if(nonblock)
- return fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
+ return sfcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
else
- return fcntl(sockfd, F_SETFL, flags & (~O_NONBLOCK));
+ return sfcntl(sockfd, F_SETFL, flags & (~O_NONBLOCK));
#elif defined(HAVE_IOCTL_FIONBIO)
> If I understand you correctly, you'd then be down to only need to simple
> defines done to build properly with lwip?
My goal is to write a configure wrapper to generate valid
headers and makefiles, which can be used "as is" to build
the library.
Currently, my script is:
export CC=sh4gcc
export CPP=sh4cpp
export AS=sh4as
export LD=sh4ld
export NM=sh4nm
export AR=sh4ar
export OBJDUMP=sh4objdump
export CPPFLAGS="-I lwip_files -D USE_LWIPSOCK"
export CFLAGS="-Os -m4-300 -mruntime=os21 -mboard=sdk7105"
export LDFLAGS="-Llwip_files"
export LIBS="-llwip"
for OPT in ftp file ldap rtsp proxy dict telnet tftp pop3 imap smtp gopher \
manual ipv6 crypto-auth tls-srp cookies shared
do
DISABLE="$DISABLE --disable-$OPT"
done
for LIB in ssl libssh2 zlib krb4 gssapi spnego axtls librtmp libidn
do
WITHOUT="$WITHOUT --without-$LIB"
done
./configure --host=sh-superh-elf --build=i686-pc-cygwin $DISABLE $WITHOUT
By the way, is there a way to make libcurl even smaller? :-)
>> For close, the solution is not so clear-cut, because curl deals with regular
>> files as well as sockets, AFAIU.
>
> Sure, but you're in luck here since for example Windows (and some others)
> already require a separate close for sockets so the sclose() macro is used all
> over internally when closing sockets. close() is only ever done on non-sockets
> file descriptors.
Great news indeed!
>> --- setup_once.h.orig 2011-11-04 23:32:57.000000000 +0100
>> +++ setup_once.h 2012-03-15 13:49:19.875000000 +0100
>> @@ -239,6 +239,8 @@
>> # define sclose(x) closesocket((x))
>> #elif defined(HAVE_CLOSESOCKET_CAMEL)
>> # define sclose(x) CloseSocket((x))
>> +#elif defined(USE_LWIPSOCK)
>> +# define sclose(x) lwip_close((x))
>> #else
>> # define sclose(x) close((x))
>> #endif
>
> looks simple and clean enough!
I'm hoping to test all of it next week.
-- Regards. ------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.htmlReceived on 2012-03-16