Meta 1
This commit is contained in:
parent
6e4d86f37d
commit
3da12c53b5
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "gcc-8 build and debug active file",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "/home/zmiguel/TP/${fileBasenameNoExtension}",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "/home/zmiguel/TP",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
],
|
||||
"preLaunchTask": "gcc-8 build active file",
|
||||
"miDebuggerPath": "/usr/bin/gdb"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "shell",
|
||||
"label": "gcc-8 build active file",
|
||||
"command": "/usr/bin/gcc-8",
|
||||
"args": [
|
||||
"-g",
|
||||
"${file}",
|
||||
"-o",
|
||||
"/home/zmiguel/TP/${fileBasenameNoExtension}"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "/usr/bin"
|
||||
},
|
||||
"problemMatcher": [
|
||||
"$gcc"
|
||||
],
|
||||
"group": "build"
|
||||
}
|
||||
]
|
||||
}
|
4
client.c
4
client.c
|
@ -15,7 +15,7 @@
|
|||
|
||||
int main(int argc, char *argv[]){
|
||||
int sair=0, test=-1;
|
||||
char str[80], *palavra[10], *username[30];
|
||||
char str[80], *palavra[10], username[30];
|
||||
int i;
|
||||
|
||||
cl2sv msg2sv;
|
||||
|
@ -111,7 +111,7 @@ int main(int argc, char *argv[]){
|
|||
i = write(fd_servidor, &msg2sv, sizeof(msg2sv));
|
||||
}else if(strcmp(palavra[0],"verifica")==0){
|
||||
strcpy(msg2sv.cmd, "verifica");
|
||||
strcpy(msg2sv.opts,palavra[1]);
|
||||
strcpy(msg2sv.opts, palavra[1]);
|
||||
/* ENVIAR PEDIDO PARA "CP" DO SERVIDOR (write) */
|
||||
i = write(fd_servidor, &msg2sv, sizeof(msg2sv));
|
||||
//ler resposta do servidor
|
||||
|
|
1
dec.h
1
dec.h
|
@ -7,3 +7,4 @@ void listusers(clients *users);
|
|||
void closeapp(int sig);
|
||||
void desligarClientes(clients *users);
|
||||
clients *removeUser(clients *users, char *cp, int *nUsers);
|
||||
void verificador(char *verify);
|
51
server.c
51
server.c
|
@ -5,6 +5,8 @@
|
|||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <time.h>
|
||||
#include <ncurses.h>
|
||||
#include <signal.h>
|
||||
|
@ -27,7 +29,7 @@ int main(int argc, char *argv[]){
|
|||
int userCounter = 0;
|
||||
|
||||
srand(time(NULL));
|
||||
int fd_servidor, fd_cliente, fd_child[2];
|
||||
int fd_servidor, fd_cliente;
|
||||
/* VERIFICAR SE EXISTE "CP" DO SERVIDOR (access) -- APENAS UM!!!*/
|
||||
if(access("CPservidor", F_OK)==0){
|
||||
printf("[SERVIDOR] Ja existe um servidor!\n");
|
||||
|
@ -93,21 +95,7 @@ int main(int argc, char *argv[]){
|
|||
printf("[SERVER] Cliente removido!\n");
|
||||
uinit = users;
|
||||
}else if(strcmp(clResp.cmd,"verifica")==0){
|
||||
printf("[SERVER] A verificar '%s'\n",clResp.opts);
|
||||
pipe(fd_child);
|
||||
switch(fork()){
|
||||
case 0://child
|
||||
close(fd_child[1]);
|
||||
dup2(fd_child[0], STDIN_FILENO);
|
||||
close(fd_child[0]);
|
||||
execl("verificador", "./verificador", "words.txt", NULL);
|
||||
default://me
|
||||
close(fd_child[0]);
|
||||
write(fd_child[1], clResp.opts, sizeof(clResp.opts));
|
||||
close(fd_child[1]);
|
||||
wait(NULL);
|
||||
}
|
||||
|
||||
verificador(clResp.opts);
|
||||
}
|
||||
|
||||
}while(sair==0);
|
||||
|
@ -168,7 +156,7 @@ clients *addUser(clients *users, int *nUsers, char *username, int pid, char *fif
|
|||
|
||||
char *getUsernameFromfifo(clients *users, char *fifo){
|
||||
clients *uinit = users;
|
||||
char send[100];
|
||||
char *send = malloc(sizeof(char)*100);
|
||||
while(users!=NULL){
|
||||
if(strcmp(users->fifostr,fifo)==0){
|
||||
strcpy(send,users->nome);
|
||||
|
@ -220,3 +208,32 @@ clients *removeUser(clients *users, char *cp, int *nUsers){
|
|||
}
|
||||
return uinit;
|
||||
}
|
||||
|
||||
void verificador(char *verify){
|
||||
int fd_child[2], estado;
|
||||
|
||||
pipe(fd_child);
|
||||
switch(fork()){
|
||||
case 0://child
|
||||
/*close(fd_child[1]);
|
||||
dup2(fd_child[0], STDIN_FILENO);
|
||||
close(fd_child[0]);*/
|
||||
close(0);
|
||||
dup(fd_child[0]);
|
||||
close(fd_child[1]);
|
||||
close(fd_child[0]);
|
||||
execl("verificador", "./verificador", "words.txt", NULL);
|
||||
break;
|
||||
default://me
|
||||
/*close(fd_child[0]);
|
||||
write(fd_child[1], clResp.opts, sizeof(clResp.opts));
|
||||
close(fd_child[1]);*/
|
||||
close(1);
|
||||
dup(fd_child[1]);
|
||||
printf("%s\n",verify);
|
||||
close(fd_child[0]);
|
||||
close(fd_child[1]);
|
||||
close(1);
|
||||
wait(&estado);
|
||||
}
|
||||
}
|
12
util.h
12
util.h
|
@ -14,16 +14,18 @@ typedef struct st_mensagem{
|
|||
int duracao;
|
||||
int time_added;
|
||||
|
||||
struct topic * topico;
|
||||
struct mensagem * prox;
|
||||
struct st_topic * topico;
|
||||
struct st_mensagem * prox;
|
||||
}mensagem;
|
||||
|
||||
typedef struct st_topic{
|
||||
int id;
|
||||
char nome[TAM_NOME];
|
||||
struct mensagem * mensg;
|
||||
struct topic * prox;
|
||||
struct st_mensagem * mensg;
|
||||
struct st_topic * prox;
|
||||
}topic;
|
||||
|
||||
|
||||
//guardar clientes
|
||||
typedef struct st_clients{
|
||||
int pid;
|
||||
|
@ -31,7 +33,7 @@ typedef struct st_clients{
|
|||
char fifostr[TAM_NOME];
|
||||
int topics[TAM_SUB];
|
||||
|
||||
struct clients *prox;
|
||||
struct st_clients *prox;
|
||||
}clients;
|
||||
|
||||
//estructura dados de cliente --> servidor
|
||||
|
|
BIN
verificador
BIN
verificador
Binary file not shown.
Loading…
Reference in New Issue