Compare commits

...

16 Commits
v0.1 ... main

Author SHA1 Message Date
Vinicius Silva 04a71cbcb8
Merge pull request #8 from viniciusfdasilva/dev
Dev
2023-12-27 23:22:37 -03:00
Vinicius Silva f9c186ae95
Update test.yml 2023-12-26 20:16:25 -03:00
Vinicius Silva b62d57b2e2
Update test.yml 2023-12-26 20:15:12 -03:00
Vinicius Silva bcba19f917 Configuration github workflow 2023-12-26 20:13:00 -03:00
Vinicius Silva 676c923e5c
Merge pull request #6 from viniciusfdasilva/dev
Dev
2023-12-20 12:15:56 -03:00
Vinicius b4330a0b1f Fix error socket connection with void* 2023-12-20 12:08:14 -03:00
Vinicius b85e479c47 Inlcude own libraries fixed 2023-12-20 09:31:46 -03:00
Vinicius b5ff77cc41 Configuring CMake file 2023-12-19 23:55:33 -03:00
Vinicius af470b670b Configuring CMake file 2023-12-19 23:54:44 -03:00
Vinicius 00c06e2bad Fix include problems 2023-12-19 23:47:10 -03:00
Vinicius 89a8a2fda9 Configuring cmake to install own includes to pattern include 2023-12-19 23:35:33 -03:00
Vinicius 61d9911195 Replate includes to diamonds 2023-12-19 00:12:50 -03:00
Vinicius Silva 4fba1dd7b4
Merge pull request #4 from viniciusfdasilva/dev
Add pipe times
2023-12-18 20:08:17 -03:00
Vinicius Silva 51604709c0 Add pipe times 2023-12-18 18:10:43 -03:00
Vinicius Silva 5f7a523ec9
Merge pull request #3 from viniciusfdasilva/dev
Removing trash
2023-12-18 12:03:16 -03:00
Vinicius 8dddcedaec Removing trash 2023-12-18 11:59:24 -03:00
11 changed files with 95 additions and 31 deletions

27
.github/workflows/test.yml vendored Normal file
View File

@ -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
.gitignore vendored
View File

@ -3,6 +3,9 @@
*.vscode/settings.json
.vscode/settings.json
bin
# Object files
*.o
*.ko

View File

@ -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})

View File

@ -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')

BIN
graphics/full_with_pipe.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

View File

@ -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__

View File

@ -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;

View File

@ -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;

View File

@ -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()

View File

@ -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)
{

View File

@ -1,7 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "../include/utils.h"
#include <utils.h>
void panic(char* message)
{