16 #include "../../stdafx.h" 17 #include "../../thread/thread.h" 21 #include "../../safeguards.h" 37 *_tcp_connecters.
Append() =
this;
47 if (this->
sock == INVALID_SOCKET) {
74 _tcp_connecters.
Erase(iter);
75 if (cur->
sock != INVALID_SOCKET) closesocket(cur->
sock);
80 _tcp_connecters.
Erase(iter);
86 _tcp_connecters.
Erase(iter);
98 for (
TCPConnecter **iter = _tcp_connecters.
Begin(); iter != _tcp_connecters.
End(); iter++) (*iter)->killed =
true;
NetworkAddress address
Address we're connecting to.
static void KillAll()
Kill all connection attempts.
"Helper" class for creating TCP connections in a non-blocking manner
bool aborted
Whether we bailed out (i.e. connection making failed)
SOCKET sock
The socket we're connecting with.
static void ThreadEntry(void *param)
Entry point for the new threads.
static SmallVector< TCPConnecter *, 1 > _tcp_connecters
List of connections that are currently being created.
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
const T * Begin() const
Get the pointer to the first item (const)
class ThreadObject * thread
Thread used to create the TCP connection.
TCPConnecter(const NetworkAddress &address)
Create a new connecter for the given address.
virtual void OnConnect(SOCKET s)
Callback when the connection succeeded.
Simple vector template class.
const T * End() const
Get the pointer behind the last valid item (const)
T * Append(uint to_add=1)
Append an item and return it.
virtual void OnFailure()
Callback for when the connection attempt failed.
static void CheckCallbacks()
Check whether we need to call the callback, i.e.
bool killed
Whether we got killed.
SOCKET Connect()
Connect to the given address.
bool connected
Whether we succeeded in making the connection.
void Erase(T *item)
Removes given item from this vector.
Basic functions to receive and send TCP packets.
void Connect()
The actual connection function.
static bool New(OTTDThreadFunc proc, void *param, ThreadObject **thread=NULL, const char *name=NULL)
Create a thread; proc will be called as first function inside the thread, with optional params...