Compare commits
16 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
04a71cbcb8 | |
|
|
f9c186ae95 | |
|
|
b62d57b2e2 | |
|
|
bcba19f917 | |
|
|
676c923e5c | |
|
|
b4330a0b1f | |
|
|
b85e479c47 | |
|
|
b5ff77cc41 | |
|
|
af470b670b | |
|
|
00c06e2bad | |
|
|
89a8a2fda9 | |
|
|
61d9911195 | |
|
|
4fba1dd7b4 | |
|
|
51604709c0 | |
|
|
5f7a523ec9 | |
|
|
8dddcedaec |
|
|
@ -0,0 +1,27 @@
|
|||
name: Pingpong
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [dev]
|
||||
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Set up CMake
|
||||
uses: threeal/cmake-action@v1.3.0
|
||||
with:
|
||||
cmake-version: 3.21
|
||||
|
||||
- name: Configure and build
|
||||
run: |
|
||||
cmake .
|
||||
make
|
||||
|
||||
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
*.vscode/settings.json
|
||||
.vscode/settings.json
|
||||
|
||||
bin
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
*.ko
|
||||
|
|
|
|||
|
|
@ -1,14 +1,26 @@
|
|||
cmake_minimum_required(VERSION 2.8)
|
||||
project(pingpong)
|
||||
|
||||
set(INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include)
|
||||
set(SRC_DIR ${CMAKE_SOURCE_DIR}/src)
|
||||
|
||||
execute_process(
|
||||
COMMAND mkdir -p bin
|
||||
COMMAND mkdir -p /usr/include/pingpong/
|
||||
)
|
||||
|
||||
include_directories(${INCLUDE_DIR})
|
||||
|
||||
set(INCLUDE_FILES
|
||||
${INCLUDE_DIR}/socket
|
||||
${INCLUDE_DIR}/pipe
|
||||
${INCLUDE_DIR}/utils
|
||||
)
|
||||
|
||||
set(SOURCE_FILES
|
||||
src/socket.c
|
||||
src/pipe.c
|
||||
src/utils.c
|
||||
${SRC_DIR}/socket.c
|
||||
${SRC_DIR}/pipe.c
|
||||
${SRC_DIR}/utils.c
|
||||
)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
|
@ -17,7 +29,8 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
|
|||
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -march=native")
|
||||
|
||||
include_directories(include)
|
||||
|
||||
add_executable(./bin/server ${SOURCE_FILES} ./src/main_server.c)
|
||||
add_executable(./bin/client ${SOURCE_FILES} ./src/main_client.c)
|
||||
|
||||
target_include_directories(./bin/server PUBLIC ${INCLUDE_DIR})
|
||||
target_include_directories(./bin/client PUBLIC ${INCLUDE_DIR})
|
||||
|
|
@ -5,6 +5,7 @@ import numpy as np
|
|||
tamanho_buffer = ["0.064", "0.128", "0.256", "0.512", "1", "2", "4", "8"]
|
||||
tempo_execucao_udp = [0.28, 0.24, 0.19, 0.17, 0.15, 0.14, 0.12, 0.09]
|
||||
tempo_execucao_tcp = [0.40,0.23,0.20,0.18,0.17,0.16,0.16,0.13]
|
||||
tempo_execucao_pipe = [0.01,0.01,0.01,0.01,0.01,0.01,0.012,0.01]
|
||||
tempo_execucao_unix = [0.22,0.19,0.19,0.12,0.15,0.10,0.08,0.05]
|
||||
|
||||
tempo_execucao_udp.reverse()
|
||||
|
|
@ -13,6 +14,7 @@ tempo_execucao_unix.reverse()
|
|||
|
||||
# Cria o gráfico de linha
|
||||
plt.plot(tamanho_buffer, tempo_execucao_tcp, marker='o', linestyle='-', label='Socket TCP')
|
||||
plt.plot(tamanho_buffer, tempo_execucao_pipe, marker='o', linestyle='-', label='Pipe Connection')
|
||||
plt.plot(tamanho_buffer, tempo_execucao_unix, marker='o', linestyle='-', label='Socket UNIXDOMAIN')
|
||||
plt.plot(tamanho_buffer, tempo_execucao_udp, marker='o', linestyle='-', label='Socket UDP')
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 43 KiB |
|
|
@ -20,8 +20,9 @@
|
|||
extern int create_socket(int sin_family, int sock);
|
||||
extern socket_address_unix config_unixdomain_server_address();
|
||||
extern socket_address_ipv4 config_tcp_upd_server_address();
|
||||
extern void connect_to_server(void* server_address, int client_socket);
|
||||
extern void connect_to_server(int socket_type, void* server_address, int client_socket);
|
||||
extern void bind_server(void* server_address, int socket_type, int server_socket);
|
||||
extern int accept_connection(int client_socket, void* client_address, int server_socket);
|
||||
extern int accept_connection(int socket_type, int client_socket, void* client_address, int server_socket);
|
||||
extern socklen_t attribuite_type_and_getsizeof(int socket_type, struct sockaddr* address, void* socket_address);
|
||||
|
||||
#endif // __SOCKET_H__
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#include "../include/socket.h"
|
||||
#include "../include/pipe.h"
|
||||
#include "../include/utils.h"
|
||||
#include <socket.h>
|
||||
#include <pipe.h>
|
||||
#include <utils.h>
|
||||
|
||||
#define N 10000
|
||||
|
||||
|
|
@ -73,14 +73,14 @@ void attribuite_and_init_socket(int socket_type)
|
|||
client_socket = create_socket(AF_INET, SOCK_STREAM);
|
||||
socket_address_ipv4 tcp_ip_address = config_tcp_upd_server_address();
|
||||
server_address = (void*)&tcp_ip_address;
|
||||
connect_to_server(server_address,client_socket);
|
||||
connect_to_server(socket_type, server_address,client_socket);
|
||||
break;
|
||||
|
||||
case UDP_SOCKET_FLAG: // UDP SOCKET
|
||||
client_socket = create_socket(AF_INET, SOCK_STREAM);
|
||||
socket_address_ipv4 udp_ip_address = config_tcp_upd_server_address();
|
||||
server_address = (void*)&udp_ip_address;
|
||||
connect_to_server(server_address,client_socket);
|
||||
connect_to_server(socket_type, server_address,client_socket);
|
||||
|
||||
break;
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ void attribuite_and_init_socket(int socket_type)
|
|||
client_socket = create_socket(AF_UNIX, SOCK_DGRAM);
|
||||
socket_address_unix unix_ip_address = config_unixdomain_server_address();
|
||||
server_address = (void*)&unix_ip_address;
|
||||
connect_to_server(server_address,client_socket);
|
||||
connect_to_server(socket_type, server_address,client_socket);
|
||||
|
||||
break;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include "../include/socket.h"
|
||||
#include "../include/pipe.h"
|
||||
#include "../include/utils.h"
|
||||
#include <socket.h>
|
||||
#include <pipe.h>
|
||||
#include <utils.h>
|
||||
|
||||
int num_of_read_bytes = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../include/pipe.h"
|
||||
#include "../include/utils.h"
|
||||
#include <pipe.h>
|
||||
#include <utils.h>
|
||||
|
||||
|
||||
int *create_pipe()
|
||||
|
|
|
|||
42
src/socket.c
42
src/socket.c
|
|
@ -7,8 +7,8 @@
|
|||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "../include/socket.h"
|
||||
#include "../include/utils.h"
|
||||
#include <socket.h>
|
||||
#include <utils.h>
|
||||
|
||||
int create_socket(int sin_family, int sock)
|
||||
{
|
||||
|
|
@ -43,13 +43,14 @@ socket_address_ipv4 config_tcp_upd_server_address()
|
|||
return server_address;
|
||||
}
|
||||
|
||||
void connect_to_server(void *server_address, int client_socket)
|
||||
void connect_to_server(int socket_type, void *server_address, int client_socket)
|
||||
{
|
||||
struct sockaddr* address = (struct sockaddr*)&server_address;
|
||||
struct sockaddr address;
|
||||
socklen_t address_sizeof = attribuite_type_and_getsizeof(socket_type, &address, server_address);
|
||||
|
||||
int connection_response = connect(client_socket,
|
||||
address,
|
||||
(socklen_t)sizeof(server_address)
|
||||
&address,
|
||||
address_sizeof
|
||||
);
|
||||
|
||||
if(connection_response == SOCKET_ERROR_CODE)
|
||||
|
|
@ -61,14 +62,29 @@ void connect_to_server(void *server_address, int client_socket)
|
|||
|
||||
}
|
||||
|
||||
socklen_t attribuite_type_and_getsizeof(int socket_type, struct sockaddr* address, void* socket_address)
|
||||
{
|
||||
if(socket_type == UNIX_SOCKET_FLAG)
|
||||
{
|
||||
address = (struct sockaddr*)&*((socket_address_unix*)socket_address);
|
||||
return (socklen_t)sizeof(*(socket_address_unix*)socket_address);
|
||||
}else
|
||||
{
|
||||
address = (struct sockaddr*)&*((socket_address_ipv4*)socket_address);
|
||||
return (socklen_t)sizeof(*(socket_address_ipv4*)socket_address);
|
||||
}
|
||||
}
|
||||
|
||||
void bind_server(void *server_address, int socket_type, int server_socket)
|
||||
{
|
||||
|
||||
struct sockaddr* address = (struct sockaddr*)&server_address;
|
||||
|
||||
struct sockaddr address;
|
||||
socklen_t address_sizeof = attribuite_type_and_getsizeof(socket_type, &address, server_address);
|
||||
|
||||
int server_bind_response = bind(server_socket, address, sizeof(server_address));
|
||||
int server_bind_response = bind(server_socket, &address, address_sizeof);
|
||||
|
||||
if (socket_type == UNIX_SOCKET_FLAG) unlink((const char*)address);
|
||||
if (socket_type == UNIX_SOCKET_FLAG) unlink((const char*)&address);
|
||||
|
||||
if(server_bind_response == SOCKET_ERROR_CODE)
|
||||
{
|
||||
|
|
@ -77,12 +93,14 @@ void bind_server(void *server_address, int socket_type, int server_socket)
|
|||
}
|
||||
}
|
||||
|
||||
int accept_connection(int client_socket, void *client_address, int server_socket)
|
||||
int accept_connection(int socket_type, int client_socket, void *client_address, int server_socket)
|
||||
{
|
||||
socklen_t client_addr_len = sizeof(client_address);
|
||||
struct sockaddr *address = (struct sockaddr*)&client_address;
|
||||
|
||||
struct sockaddr address;
|
||||
attribuite_type_and_getsizeof(socket_type, &address, client_address);
|
||||
|
||||
client_socket = accept(server_socket, address, &client_addr_len);
|
||||
client_socket = accept(server_socket, &address, &client_addr_len);
|
||||
|
||||
if(client_socket == SYSTEM_EXIT_FAILED)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../include/utils.h"
|
||||
#include <utils.h>
|
||||
|
||||
void panic(char* message)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue