ft_irc 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
Server クラス

Implements the core IRC server functionality as a Singleton. [詳解]

#include <Server.hpp>

Server 連携図
Collaboration graph

公開メンバ関数

 ~Server ()
 Destroys the Server object, cleaning up all clients, channels, and the command manager.
 
void run ()
 Starts the IRC server, setting up the socket and entering the main event loop.
 
void addTestClient (Client *client)
 Adds a client directly to the server's management for testing purposes.
 
void acceptNewClient ()
 Accepts a new incoming client connection.
 
void removeClient (int fd)
 Removes a client from the server, closing its socket and freeing resources.
 
ClientgetClient (int fd)
 Retrieves a Client object by its file descriptor.
 
ClientgetClientByNickname (const std::string &nickname)
 Retrieves a Client object by its nickname.
 
void addChannel (Channel *channel)
 Adds a new channel to the server.
 
ChannelgetChannel (const std::string &name)
 Retrieves a Channel object by its name.
 
void removeChannel (const std::string &name)
 Removes a channel from the server, deleting the Channel object.
 
const std::map< std::string, Channel * > & getChannels () const
 Gets a constant reference to the map of channels managed by the server.
 
const std::map< int, Client * > & getClients () const
 Gets a constant reference to the map of clients managed by the server.
 
const std::stringgetPassword () const
 Gets the server's password.
 
const std::stringgetServerName () const
 Gets the server's name.
 

静的公開メンバ関数

static ServergetInstance (int port=-1, const std::string &password="")
 Gets the single instance of the Server (Singleton pattern).
 
static void resetInstance ()
 Resets the singleton instance of the Server for testing purposes.
 

詳解

Implements the core IRC server functionality as a Singleton.

This class is responsible for setting up the network socket, managing client connections, handling I/O events using poll(), dispatching commands through the CommandManager, and managing channels and clients. It follows the Singleton design pattern to ensure only one server instance exists.

Server.hpp49 行目に定義があります。

構築子と解体子

◆ ~Server()

Server::~Server ( )

Destroys the Server object, cleaning up all clients, channels, and the command manager.

Server.cpp77 行目に定義があります。

関数詳解

◆ acceptNewClient()

void Server::acceptNewClient ( )

Accepts a new incoming client connection.

Creates a new Client object, sets its socket to non-blocking, and adds it to the server's list of managed clients and pollfds.

Server.cpp262 行目に定義があります。

◆ addChannel()

void Server::addChannel ( Channel channel)

Adds a new channel to the server.

引数
channelA pointer to the Channel object to add.

Server.cpp400 行目に定義があります。

◆ addTestClient()

void Server::addTestClient ( Client client)

Adds a client directly to the server's management for testing purposes.

This bypasses the normal socket acceptance process and is intended for injecting mock clients in unit tests.

引数
clientA pointer to the Client object to add.

Server.cpp48 行目に定義があります。

◆ getChannel()

Channel * Server::getChannel ( const std::string name)

Retrieves a Channel object by its name.

引数
nameThe name of the channel.
戻り値
A pointer to the Channel object, or NULL if not found.

Server.cpp406 行目に定義があります。

◆ getChannels()

const std::map< std::string, Channel * > & Server::getChannels ( ) const

Gets a constant reference to the map of channels managed by the server.

戻り値
A constant map of channel names to Channel objects.

Server.cpp422 行目に定義があります。

◆ getClient()

Client * Server::getClient ( int  fd)

Retrieves a Client object by its file descriptor.

引数
fdThe file descriptor of the client.
戻り値
A pointer to the Client object, or NULL if not found.

Server.cpp383 行目に定義があります。

◆ getClientByNickname()

Client * Server::getClientByNickname ( const std::string nickname)

Retrieves a Client object by its nickname.

引数
nicknameThe nickname of the client.
戻り値
A pointer to the Client object, or NULL if not found.

Server.cpp391 行目に定義があります。

◆ getClients()

const std::map< int, Client * > & Server::getClients ( ) const

Gets a constant reference to the map of clients managed by the server.

戻り値
A constant map of client file descriptors to Client objects.

Server.cpp424 行目に定義があります。

◆ getInstance()

Server * Server::getInstance ( int  port = -1,
const std::string password = "" 
)
static

Gets the single instance of the Server (Singleton pattern).

引数
portThe port number for server initialization (used only on first call).
passwordThe password for server initialization (used only on first call).
戻り値
A pointer to the Server instance.

Server.cpp63 行目に定義があります。

◆ getPassword()

const std::string & Server::getPassword ( ) const

Gets the server's password.

戻り値
The server password.

Server.cpp379 行目に定義があります。

◆ getServerName()

const std::string & Server::getServerName ( ) const

Gets the server's name.

戻り値
The server name.

Server.cpp381 行目に定義があります。

◆ removeChannel()

void Server::removeChannel ( const std::string name)

Removes a channel from the server, deleting the Channel object.

引数
nameThe name of the channel to remove.

Server.cpp414 行目に定義があります。

◆ removeClient()

void Server::removeClient ( int  fd)

Removes a client from the server, closing its socket and freeing resources.

引数
fdThe file descriptor of the client to remove.

Server.cpp290 行目に定義があります。

◆ resetInstance()

void Server::resetInstance ( )
static

Resets the singleton instance of the Server for testing purposes.

This method should only be used in test environments to ensure a clean slate before each test case.

Server.cpp43 行目に定義があります。

◆ run()

void Server::run ( )

Starts the IRC server, setting up the socket and entering the main event loop.

例外
std::runtime_errorif socket setup fails.

Server.cpp101 行目に定義があります。


このクラス詳解は次のファイルから抽出されました: