[lwip-users] Using libcurl on top of lwip

117 views
Skip to first unread message

Mason

unread,
Mar 13, 2012, 11:40:37 AM3/13/12
to Mailing list for lwIP users
Hello,

I'm trying to port libcurl on top of lwip.

http://en.wikipedia.org/wiki/CURL
http://en.wikipedia.org/wiki/LwIP

My main difficulty is the close function, because it is
defined both in libc.a, to deal with regular files, and
in lwip.a, to deal with sockets.

I suppose the simple solution would be to convince libcurl
to use lwip_close instead of close?

It looks like libcurl wrapped the call to close within a macro,
which means I would only have to change one line:

#if defined(HAVE_CLOSESOCKET)
# define sclose(x) closesocket((x))
#elif defined(HAVE_CLOSESOCKET_CAMEL)
# define sclose(x) CloseSocket((x))
#else
# define sclose(x) close((x))
#endif

There's a similar problem with fcntl, with the added complexity
that some of the parameters are #defined in two places.

I'd be happy to hear suggestions, opinions, comments...

--
Regards.

_______________________________________________
lwip-users mailing list
lwip-...@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Kieran Mansley

unread,
Mar 13, 2012, 12:00:23 PM3/13/12
to Mailing list for lwIP users
On Tue, 2012-03-13 at 16:40 +0100, Mason wrote:
>
> I'd be happy to hear suggestions, opinions, comments...

If you could arrange for lwIP to use a different range of socket IDs
from the file descriptors used by libc then you could easily make a
wrapper function that would call the appropriate function (libc close or
lwip_close) based on the fd provided. This would then allow you to use
libcurl without modifying it as your wrapper could be in a preload
library and intercept the calls to close.

Kieran

Mason

unread,
Mar 13, 2012, 12:16:27 PM3/13/12
to Mailing list for lwIP users
Kieran Mansley wrote:

> If you could arrange for lwIP to use a different range of socket IDs
> from the file descriptors used by libc then you could easily make a
> wrapper function that would call the appropriate function (libc close or
> lwip_close) based on the fd provided. This would then allow you to use
> libcurl without modifying it as your wrapper could be in a preload
> library and intercept the calls to close.

The preload trick works on dynamic-link systems, right?

(Everything is statically linked on my system.)

Or did you have something like weak symbols in mind?

--
Regards.

Kieran Mansley

unread,
Mar 13, 2012, 12:21:37 PM3/13/12
to Mailing list for lwIP users
On Tue, 2012-03-13 at 17:16 +0100, Mason wrote:
> The preload trick works on dynamic-link systems, right?
>
> (Everything is statically linked on my system.)

Yes, if you're statically linked you'll have to modify libcurl or libc
to call lwIP when appropriate.

Kieran

Gisle Vanem

unread,
Mar 13, 2012, 5:06:48 PM3/13/12
to Mailing list for lwIP users
"Mason" <mpeg...@free.fr> wrote:

> My main difficulty is the close function, because it is
> defined both in libc.a, to deal with regular files, and

> in lip.a, to deal with sockets.


>
> I suppose the simple solution would be to convince libcurl

> to use lip_close instead of close?

Didn't the thread on the libcurl-list work? You posted about this
28 Feb 2012.

Gist of that was...
In lwIP's src/include/lip/sockets.h:

#if LWIP_COMPAT_SOCKETS
#define closesocket(s) lwip_close(s)
...

> It looks like libcurl wrapped the call to close within a macro,
> which means I would only have to change one line:
>
> #if defined(HAVE_CLOSESOCKET)
> # define sclose(x) closesocket((x))

So without looking at this in detail, you should define
HAVE_CLOSESOCKET and make sure the headers are in
correct order. My advice is to look at the preprocessed output
(gcc-whatever -E ...). So the real close() (or the real worker in libc.a)
should not shadow for anything in either lwIP nor libcurl. But I'm
not sure. Daniel Stenberg should know.

> I'd be happy to hear suggestions, opinions, comments...

Me too; I'd be happy to get lwIP+libcurl to work okay on Windows.
But it's rather low on my list of priorities.

--gv

Mason

unread,
Mar 15, 2012, 8:35:01 AM3/15/12
to Mailing list for lwIP users
Gisle Vanem wrote:

> Mason wrote:
>
>> My main difficulty is the close function, because it is
>> defined both in libc.a, to deal with regular files, and
>> in lip.a, to deal with sockets.
>>
>> I suppose the simple solution would be to convince libcurl

>> to use lwip_close instead of close?


>
> Didn't the thread on the libcurl-list work?

I did get a few suggestions, but I don't want to fiddle with
generated files like curl_config.h, I want to be able to use
the generated headers and makefiles "as is".

> You posted about this 28 Feb 2012.

For reference,
http://curl.haxx.se/mail/lib-2012-02/0236.html

> Gist of that was...
> In lwIP's src/include/lip/sockets.h:
>
> #if LWIP_COMPAT_SOCKETS
> #define closesocket(s) lwip_close(s)

I ignored this macro, because it corresponds to a Win32
function, and the configure script looks for its definition
in non-POSIX headers (socket.h instead of sys/socket.h)

(My environment is 90% POSIX-compliant, and I've provided
a set of POSIX-compliant wrappers for lwip.)

> I'd be happy to get lwIP+libcurl to work okay on Windows.
> But it's rather low on my list of priorities.

I'm 99% done (on a POSIX embedded system). If the libcurl
maintainer accepts my small patch, then it will be possible
to invoke the configure script and just run the makefile
in lib to build libcurl for lwip :-)

--
Regards.

Reply all
Reply to author
Forward
0 new messages