-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjogador.c
55 lines (46 loc) · 1.37 KB
/
jogador.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*****************************************************************************/
/* Laborátorio de Sistemas Operacionais */
/* Trabalho do Grau B (TGB) */
/* Autores: Nadine e Fernando */
/*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <mqueue.h>
//Nome da fila
const char* NOME_FILA = "/jogoVelha";
//Estrutura de dados para a mensagem
typedef struct JogoVelha {
char playerID[2];
int coord1;
int coord2;
} TJogoVelha;
//Método main
//Realiza o envio da mensagem da jogada
int main(int argc, char* argv[]) {
//Declaração da fila
mqd_t queue;
//Declaração da mensagem
TJogoVelha j;
char* jogador = argv[1];
//Obter descritor (mq_open+O_WRONLY+O_CREAT)
queue = mq_open(NOME_FILA, O_WRONLY | O_CREAT, 0770, NULL);
if (queue == (mqd_t) -1) {
perror("mq_open");
exit(2);
}
//Montar a mensagem
strcpy(j.playerID, jogador);
j.coord1 = atoi(argv[2]);
j.coord2 = atoi(argv[3]);
//Enviar (mq_send)
if (mq_send(queue, (const char*) &j, sizeof(TJogoVelha), 29) != 0) {
perror("send #29");
}
//Liberar descritor (mq_close)
mq_close(queue);
printf("Mensagem enviada!\n");
exit(EXIT_SUCCESS);
}