cliet_setup
This commit is contained in:
parent
06744b5b02
commit
eb4c32c110
4
TODO.txt
4
TODO.txt
|
@ -11,4 +11,6 @@
|
||||||
|
|
||||||
- abbandono player
|
- 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 = ...
|
|
@ -1,6 +1,9 @@
|
||||||
#ifndef CLIENT_H
|
#ifndef CLIENT_H
|
||||||
#define CLIENT_H
|
#define CLIENT_H
|
||||||
|
|
||||||
|
|
||||||
|
msg_t msg;
|
||||||
|
|
||||||
void setupClient(int argc, char *argv[]);
|
void setupClient(int argc, char *argv[]);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -9,7 +9,7 @@ void setupServerShm();
|
||||||
|
|
||||||
int getShmid();
|
int getShmid();
|
||||||
tile_t * shmServerAt();
|
tile_t * shmServerAt();
|
||||||
tile_t * shmClientAt(int shmid);
|
tile_t * shmClientAt();
|
||||||
void shmDt(void *shm_ptr);
|
void shmDt(void *shm_ptr);
|
||||||
void shmServerRm(int shmid);
|
void shmServerRm(int shmid);
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,6 @@ extern pid_t _PIDS[2];
|
||||||
void sigHandlerServer(int sig);
|
void sigHandlerServer(int sig);
|
||||||
|
|
||||||
void setupServerSignalHandler();
|
void setupServerSignalHandler();
|
||||||
void setupServerSignalHandler();
|
void setupClientSignalHandler();
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -25,29 +25,14 @@ int main(int argc, char *argv[]){
|
||||||
|
|
||||||
printf("Il mio pid per killarmi: %d\n", getpid()); //TMP
|
printf("Il mio pid per killarmi: %d\n", getpid()); //TMP
|
||||||
|
|
||||||
setupClient(argc, argv);
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
// MSGQ
|
|
||||||
|
|
||||||
|
|
||||||
// msg
|
|
||||||
input_server_t input;
|
|
||||||
msg_t msg;
|
msg_t msg;
|
||||||
|
setupClient(argc, argv); //FIXME: msg é tmp
|
||||||
// msgrcv
|
|
||||||
printf(PCLIENT "Waiting for message...\n");
|
|
||||||
rcvMsg(&msg);
|
|
||||||
|
|
||||||
input = msg.server_in;
|
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
// SHM
|
// SHM
|
||||||
printf(PCLIENT "Setting up shm\n");
|
printf(PCLIENT "Setting up shm\n");
|
||||||
int shmBoardid = getShmid();
|
int _SHMID = getShmid();
|
||||||
_BOARD = shmClientAt(shmBoardid);
|
_BOARD = shmClientAt();
|
||||||
//
|
//
|
||||||
|
|
||||||
// SEM
|
// 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
|
// aspetto che il server mi dia il permesso di collegarmi e segnalo collegamento al server
|
||||||
semOp(semid, msg.player_id, -1);
|
semOp(semid, msg.player_id, -1);
|
||||||
|
@ -82,9 +66,6 @@ int main(int argc, char *argv[]){
|
||||||
|
|
||||||
// PARTITA
|
// PARTITA
|
||||||
move_t move = {.mtype = 2};
|
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) {
|
while (1) {
|
||||||
// aspetto il mio turno
|
// aspetto il mio turno
|
||||||
|
|
|
@ -22,10 +22,12 @@ void setupClient(int argc, char *argv[]) {
|
||||||
// CHECK INPUT
|
// CHECK INPUT
|
||||||
checkClientinput(argc, argv);
|
checkClientinput(argc, argv);
|
||||||
|
|
||||||
|
// SIGNAL
|
||||||
|
setupClientSignalHandler();
|
||||||
|
|
||||||
|
|
||||||
// MSGQ
|
// MSGQ
|
||||||
setupClientMsgq();
|
setupClientMsgq();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkClientinput(int argc, char *argv[]){
|
void checkClientinput(int argc, char *argv[]){
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#include <custom_msgq.h>
|
#include <custom_msgq.h>
|
||||||
#include <errExit.h>
|
#include <errExit.h>
|
||||||
#include <server.h> //FIXME: da togliere poi
|
#include <server.h> //FIXME: da togliere poi
|
||||||
|
#include <client.h>
|
||||||
|
#include <forza4.h>
|
||||||
|
|
||||||
int _MSGQID;
|
int _MSGQID;
|
||||||
|
|
||||||
|
@ -13,6 +15,7 @@ void msgRcv(void *msgp, size_t size, long mtype);
|
||||||
void msgSnd(void *msgp, size_t size);
|
void msgSnd(void *msgp, size_t size);
|
||||||
void openMsgq();
|
void openMsgq();
|
||||||
void sndId();
|
void sndId();
|
||||||
|
void rcvId();
|
||||||
|
|
||||||
void setupServerMsgq() {
|
void setupServerMsgq() {
|
||||||
openMsgq();
|
openMsgq();
|
||||||
|
@ -20,19 +23,15 @@ void setupServerMsgq() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupClientMsgq() {
|
void setupClientMsgq() {
|
||||||
printf(PCLIENT "Setting up msgq\n");
|
openMsgq();
|
||||||
key_t msgKey = ftok(KEYFILE, 'M');
|
rcvId();
|
||||||
_MSGQID = msgget(msgKey, IPC_CREAT | S_IRUSR | S_IWUSR);
|
|
||||||
if (_MSGQID == -1) {
|
|
||||||
errExit("msgget", "F4Client");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void openMsgq() {
|
void openMsgq() {
|
||||||
key_t msgKey = ftok(KEYFILE, 'M');
|
key_t msgKey = ftok(KEYFILE, 'M');
|
||||||
_MSGQID = msgget(msgKey, IPC_CREAT | S_IRUSR | S_IWUSR);
|
_MSGQID = msgget(msgKey, IPC_CREAT | S_IRUSR | S_IWUSR);
|
||||||
if (_MSGQID == -1){
|
if (_MSGQID == -1){
|
||||||
errExit("msgget", "F4Server");
|
errExitMsg("msgget");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +47,15 @@ void sndId() {
|
||||||
sndMsg(&msg);
|
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) {
|
void msgRcv(void *msgp, size_t size, long mtype) {
|
||||||
int res;
|
int res;
|
||||||
|
|
|
@ -26,11 +26,10 @@ int getShmid() {
|
||||||
errExit("shmget", "getShmid");
|
errExit("shmget", "getShmid");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return shmid;
|
return shmid;
|
||||||
}
|
}
|
||||||
|
|
||||||
tile_t *shmServerAt() {
|
tile_t *shmServerAt() { //FIXME: si possono fare void
|
||||||
tile_t *board = (tile_t *)shmat(_SHMID, NULL, 0);
|
tile_t *board = (tile_t *)shmat(_SHMID, NULL, 0);
|
||||||
if (board == SHMERR) {
|
if (board == SHMERR) {
|
||||||
errExit("shmat", "shmServerAt");
|
errExit("shmat", "shmServerAt");
|
||||||
|
@ -39,8 +38,10 @@ tile_t *shmServerAt() {
|
||||||
return board;
|
return board;
|
||||||
}
|
}
|
||||||
|
|
||||||
tile_t * shmClientAt(int shmid) {
|
tile_t * shmClientAt() {
|
||||||
tile_t *board = (tile_t *)shmat(shmid, NULL, SHM_RDONLY);
|
tile_t *board = (tile_t *)shmat(_SHMID, NULL, SHM_RDONLY);
|
||||||
|
perror("perche");
|
||||||
|
|
||||||
if (board == SHMERR) {
|
if (board == SHMERR) {
|
||||||
errExit("shmat", "shmClientAt");
|
errExit("shmat", "shmClientAt");
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ void sigIntHandler2(int sig) {
|
||||||
|
|
||||||
void sigHandlerServer(int sig) {
|
void sigHandlerServer(int sig) {
|
||||||
if (sig == SIGINT) {
|
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);
|
signal(SIGINT, sigIntHandler2);
|
||||||
alarm(TIME_TO_RESET);
|
alarm(TIME_TO_RESET);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue