Wes Hardaker <harda...@users.sourceforge.net> writes:

>You're probably right (I'm not a windows expert), but it sounds like we should 
>be doing something like:
>
>int ns_errno() {
>    #ifdef windows
>       return dosomething();
>    #else
>       return errno;
>    #endif
>}

Something like that. And if dosomething() is just WSAGetLastError() there 
should be constants for the error codes as well. Because WSAGetLastError() 
returns for example WSAEINTR and not EINTR and EINTR is still defined in 
Windows (with EINTR equals to 4 in errno.h and WSAEINTR being 10004 in 
winsock2.h)

So what I would do, additional to your suggested "ns_errno()", is something 
like this in a header (assuming that the prefix NS makes some sense in the 
project.)
#ifdef windows
   #define NS_EINTR  WSAEINTR
   #define NS_EBADF  WSAEBADF
   #define NS_EACCES WSAEACCES
   #define NS_EFAULT WSAEFAULT
   #define NS_EINVAL WSAEINVAL
   #define NS_EMFILE WSAEMFILE
   ...
#else
   #define NS_EINTR EINTR
   #define NS_EBADF  EBADF
   ...
#endif

This would be the easy part. And then every occurrence of errno has to be 
checked and if it is used to evaluate the errors of a socket call it must be 
replaced with ns_errno and the associated constants have to be replaced with 
their NS_* counterparts.

Alternatively dosomething() is not WSAGetLastError but  looks something like 
that:

int dosomething() {
   switch(WSAGetLastError)  {
   case WSAEINTR:
      return EINTR;
   case WSAEBADF:
      return EBADF;
   ...
   }
}

Then the constants in the source code must not be replaced. But still errno has 
to be replaced with ns_errno() where applicable.
I would prefer the first variant because there is probably not a suitable 
constant in errno.h for every error code in winsock2.h.

These are just my suggestions of what could be done. Probably you have much 
better ideas. Probably you don't care. I'm not annoyed if you store my ideas on 
/dev/null, or on NUL, if it comes to Windows :-).

I'm still wondering that I should be the first to mention this problem, with 
all those years of net-snmp. Anyway...

Thanks for your answer!
Walter



#####################################################################################
This message and any attachments are solely for the use of the intended 
recipients. They may contain privileged and/or confidential information or 
other information protected from disclosure. If you are not an intended 
recipient, you are hereby notified that you received this email in error and 
that any review, dissemination, distribution or copying of this email and any 
attachment is strictly prohibited. If you have received this email in error, 
please contact the sender and delete the message and any attachment from your 
system.
Thank You.
  ANDRITZ HYDRO GmbH
  Rechtsform/ Legal form: Gesellschaft mit beschr?nkter Haftung / Corporation
  Firmensitz/ Registered seat: Wien
  Firmenbuchgericht/ Court of registry: Handelsgericht Wien
  Firmenbuchnummer/ Company registration: FN 61833 g
  DVR: 0605077
  UID-Nr.: ATU14756806
#####################################################################################


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to