mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-16 05:11:29 +00:00
Fix for crash on bind
This commit is contained in:
parent
23120bcde6
commit
960da66b87
@ -352,7 +352,7 @@ IF(EQEMU_BUILD_SERVER)
|
|||||||
ADD_SUBDIRECTORY(world)
|
ADD_SUBDIRECTORY(world)
|
||||||
ADD_SUBDIRECTORY(zone)
|
ADD_SUBDIRECTORY(zone)
|
||||||
ADD_SUBDIRECTORY(ucs)
|
ADD_SUBDIRECTORY(ucs)
|
||||||
ADD_SUBDIRECTORY(queryserv)
|
#ADD_SUBDIRECTORY(queryserv)
|
||||||
ADD_SUBDIRECTORY(eqlaunch)
|
ADD_SUBDIRECTORY(eqlaunch)
|
||||||
ENDIF(EQEMU_BUILD_SERVER)
|
ENDIF(EQEMU_BUILD_SERVER)
|
||||||
IF(EQEMU_BUILD_LOGIN)
|
IF(EQEMU_BUILD_LOGIN)
|
||||||
|
|||||||
@ -27,16 +27,18 @@ void EQ::Net::TCPServer::Listen(int port, bool ipv6, std::function<void(std::sha
|
|||||||
memset(m_socket, 0, sizeof(uv_tcp_t));
|
memset(m_socket, 0, sizeof(uv_tcp_t));
|
||||||
uv_tcp_init(loop, m_socket);
|
uv_tcp_init(loop, m_socket);
|
||||||
|
|
||||||
sockaddr iaddr;
|
|
||||||
if (ipv6) {
|
if (ipv6) {
|
||||||
uv_ip6_addr("::", port, (sockaddr_in6*)&iaddr);
|
sockaddr_in6 iaddr;
|
||||||
|
uv_ip6_addr("::", port, &iaddr);
|
||||||
|
uv_tcp_bind(m_socket, (sockaddr*)&iaddr, 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
uv_ip4_addr("0.0.0.0", port, (sockaddr_in*)&iaddr);
|
sockaddr_in iaddr;
|
||||||
|
uv_ip4_addr("0.0.0.0", port, &iaddr);
|
||||||
|
uv_tcp_bind(m_socket, (sockaddr*)&iaddr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_socket->data = this;
|
m_socket->data = this;
|
||||||
uv_tcp_bind(m_socket, &iaddr, 0);
|
|
||||||
|
|
||||||
uv_listen((uv_stream_t*)m_socket, 128, [](uv_stream_t* server, int status) {
|
uv_listen((uv_stream_t*)m_socket, 128, [](uv_stream_t* server, int status) {
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
|
|||||||
28
ucs/ucs.cpp
28
ucs/ucs.cpp
@ -33,6 +33,8 @@
|
|||||||
#include <list>
|
#include <list>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include "../common/net/tcp_server.h"
|
||||||
|
|
||||||
ChatChannelList *ChannelList;
|
ChatChannelList *ChannelList;
|
||||||
Clientlist *g_Clientlist;
|
Clientlist *g_Clientlist;
|
||||||
EQEmuLogSys Log;
|
EQEmuLogSys Log;
|
||||||
@ -142,6 +144,32 @@ int main() {
|
|||||||
|
|
||||||
worldserver->Connect();
|
worldserver->Connect();
|
||||||
|
|
||||||
|
EQ::Net::TCPServer server;
|
||||||
|
std::vector<std::shared_ptr<EQ::Net::TCPConnection>> connections;
|
||||||
|
server.Listen(5999, true, [&](std::shared_ptr<EQ::Net::TCPConnection> connection) {
|
||||||
|
Log.OutF(Logs::General, Logs::Debug, "New connection found.");
|
||||||
|
connections.push_back(connection);
|
||||||
|
|
||||||
|
connection->OnRead([](EQ::Net::TCPConnection *connection, const unsigned char *data, size_t length) {
|
||||||
|
EQ::Net::ReadOnlyPacket p((void*)data, length);
|
||||||
|
Log.OutF(Logs::General, Logs::Debug, "{0}", p.ToString());
|
||||||
|
});
|
||||||
|
|
||||||
|
connection->OnDisconnect([&](EQ::Net::TCPConnection *connection) {
|
||||||
|
auto iter = connections.begin();
|
||||||
|
while (iter != connections.end()) {
|
||||||
|
if ((*iter).get() == connection) {
|
||||||
|
Log.OutF(Logs::General, Logs::Debug, "Removing connection");
|
||||||
|
connections.erase(iter);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
iter++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
connection->Start();
|
||||||
|
});
|
||||||
|
|
||||||
while(RunLoops) {
|
while(RunLoops) {
|
||||||
|
|
||||||
Timer::SetCurrentTime();
|
Timer::SetCurrentTime();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user