#include <arpa/inet.h>
#endif
+#ifdef __MORPHOS__
+#include <proto/socket.h>
+#endif
+
// for Z_Malloc/Z_Free in quake
#ifndef STANDALONETEST
#include "quakedef.h"
#include "lhnet.h"
+#if defined(WIN32)
+#define EWOULDBLOCK WSAEWOULDBLOCK
+#define ECONNREFUSED WSAECONNREFUSED
+
+#define SOCKETERRNO WSAGetLastError()
+
+#define SOCKLEN_T int
+#elif defined(__MORPHOS__)
+#define ioctlsocket IoctlSocket
+#define closesocket CloseSocket
+#define SOCKETERRNO Errno()
+
+#define SOCKLEN_T int
+#else
+#define ioctlsocket ioctl
+#define closesocket close
+#define SOCKETERRNO errno
+
+#define SOCKLEN_T socklen_t
+#endif
+
// to make LHNETADDRESS_FromString resolve repeated hostnames faster, cache them
#define MAX_NAMECACHE 64
static struct namecache_s
{
#ifdef WIN32
u_long _true = 1;
- if (ioctlsocket(lhnetsocket->inetsocket, FIONBIO, &_true) != -1)
#else
char _true = 1;
- if (ioctl(lhnetsocket->inetsocket, FIONBIO, &_true) != -1)
#endif
+ if (ioctlsocket(lhnetsocket->inetsocket, FIONBIO, &_true) != -1)
{
-#ifdef WIN32
- int namelen;
-#else
- socklen_t namelen;
-#endif
+ SOCKLEN_T namelen;
namelen = address->addresstype == LHNETADDRESSTYPE_INET6 ? sizeof(lhnetsocket->address.addressdata.inet6) : sizeof(lhnetsocket->address.addressdata.inet4);
if (bind(lhnetsocket->inetsocket, (struct sockaddr *)&lhnetsocket->address.addressdata, namelen) != -1)
{
}
else
Con_Printf("LHNET_OpenSocket_Connectionless: ioctlsocket returned error: %s\n", LHNETPRIVATE_StrError());
-#ifdef WIN32
closesocket(lhnetsocket->inetsocket);
-#else
- close(lhnetsocket->inetsocket);
-#endif
}
else
Con_Printf("LHNET_OpenSocket_Connectionless: socket returned error: %s\n", LHNETPRIVATE_StrError());
// no special close code for loopback, just inet
if (lhnetsocket->address.addresstype == LHNETADDRESSTYPE_INET4 || lhnetsocket->address.addresstype == LHNETADDRESSTYPE_INET6)
{
-#ifdef WIN32
closesocket(lhnetsocket->inetsocket);
-#else
- close(lhnetsocket->inetsocket);
-#endif
}
#ifdef WIN32
if (lhnet_socketlist.next == &lhnet_socketlist && lhnet_didWSAStartup)
}
else if (value == -1)
{
-#ifdef WIN32
- int e = WSAGetLastError();
- if (e == WSAEWOULDBLOCK)
+ int e = SOCKETERRNO;
+ if (e == EWOULDBLOCK)
return 0;
switch (e)
- {
- case WSAECONNREFUSED:
- Con_Print("Connection refused\n");
- return 0;
- }
-#else
- if (errno == EWOULDBLOCK)
- return 0;
- switch (errno)
{
case ECONNREFUSED:
Con_Print("Connection refused\n");
return 0;
}
-#endif
}
}
else if (lhnetsocket->address.addresstype == LHNETADDRESSTYPE_INET6)
}
else if (value == -1)
{
-#ifdef WIN32
- int e = WSAGetLastError();
- if (e == WSAEWOULDBLOCK)
+ int e = SOCKETERRNO;
+ if (e == EWOULDBLOCK)
return 0;
switch (e)
- {
- case WSAECONNREFUSED:
- Con_Print("Connection refused\n");
- return 0;
- }
-#else
- if (errno == EWOULDBLOCK)
- return 0;
- switch (errno)
{
case ECONNREFUSED:
Con_Print("Connection refused\n");
return 0;
}
-#endif
}
}
return value;
value = sendto(lhnetsocket->inetsocket, content, contentlength, 0, (struct sockaddr *)&address->addressdata.inet4, sizeof(address->addressdata.inet4));
if (value == -1)
{
-#ifdef WIN32
- int e = WSAGetLastError();
- if (e == WSAEWOULDBLOCK)
- return 0;
-#else
- if (errno == EWOULDBLOCK)
+ if (SOCKETERRNO == EWOULDBLOCK)
return 0;
-#endif
}
}
else if (lhnetsocket->address.addresstype == LHNETADDRESSTYPE_INET6)
value = sendto(lhnetsocket->inetsocket, content, contentlength, 0, (struct sockaddr *)&address->addressdata.inet6, sizeof(address->addressdata.inet6));
if (value == -1)
{
-#ifdef WIN32
- int e = WSAGetLastError();
- if (e == WSAEWOULDBLOCK)
+ if (SOCKETERRNO == EWOULDBLOCK)
return 0;
-#else
- if (errno == EWOULDBLOCK)
- return 0;
-#endif
}
}
return value;