# OS X fixes.
- Networking no longer tries to use IPV6, ignoring the family type of CSocketAddr. This address will be replaced when we switch to ENet anyway. - The name of the Atlas semaphore now also includes a timestamp, since the RNG generated the same sequence of names for multiple runs of the game, causing problems if the games crashed and leaked semaphores, and making debugging painful. - get_executable_name now also works if the game is within an app bundle (useful for packaging it more nicely later on, and since wxWidgets expects us to be in an app bundle). This was SVN commit r5407.
This commit is contained in:
parent
46dd72de18
commit
277ed33da6
@ -70,8 +70,19 @@ LibError sys_get_executable_name(char* n_path, size_t buf_size)
|
||||
}
|
||||
debug_printf("exe name before realpath: %s\n", temp);
|
||||
realpath(temp, name);
|
||||
debug_printf("exe name after realpath: %s\n", temp);
|
||||
}
|
||||
|
||||
// On OS X, we might be in a bundle. In this case set its name as our name.
|
||||
char* app = strstr(name, ".app");
|
||||
if (app) {
|
||||
// Remove everything after the .app
|
||||
*(app + strlen(".app")) = '\0';
|
||||
debug_printf("app bundle name: %s\n", name);
|
||||
}
|
||||
|
||||
strncpy(n_path, name, buf_size);
|
||||
debug_printf("exe name: %s\n", name);
|
||||
debug_printf("returning exe name: %s\n", name);
|
||||
|
||||
return INFO::OK;
|
||||
}
|
||||
|
@ -106,31 +106,9 @@ CSocketAddress CSocketAddress::Loopback(int port, ESocketProtocol proto)
|
||||
|
||||
PS_RESULT CSocketAddress::Resolve(const char *name, int port, CSocketAddress &addr)
|
||||
{
|
||||
addrinfo *ai;
|
||||
int res=getaddrinfo(name, NULL, NULL, &ai);
|
||||
if (res == 0)
|
||||
{
|
||||
if (ai->ai_addrlen < sizeof(addr.m_Union))
|
||||
cpu_memcpy(&addr.m_Union, ai->ai_addr, ai->ai_addrlen);
|
||||
switch (addr.m_Union.m_Family)
|
||||
{
|
||||
case IPv4:
|
||||
addr.m_Union.m_IPv4.sin_port=htons(port);
|
||||
break;
|
||||
case IPv6:
|
||||
addr.m_Union.m_IPv6.sin6_port=htons(port);
|
||||
break;
|
||||
}
|
||||
freeaddrinfo(ai);
|
||||
return PS_OK;
|
||||
}
|
||||
// supported, but failed
|
||||
if (errno != ENOSYS)
|
||||
return NO_SUCH_HOST;
|
||||
// else: IPv6 not supported, fall back to IPv4
|
||||
|
||||
// Use IPV4 by default, ignoring address type.
|
||||
memset(&addr.m_Union, 0, sizeof(addr.m_Union));
|
||||
hostent *he;
|
||||
|
||||
addr.m_Union.m_IPv4.sin_family=AF_INET;
|
||||
addr.m_Union.m_IPv4.sin_port=htons(port);
|
||||
// Try to parse dot-notation IP
|
||||
@ -148,7 +126,7 @@ PS_RESULT CSocketAddress::Resolve(const char *name, int port, CSocketAddress &ad
|
||||
CStr CSocketAddress::GetString() const
|
||||
{
|
||||
char convBuf[NI_MAXHOST];
|
||||
int res=getnameinfo((sockaddr *)&m_Union, sizeof(m_Union), convBuf, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
|
||||
int res=getnameinfo((sockaddr *)&m_Union, sizeof(sockaddr), convBuf, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
|
||||
if (res == 0)
|
||||
return CStr(convBuf);
|
||||
// getnameinfo won't return a string for the IPv6 unspecified address
|
||||
@ -252,7 +230,8 @@ void *WaitLoopThreadMain(void *)
|
||||
|
||||
PS_RESULT CSocketBase::Initialize(ESocketProtocol proto)
|
||||
{
|
||||
int res=socket(proto, SOCK_STREAM, 0);
|
||||
// Use IPV4 by default, ignoring address type.
|
||||
int res=socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
NET_LOG("CSocketBase::Initialize(): socket() res: %d", res);
|
||||
|
||||
@ -438,7 +417,7 @@ PS_RESULT CSocketBase::Write(void *buf, uint len, uint *bytesWritten)
|
||||
|
||||
PS_RESULT CSocketBase::Connect(const CSocketAddress &addr)
|
||||
{
|
||||
int res = connect(m_pInternal->m_fd, (struct sockaddr *)(&addr.m_Union), sizeof(addr));
|
||||
int res = connect(m_pInternal->m_fd, (struct sockaddr *)(&addr.m_Union), sizeof(struct sockaddr));
|
||||
NET_LOG("connect returned %d [%d]", res, m_NonBlocking);
|
||||
|
||||
if (res != 0)
|
||||
@ -473,7 +452,7 @@ PS_RESULT CSocketBase::Bind(const CSocketAddress &address)
|
||||
|
||||
SetOpMask(READ);
|
||||
|
||||
res=bind(m_pInternal->m_fd, (struct sockaddr *)&address, sizeof(address));
|
||||
res=bind(m_pInternal->m_fd, (struct sockaddr *)&address, sizeof(struct sockaddr));
|
||||
if (res == -1)
|
||||
{
|
||||
PS_RESULT ret=PS_FAIL;
|
||||
@ -513,7 +492,7 @@ PS_RESULT CSocketBase::Bind(const CSocketAddress &address)
|
||||
|
||||
PS_RESULT CSocketBase::PreAccept(CSocketAddress &addr)
|
||||
{
|
||||
socklen_t addrLen=sizeof(addr.m_Union);
|
||||
socklen_t addrLen=sizeof(struct sockaddr_in);
|
||||
int fd=accept(m_pInternal->m_fd, (struct sockaddr *)&addr.m_Union, &addrLen);
|
||||
m_pInternal->m_AcceptFd=fd;
|
||||
m_pInternal->m_AcceptAddr=addr;
|
||||
@ -640,8 +619,7 @@ void CSocketBase::SocketReadable(CSocketBase *pSock)
|
||||
int res=ioctl(pSock->m_pInternal->m_fd, FIONREAD, &nRead);
|
||||
// failure, errno=EINVAL means server socket
|
||||
// success, nRead != 0 means alive stream socket
|
||||
if ((res == -1 && errno != EINVAL) ||
|
||||
(res == 0 && nRead == 0))
|
||||
if (res == -1 && errno != EINVAL)
|
||||
{
|
||||
NET_LOG("RunWaitLoop:ioctl: Connection broken [%d:%s]", errno, strerror(errno));
|
||||
// Don't use API function - we both hold a lock and
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef INCLUDED_TRASTARENGINE
|
||||
#define INCLUDED_TRASTARENGINE
|
||||
|
||||
#include "simulation\astarengine.h"
|
||||
#include "AStarEngine.h"
|
||||
|
||||
class CTRAStarEngine :
|
||||
public CAStarEngine
|
||||
|
@ -270,6 +270,7 @@ template bool ScriptInterface::FromJSVal<wxString>(JSContext*, jsval, wxString&)
|
||||
|
||||
template bool ScriptInterface::FromJSVal<float>(JSContext*, jsval, float&);
|
||||
|
||||
template jsval ScriptInterface::ToJSVal<wxString>(JSContext*, wxString const&);
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -15,11 +15,14 @@ MessagePasserImpl::MessagePasserImpl()
|
||||
int tries = 0;
|
||||
while (tries++ < 16) // some arbitrary cut-off point to avoid infinite loops
|
||||
{
|
||||
CStr name = "/wfg-atlas-msgpass-" + CStr(rand(100000, 1000000));
|
||||
static char name[1024];
|
||||
sprintf(name, "/wfg-atlas-msgpass-%d-%d",
|
||||
rand(1, 1000), (int)(time(0)%1000));
|
||||
sem_t* sem = sem_open(name, O_CREAT | O_EXCL, 0700, 0);
|
||||
|
||||
// This cast should not be necessary, but apparently SEM_FAILED is not
|
||||
// a value of a pointer type
|
||||
if (sem == (sem_t*)SEM_FAILED)
|
||||
if (sem == (sem_t*)SEM_FAILED || !sem)
|
||||
{
|
||||
int err = errno;
|
||||
if (err == EEXIST)
|
||||
@ -28,7 +31,6 @@ MessagePasserImpl::MessagePasserImpl()
|
||||
continue;
|
||||
}
|
||||
// Otherwise, it's a probably-fatal error
|
||||
debug_printf("errno: %d (%s)\n", err, strerror(err));
|
||||
debug_warn("sem_open failed");
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user