I'm developing a networking library in C++. I have a method that sends a network packet. Signature:
void Send(PacketId packet_id,
const UserPacket& user_packet,
const std::shared_ptr<RemoteSystem>& remote_system,
bool broadcast,
std::function<void(Packet* p)>&& response_callback,
uint32_t response_timeout,
std::function<void()>&& response_timeout_callback,
uint32_t response_to_packet);
Arguments:
packet_id
- Packet iduser_packet
- User packet dataremote_system
- remote system to send a packetbroadcast
- broadcasting mode. if true - sends to all connected systems excludingremote_system
response_callback
- waits for the response to the sent packetresponse_timeout
- waiting for the response timeout in millisecondsresponse_timeout_callback
- callback that will be called when response timed outresponse_to_packet
- ID of a received packet to respond to
Have bigger than 3 arguments it's a bad practice. So, how can I design my code better? What design pattern can you advise me? Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire