Skip to content

Commit

Permalink
netplay/netsocket: remove SocketSet struct
Browse files Browse the repository at this point in the history
It's not used anymore and it's completely replaced
by the more advanced `IDescriptorSet`.

Signed-off-by: Pavel Solodovnikov <pavel.al.solodovnikov@gmail.com>
  • Loading branch information
ManManson committed Feb 20, 2025
1 parent fd02292 commit a5b7614
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 55 deletions.
49 changes: 0 additions & 49 deletions lib/netplay/tcp/netsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ struct Socket
char textAddress[40] = {};
};

struct SocketSet
{
std::vector<Socket *> fds;
};

SOCKET getRawSocketFd(const Socket& sock)
{
return sock.fd[SOCK_CONNECTION];
Expand Down Expand Up @@ -333,50 +328,6 @@ bool socketSetTCPNoDelay(Socket& sock, bool nodelay)
#endif
}

SocketSet *allocSocketSet()
{
return new SocketSet;
}

void deleteSocketSet(SocketSet *set)
{
delete set;
}

/**
* Add the given socket to the given socket set.
*
* @return true if @c socket is successfully added to @set.
*/
void SocketSet_AddSocket(SocketSet& set, Socket *socket)
{
/* Check whether this socket is already present in this set (i.e. it
* shouldn't be added again).
*/
size_t i = std::find(set.fds.begin(), set.fds.end(), socket) - set.fds.begin();
if (i != set.fds.size())
{
debug(LOG_NET, "Already found, socket: (set->fds[%lu]) %p", (unsigned long)i, static_cast<void *>(socket));
return;
}

set.fds.push_back(socket);
debug(LOG_NET, "Socket added: set->fds[%lu] = %p", (unsigned long)i, static_cast<void *>(socket));
}

/**
* Remove the given socket from the given socket set.
*/
void SocketSet_DelSocket(SocketSet& set, Socket *socket)
{
size_t i = std::find(set.fds.begin(), set.fds.end(), socket) - set.fds.begin();
if (i != set.fds.size())
{
debug(LOG_NET, "Socket %p erased (set->fds[%lu])", static_cast<void *>(socket), (unsigned long)i);
set.fds.erase(set.fds.begin() + i);
}
}

#if !defined(SOCK_CLOEXEC)
static bool setSocketInheritable(SOCKET fd, bool inheritable)
{
Expand Down
6 changes: 0 additions & 6 deletions lib/netplay/tcp/netsocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ namespace tcp
{

struct Socket;
struct SocketSet;

} // namespace tcp

Expand Down Expand Up @@ -114,11 +113,6 @@ void socketSetReadReady(Socket& sock, bool ready);
bool socketSetTCPNoDelay(Socket& sock, bool nodelay); ///< nodelay = true disables the Nagle algorithm for TCP socket

// Socket sets.
WZ_DECL_ALLOCATION SocketSet *allocSocketSet(); ///< Constructs a SocketSet.
WZ_DECL_NONNULL(1) void deleteSocketSet(SocketSet *set); ///< Destroys the SocketSet.

WZ_DECL_NONNULL(2) void SocketSet_AddSocket(SocketSet& set, Socket *socket); ///< Adds a Socket to a SocketSet.
WZ_DECL_NONNULL(2) void SocketSet_DelSocket(SocketSet& set, Socket *socket); ///< Removes a Socket from a SocketSet.
int checkSocketsReadable(const std::vector<IClientConnection*>& conns, IDescriptorSet& readableSet, unsigned int timeout); ///< Checks which Sockets are ready for reading. Returns the number of ready Sockets, or returns SOCKET_ERROR on error.

} // namespace tcp
Expand Down

0 comments on commit a5b7614

Please sign in to comment.