Subject: Re: INVALID_SOCKET symbol conflict

Re: INVALID_SOCKET symbol conflict

From: Lawson <lawson08_at_yahoo.com>
Date: Fri, 2 Mar 2012 08:12:32 -0800 (PST)

Hi,

Thanks for the prompt reply. The compile warning is:

In file included from /usr/local/include/libssh2/libssh2.h:140:1: warning: "INVALID_SOCKET" redefined
In file included from /usr/local/include/snmp_pp/snmp_pp.h:71,
                 from snmpThreadData.h:13,
                 from snmpThreadData.cpp:4:

/usr/local/include/snmp_pp/uxsnmp.h:49:1: warning: this is the location of the previous definition

So the conflict is I end up with headers both from libssh2 and the snmp++ library (http://www.agentpp.com/snmp_pp3_x/snmp_pp3_x.html).

Libssh2 defines it as:

#define INVALID_SOCKET -1

and SNMP++ defines it as:
#ifndef INVALID_SOCKET
#define INVALID_SOCKET ((SnmpSocket)(~0)) // value for invalid socket
#endif

Note that the SNMP++ header has an #ifdef. If I make the libssh2 come first, then the ifdef will stop it from being redefined... but it will be the wrong value (and type) for SNMP++.

I'm sure I can craft a workaround. Mostly I was perplexed at why two different libraries which are otherwise both disciplined about defining their constants with a namespace prefix both chose to define this one symbol like this, like it was some magical special symbol that everyone knew about.

- matt

--- On Fri, 3/2/12, Alexander Lamaison <swish_at_lammy.co.uk> wrote:

> From: Alexander Lamaison <swish_at_lammy.co.uk>
> Subject: Re: INVALID_SOCKET symbol conflict
> To: "libssh2 development" <libssh2-devel_at_cool.haxx.se>
> Date: Friday, March 2, 2012, 7:43 AM
> On 2 March 2012 15:13, Lawson <lawson08_at_yahoo.com>
> wrote:
> >
> > I notice that nearly all the defines in libssh2.h use
> the LIBSSH2_ prefix, except for INVALID_SOCKET.  It seems
> to be on purpose but I don't understand why.  Is it a
> Windows thing?
>
> It is a Windows Winsock constant that represents the only
> value
> returned by socket() that is guaranteed not to be a valid
> socket
> handle.  libssh2 defines it in the header for other
> platforms to help
> with portable programming.
>
> > My issue is that I'm writing an application (on Linux)
> which includes headers from multiple libraries, and some of
> them also set this symbol to a conflicting value.
>
> I believe the difference is because on some platforms
> sockets are
> signed ints and others they are unsigned ints.  Can you
> give more
> details about the conflict.  Error messages etc.
>
> Alex
>
> --
> Easy SFTP for Windows Explorer (http://www.swish-sftp.org)
>
> _______________________________________________
> libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
>

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2012-03-02