my_teams
protocol.h File Reference
#include <netinet/in.h>
#include <sys/queue.h>
#include <stdbool.h>
Include dependency graph for protocol.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  p_network_data_s
 Represents network data including socket file descriptor and server address. More...
 
struct  p_packet_s
 Represents a packet with type and data. More...
 
struct  p_payload_s
 Represents a payload containing packet, network data, and actual data. More...
 
struct  p_client_s
 Represents a client with socket file descriptor and network data. More...
 
struct  p_server_s
 Represents a server with network data, file descriptor set, and list of clients. More...
 

Macros

#define DATA_SIZE   4096
 

Typedefs

typedef struct p_network_data_s p_network_data_t
 
typedef struct p_packet_s p_packet_t
 
typedef struct p_payload_s p_payload_t
 
typedef struct p_client_s p_client_t
 
typedef struct p_server_s p_server_t
 

Functions

p_client_tp_client_create (const char *ip, int port)
 Create a client with given IP and port. More...
 
p_payload_tp_client_listen (p_client_t *client)
 Listen for incoming packets on the client. More...
 
bool p_client_send_packet (const p_client_t *client, uint16_t type, const void *data, int size)
 Send a packet from the client. More...
 
p_server_tp_server_create (int port)
 Create a server with given port. More...
 
p_payload_tp_server_listen (p_server_t *server)
 Listen for incoming packets on the server. More...
 
bool p_server_send_packet (const p_packet_t *packet, int client_fd, p_server_t *server)
 Send a packet from the server to a specific client. More...
 
bool p_server_send_packet_type (uint16_t type, int client_fd, p_server_t *server)
 Send a packet from the server to a specific client. More...
 
p_payload_tp_create_payload (uint16_t packet_type, const void *payload_data)
 Create a payload with given packet type, data, and size. More...
 
bool new_client (p_server_t *server)
 Create a new client on the server. More...
 
bool select_server (p_server_t *server)
 Select the server for incoming packets. More...
 
bool server_bind (p_server_t *server)
 Bind the server to the given port. More...
 
bool server_listen (p_server_t *server)
 Listen for incoming connections on the server. More...
 
bool server_setsockopt (p_server_t *server)
 Set socket options for the server. More...
 
p_server_tserver_socket (int port)
 Create a socket for the server. More...
 
p_client_tget_client (int fd, const p_server_t *server)
 Get the client with the given file descriptor. More...
 
void p_server_close (p_server_t *server)
 Close the server. More...
 
bool p_server_is_open (void)
 Check if the server is open. More...
 
void p_client_close (p_client_t *client)
 Close the client. More...
 

Macro Definition Documentation

◆ DATA_SIZE

#define DATA_SIZE   4096

Typedef Documentation

◆ p_client_t

typedef struct p_client_s p_client_t

◆ p_network_data_t

◆ p_packet_t

typedef struct p_packet_s p_packet_t

◆ p_payload_t

typedef struct p_payload_s p_payload_t

◆ p_server_t

typedef struct p_server_s p_server_t

Function Documentation

◆ get_client()

p_client_t* get_client ( int  fd,
const p_server_t server 
)

Get the client with the given file descriptor.

Parameters
fdFile descriptor of the client.
serverPointer to the server.
Returns
Pointer to the client.
Here is the call graph for this function:

◆ new_client()

bool new_client ( p_server_t server)

Create a new client on the server.

Parameters
serverPointer to the server.
Returns
true on success, false on failure.
Here is the call graph for this function:

◆ p_client_close()

void p_client_close ( p_client_t client)

Close the client.

Parameters
clientPointer to the client.
Here is the call graph for this function:

◆ p_client_create()

p_client_t* p_client_create ( const char *  ip,
int  port 
)

Create a client with given IP and port.

Parameters
ipIP address of the server.
portPort number of the server.
Returns
Pointer to the created client.
Here is the call graph for this function:

◆ p_client_listen()

p_payload_t* p_client_listen ( p_client_t client)

Listen for incoming packets on the client.

Parameters
clientPointer to the client.
Returns
Pointer to the received payload.
Here is the call graph for this function:

◆ p_client_send_packet()

bool p_client_send_packet ( const p_client_t client,
uint16_t  type,
const void *  data,
int  size 
)

Send a packet from the client.

Parameters
clientPointer to the client.
typeType of the packet.
dataData to be included in the packet.
sizeSize of the data.
Returns
True on success, false on failure.
Here is the call graph for this function:

◆ p_create_payload()

p_payload_t* p_create_payload ( uint16_t  packet_type,
const void *  payload_data 
)

Create a payload with given packet type, data, and size.

Parameters
packet_typeType of the packet.
payload_dataData to be included in the payload.
Returns
Pointer to the created payload.

◆ p_server_close()

void p_server_close ( p_server_t server)

Close the server.

Parameters
serverPointer to the server.
Here is the call graph for this function:

◆ p_server_create()

p_server_t* p_server_create ( int  port)

Create a server with given port.

Parameters
portPort number to bind the server.
Returns
Pointer to the created server.
Here is the call graph for this function:

◆ p_server_is_open()

bool p_server_is_open ( void  )

Check if the server is open.

Returns
true if the server is open, false otherwise.

◆ p_server_listen()

p_payload_t* p_server_listen ( p_server_t server)

Listen for incoming packets on the server.

Parameters
serverPointer to the server.
Returns
Pointer to the received payload.
Here is the call graph for this function:

◆ p_server_send_packet()

bool p_server_send_packet ( const p_packet_t packet,
int  client_fd,
p_server_t server 
)

Send a packet from the server to a specific client.

Parameters
packetPointer to the packet to be sent.
client_fdFile descriptor of the client.
serverPointer to the server.
Returns
true on success, false on failure.
Here is the call graph for this function:

◆ p_server_send_packet_type()

bool p_server_send_packet_type ( uint16_t  type,
int  client_fd,
p_server_t server 
)

Send a packet from the server to a specific client.

Parameters
typeType of the packet.
client_fdFile descriptor of the client.
serverPointer to the server.
Returns
true on success, false on failure.
Here is the call graph for this function:

◆ select_server()

bool select_server ( p_server_t server)

Select the server for incoming packets.

Parameters
serverPointer to the server.
Returns
true on success, false on failure.
Here is the call graph for this function:

◆ server_bind()

bool server_bind ( p_server_t server)

Bind the server to the given port.

Parameters
serverPointer to the server.
Returns
true on success, false on failure.
Here is the call graph for this function:

◆ server_listen()

bool server_listen ( p_server_t server)

Listen for incoming connections on the server.

Parameters
serverPointer to the server.
Returns
true on success, false on failure.
Here is the call graph for this function:

◆ server_setsockopt()

bool server_setsockopt ( p_server_t server)

Set socket options for the server.

Parameters
serverPointer to the server.
Returns
true on success, false on failure.
Here is the call graph for this function:

◆ server_socket()

p_server_t* server_socket ( int  port)

Create a socket for the server.

Parameters
portPort number to bind the server.
Here is the call graph for this function: