cliet_setup

This commit is contained in:
Lorenzo Bianchi 2023-05-29 13:06:22 +02:00
parent 06744b5b02
commit eb4c32c110
9 changed files with 36 additions and 39 deletions

View File

@ -11,4 +11,6 @@
- abbandono player
- pulire f4client mettendo var con nomi normali
- pulire f4client mettendo var con nomi normali
- ho scoperto solo adesso che c'é set_rows ecc, forse non lho sempre usato facendo invece _ROWS = ...

View File

@ -1,6 +1,9 @@
#ifndef CLIENT_H
#define CLIENT_H
msg_t msg;
void setupClient(int argc, char *argv[]);
#endif

View File

@ -9,7 +9,7 @@ void setupServerShm();
int getShmid();
tile_t * shmServerAt();
tile_t * shmClientAt(int shmid);
tile_t * shmClientAt();
void shmDt(void *shm_ptr);
void shmServerRm(int shmid);

View File

@ -8,6 +8,6 @@ extern pid_t _PIDS[2];
void sigHandlerServer(int sig);
void setupServerSignalHandler();
void setupServerSignalHandler();
void setupClientSignalHandler();
#endif

View File

@ -25,29 +25,14 @@ int main(int argc, char *argv[]){
printf("Il mio pid per killarmi: %d\n", getpid()); //TMP
setupClient(argc, argv);
//
// MSGQ
// msg
input_server_t input;
msg_t msg;
// msgrcv
printf(PCLIENT "Waiting for message...\n");
rcvMsg(&msg);
input = msg.server_in;
//
setupClient(argc, argv); //FIXME: msg é tmp
// SHM
printf(PCLIENT "Setting up shm\n");
int shmBoardid = getShmid();
_BOARD = shmClientAt(shmBoardid);
int _SHMID = getShmid();
_BOARD = shmClientAt();
//
// SEM
@ -59,7 +44,6 @@ int main(int argc, char *argv[]){
}
//
// aspetto che il server mi dia il permesso di collegarmi e segnalo collegamento al server
semOp(semid, msg.player_id, -1);
@ -82,9 +66,6 @@ int main(int argc, char *argv[]){
// PARTITA
move_t move = {.mtype = 2};
setRows(input.rows); //FIXME: da mettere in un setup
setCollums(input.collums);
setTokens(msg.server_in.player1Token, msg.server_in.player2Token);
while (1) {
// aspetto il mio turno

View File

@ -22,10 +22,12 @@ void setupClient(int argc, char *argv[]) {
// CHECK INPUT
checkClientinput(argc, argv);
// SIGNAL
setupClientSignalHandler();
// MSGQ
setupClientMsgq();
}
void checkClientinput(int argc, char *argv[]){

View File

@ -6,6 +6,8 @@
#include <custom_msgq.h>
#include <errExit.h>
#include <server.h> //FIXME: da togliere poi
#include <client.h>
#include <forza4.h>
int _MSGQID;
@ -13,6 +15,7 @@ void msgRcv(void *msgp, size_t size, long mtype);
void msgSnd(void *msgp, size_t size);
void openMsgq();
void sndId();
void rcvId();
void setupServerMsgq() {
openMsgq();
@ -20,19 +23,15 @@ void setupServerMsgq() {
}
void setupClientMsgq() {
printf(PCLIENT "Setting up msgq\n");
key_t msgKey = ftok(KEYFILE, 'M');
_MSGQID = msgget(msgKey, IPC_CREAT | S_IRUSR | S_IWUSR);
if (_MSGQID == -1) {
errExit("msgget", "F4Client");
}
openMsgq();
rcvId();
}
void openMsgq() {
key_t msgKey = ftok(KEYFILE, 'M');
_MSGQID = msgget(msgKey, IPC_CREAT | S_IRUSR | S_IWUSR);
if (_MSGQID == -1){
errExit("msgget", "F4Server");
errExitMsg("msgget");
}
}
@ -48,6 +47,15 @@ void sndId() {
sndMsg(&msg);
}
void rcvId() {
printf(PCLIENT "Waiting for message...\n");
rcvMsg(&msg);
setRows(msg.server_in.rows);
setCollums(msg.server_in.collums);
setTokens(msg.server_in.player1Token, msg.server_in.player2Token);
}
void msgRcv(void *msgp, size_t size, long mtype) {
int res;

View File

@ -26,11 +26,10 @@ int getShmid() {
errExit("shmget", "getShmid");
}
return shmid;
}
tile_t *shmServerAt() {
tile_t *shmServerAt() { //FIXME: si possono fare void
tile_t *board = (tile_t *)shmat(_SHMID, NULL, 0);
if (board == SHMERR) {
errExit("shmat", "shmServerAt");
@ -39,8 +38,10 @@ tile_t *shmServerAt() {
return board;
}
tile_t * shmClientAt(int shmid) {
tile_t *board = (tile_t *)shmat(shmid, NULL, SHM_RDONLY);
tile_t * shmClientAt() {
tile_t *board = (tile_t *)shmat(_SHMID, NULL, SHM_RDONLY);
perror("perche");
if (board == SHMERR) {
errExit("shmat", "shmClientAt");
}

View File

@ -25,7 +25,7 @@ void sigIntHandler2(int sig) {
void sigHandlerServer(int sig) {
if (sig == SIGINT) {
printf("\n" PSERVER "Press again Ctrl^C to exit (whitin %d sec)\n", TIME_TO_RESET);
printf("\n" PSERVER "Press again Ctrl^C to exit (within %d sec)\n", TIME_TO_RESET);
signal(SIGINT, sigIntHandler2);
alarm(TIME_TO_RESET);
}