cliet_setup
This commit is contained in:
parent
eb4c32c110
commit
87bc2e65b3
|
@ -6,8 +6,9 @@
|
|||
extern int _SHMID;
|
||||
|
||||
void setupServerShm();
|
||||
void setupClientShm();
|
||||
|
||||
int getShmid();
|
||||
int getShmid(); //FIXME: dovrebbero andare nel .c perche non vanno usate da altri file
|
||||
tile_t * shmServerAt();
|
||||
tile_t * shmClientAt();
|
||||
void shmDt(void *shm_ptr);
|
||||
|
|
|
@ -28,27 +28,22 @@ int main(int argc, char *argv[]){
|
|||
msg_t msg;
|
||||
setupClient(argc, argv); //FIXME: msg é tmp
|
||||
|
||||
|
||||
// SHM
|
||||
printf(PCLIENT "Setting up shm\n");
|
||||
int _SHMID = getShmid();
|
||||
_BOARD = shmClientAt();
|
||||
//
|
||||
printf("fin qua funzia (spero)\n");
|
||||
scanf("%d");
|
||||
|
||||
// SEM
|
||||
printf(PCLIENT "Setting up sem\n");
|
||||
key_t semKey = ftok(KEYFILE, 'S');
|
||||
int semid;
|
||||
if ((semid = semget(semKey, 3, S_IRUSR | S_IWUSR | IPC_CREAT)) == -1) {
|
||||
if ((_SEMID = semget(semKey, 3, S_IRUSR | S_IWUSR | IPC_CREAT)) == -1) {
|
||||
errExit("getsem", "F4Client");
|
||||
}
|
||||
//
|
||||
|
||||
|
||||
// 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);
|
||||
printf(PCLIENT "Connecting to server...\n");
|
||||
semOp(semid, 2, 1);
|
||||
semOp(_SEMID, 2, 1);
|
||||
|
||||
|
||||
// mando i miei dati al server
|
||||
|
@ -58,7 +53,7 @@ int main(int argc, char *argv[]){
|
|||
|
||||
printf(PCLIENT "Searching for oponent...\n");
|
||||
|
||||
semOp(semid, msg.player_id, -1);
|
||||
semOp(_SEMID, msg.player_id, -1);
|
||||
|
||||
printf(PCLIENT "Opponent found\n");
|
||||
|
||||
|
@ -69,7 +64,7 @@ int main(int argc, char *argv[]){
|
|||
|
||||
while (1) {
|
||||
// aspetto il mio turno
|
||||
semOp(semid, msg.player_id, -1); // mettere id eccetera in var
|
||||
semOp(_SEMID, msg.player_id, -1); // mettere id eccetera in var
|
||||
printBoard(_BOARD);
|
||||
|
||||
// input e controllo
|
||||
|
@ -84,7 +79,7 @@ int main(int argc, char *argv[]){
|
|||
// mando mossa al server
|
||||
sndMove(&move);
|
||||
|
||||
semOp(semid, msg.player_id, -1);
|
||||
semOp(_SEMID, msg.player_id, -1);
|
||||
printBoard(_BOARD);
|
||||
|
||||
printf(PCLIENT "Waiting for oponent\n"); //FIXME: solo se la partita non è finita
|
||||
|
|
|
@ -25,9 +25,11 @@ void setupClient(int argc, char *argv[]) {
|
|||
// SIGNAL
|
||||
setupClientSignalHandler();
|
||||
|
||||
|
||||
// MSGQ
|
||||
setupClientMsgq();
|
||||
|
||||
// SHM
|
||||
setupClientShm();
|
||||
}
|
||||
|
||||
void checkClientinput(int argc, char *argv[]){
|
||||
|
|
|
@ -20,6 +20,12 @@ void setupServerShm() {
|
|||
}
|
||||
}
|
||||
|
||||
void setupClientShm() {
|
||||
printf(PCLIENT "Setting up shm\n");
|
||||
_SHMID = getShmid();
|
||||
_BOARD = shmClientAt();
|
||||
}
|
||||
|
||||
int getShmid() {
|
||||
int shmid = shmget(ftok(KEYFILE, 'h'), _ROWS * _COLLUMS * sizeof(tile_t), IPC_CREAT | S_IRUSR | S_IWUSR);
|
||||
if (shmid == -1) {
|
||||
|
@ -40,8 +46,6 @@ tile_t *shmServerAt() { //FIXME: si possono fare void
|
|||
|
||||
tile_t * shmClientAt() {
|
||||
tile_t *board = (tile_t *)shmat(_SHMID, NULL, SHM_RDONLY);
|
||||
perror("perche");
|
||||
|
||||
if (board == SHMERR) {
|
||||
errExit("shmat", "shmClientAt");
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ void setupServer(int argc, char *argv[]){
|
|||
_COLLUMS = _INPUT_S.collums;
|
||||
|
||||
// MSGQ
|
||||
printf(PSERVER "Setting up msgq\n");
|
||||
printf(PSERVER "Setting up msgq\n"); // FIXME: mettere printf nelle funzioni
|
||||
setupServerMsgq();
|
||||
|
||||
// SIGNAL
|
||||
|
|
Loading…
Reference in New Issue