summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-04-27 22:20:49 +0200
committermadmaxoft <github@xoft.cz>2014-04-27 22:20:49 +0200
commitf301d052cfa70d00f76c31fcad4f961040736a80 (patch)
tree7ab0633617131ef27594f50e6e531483d8103a29 /src
parentFixed C++11 check for SharedPtr. (diff)
downloadcuberite-f301d052cfa70d00f76c31fcad4f961040736a80.tar
cuberite-f301d052cfa70d00f76c31fcad4f961040736a80.tar.gz
cuberite-f301d052cfa70d00f76c31fcad4f961040736a80.tar.bz2
cuberite-f301d052cfa70d00f76c31fcad4f961040736a80.tar.lz
cuberite-f301d052cfa70d00f76c31fcad4f961040736a80.tar.xz
cuberite-f301d052cfa70d00f76c31fcad4f961040736a80.tar.zst
cuberite-f301d052cfa70d00f76c31fcad4f961040736a80.zip
Diffstat (limited to '')
-rw-r--r--src/OSSupport/Socket.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/OSSupport/Socket.cpp b/src/OSSupport/Socket.cpp
index c29e495c3..98f694a79 100644
--- a/src/OSSupport/Socket.cpp
+++ b/src/OSSupport/Socket.cpp
@@ -295,7 +295,7 @@ bool cSocket::ConnectToLocalhostIPv4(unsigned short a_Port)
bool cSocket::ConnectIPv4(const AString & a_HostNameOrAddr, unsigned short a_Port)
{
- // First try IP Address string to hostent conversion, because it's faster
+ // First try IP Address string to hostent conversion, because it's faster and local:
unsigned long addr = inet_addr(a_HostNameOrAddr.c_str());
if (addr == INADDR_NONE)
{
@@ -307,10 +307,16 @@ bool cSocket::ConnectIPv4(const AString & a_HostNameOrAddr, unsigned short a_Por
CloseSocket();
return false;
}
- // Should be optimised to a single word copy
memcpy(&addr, hp->h_addr, hp->h_length);
}
+ // If the socket is not created yet, create one:
+ if (!IsValid())
+ {
+ m_Socket = socket((int)IPv4, SOCK_STREAM, 0);
+ }
+
+ // Connect the socket:
sockaddr_in server;
server.sin_addr.s_addr = addr;
server.sin_family = AF_INET;