mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Add very basic test for Unix sockets
This commit is contained in:
parent
1a236dbefc
commit
eb31a52b83
|
@ -1053,6 +1053,7 @@ if(GTEST_FOUND OR DOWNLOAD_GTEST)
|
|||
test.cpp
|
||||
test.h
|
||||
thread.cpp
|
||||
unix.cpp
|
||||
)
|
||||
set(TESTS_EXTRA
|
||||
src/game/server/teehistorian.cpp
|
||||
|
|
|
@ -1826,7 +1826,7 @@ int net_init()
|
|||
}
|
||||
|
||||
#if defined(CONF_FAMILY_UNIX)
|
||||
UNIXSOCKET net_unnamed_unix_create()
|
||||
UNIXSOCKET net_unix_create_unnamed()
|
||||
{
|
||||
return socket(AF_UNIX, SOCK_DGRAM, 0);
|
||||
}
|
||||
|
@ -1842,6 +1842,11 @@ void net_unix_set_addr(UNIXSOCKETADDR *addr, const char *path)
|
|||
addr->sun_family = AF_UNIX;
|
||||
str_copy(addr->sun_path, path, sizeof(addr->sun_path));
|
||||
}
|
||||
|
||||
void net_unix_close(UNIXSOCKET sock)
|
||||
{
|
||||
close(sock);
|
||||
}
|
||||
#endif
|
||||
|
||||
int fs_listdir_info(const char *dir, FS_LISTDIR_INFO_CALLBACK cb, int type, void *user)
|
||||
|
|
|
@ -837,13 +837,13 @@ int net_tcp_close(NETSOCKET sock);
|
|||
/* Group: Network Unix Sockets */
|
||||
|
||||
/*
|
||||
Function: net_unnamed_unix_create
|
||||
Creates an unnamed unix dgram socket.
|
||||
Function: net_unix_create_unnamed
|
||||
Creates an unnamed unix datagram socket.
|
||||
|
||||
Returns:
|
||||
On success it returns a handle to the socket. On failure it returns -1.
|
||||
*/
|
||||
UNIXSOCKET net_unnamed_unix_create();
|
||||
UNIXSOCKET net_unix_create_unnamed();
|
||||
|
||||
/*
|
||||
Function: net_unix_send
|
||||
|
@ -869,6 +869,16 @@ int net_unix_send(UNIXSOCKET sock, UNIXSOCKETADDR *addr, void *data, int size);
|
|||
path - Path to the (named) unix socket.
|
||||
*/
|
||||
void net_unix_set_addr(UNIXSOCKETADDR *addr, const char *path);
|
||||
|
||||
/*
|
||||
Function: net_unix_close
|
||||
Closes a Unix socket.
|
||||
|
||||
Parameters:
|
||||
sock - Socket to close.
|
||||
*/
|
||||
void net_unix_close(UNIXSOCKET sock);
|
||||
|
||||
#endif
|
||||
|
||||
/* Group: Strings */
|
||||
|
|
|
@ -863,7 +863,7 @@ void CServer::SendConnLoggingCommand(CONN_LOGGING_CMD Cmd, const NETADDR* pAddr)
|
|||
mem_copy(&aData[5], pAddr->ip, 16);
|
||||
mem_copy(&aData[21], &pAddr->port, 2);
|
||||
|
||||
net_unix_socket_send(m_ConnLoggingSocket, &m_ConnLoggingDestAddr, aData, sizeof(aData));
|
||||
net_unix_send(m_ConnLoggingSocket, &m_ConnLoggingDestAddr, aData, sizeof(aData));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -2652,7 +2652,7 @@ void CServer::ConchainConnLoggingServerChange(IConsole::IResult *pResult, void *
|
|||
// open socket to send new connections
|
||||
if(!pServer->m_ConnLoggingSocketCreated)
|
||||
{
|
||||
pServer->m_ConnLoggingSocket = net_unnamed_unix_socket_create();
|
||||
pServer->m_ConnLoggingSocket = net_unix_create_unnamed();
|
||||
if(pServer->m_ConnLoggingSocket == -1)
|
||||
{
|
||||
pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "Failed to created socket for communication with the connection logging server.");
|
||||
|
@ -2664,7 +2664,7 @@ void CServer::ConchainConnLoggingServerChange(IConsole::IResult *pResult, void *
|
|||
}
|
||||
|
||||
// set the destination address for the connection logging
|
||||
net_unix_socket_set_addr(&pServer->m_ConnLoggingDestAddr, pResult->GetString(0));
|
||||
net_unix_set_addr(&pServer->m_ConnLoggingDestAddr, pResult->GetString(0));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <gtest/gtest.h>
|
||||
|
||||
#include <base/detect.h>
|
||||
#include <engine/shared/config.h>
|
||||
#include <game/gamecore.h>
|
||||
#include <game/server/teehistorian.h>
|
||||
|
|
12
src/test/unix.cpp
Normal file
12
src/test/unix.cpp
Normal file
|
@ -0,0 +1,12 @@
|
|||
#include <gtest/gtest.h>
|
||||
|
||||
#include <base/system.h>
|
||||
|
||||
#if defined(CONF_FAMILY_UNIX)
|
||||
TEST(Unix, Create)
|
||||
{
|
||||
UNIXSOCKET Socket = net_unix_create_unnamed();
|
||||
ASSERT_GE(Socket, 0);
|
||||
net_unix_close(Socket);
|
||||
}
|
||||
#endif
|
Loading…
Reference in a new issue