Esempio n. 1
0
void parent(const char *mqname)
{
    mqd_t mqdes = mq_open(mqname, O_RDWR | O_CREAT, 0666, 0);
    if (mqdes == -1) {
        perror("mq_open() failed");
        exit(1);
    }

    struct mq_attr attr;
    mq_getattr(mqdes, &attr);

    printf("mq_flags: %ld, mq_maxmsg: %ld, mq_msgsize: %ld, mq_curmsgs: %ld\n",
           attr.mq_flags, attr.mq_maxmsg, attr.mq_msgsize, attr.mq_curmsgs);
    fflush(stdout);

    int i = 1;
    while (1) {
        printf("Server: %d\n", i);
        fflush(stdout);
        msg_snd(mqdes, i);
        sleep(1);
        i++;
    }
    exit(0);
}
Esempio n. 2
0
Boolean aceptar_cancelar(){
 int  i = 0, lasti = 0, key, fila = wherey(), x = wherex();
 char *buttons[] = {" Aceptar ", " Cancelar "};
 gotoxy(x + 1, fila);
 cputs(" Aceptar  Cancelar ");
 gotoxy(x + calculate_xpos(buttons, i), fila);
 marcar_texto(buttons[i], strlen(buttons[i]));
 msg_snd();
 do{
  key = bioskey(0);
  if((key & SC_IZQ) == SC_IZQ){
   i--;
   if((i>=0)&&(i<=1))JVGtecla();
  }
  if((key & SC_DER) == SC_DER){
   i++;
   if((i>=0)&&(i<=1))JVGtecla();
  }
  if(i >= 2)  i = 1;
  if(i < 0) i = 0;
  gotoxy(x + calculate_xpos(buttons, lasti), fila);
  desmarcar_texto(buttons[lasti], strlen(buttons[lasti]));
  gotoxy(x + calculate_xpos(buttons, i), fila);
  marcar_texto(buttons[i], strlen(buttons[i]));
  lasti = i;
 }while(((key & SC_ENTER)!= SC_ENTER) && ((key & SC_ABAJO) != SC_ABAJO));
 gotoxy(x + calculate_xpos(buttons, i), fila);
 desmarcar_texto(buttons[i], strlen(buttons[i]));
 _setcursortype(_NORMALCURSOR);
 if(i == 0) return Verdadero;
 return Falso;
}
Esempio n. 3
0
void
child(int msqid)
{
  int i = 1;

  while (1) {
    msg_rcv(msqid, i);
    printf("Client: %d\n", i);
    fflush(stdout);
    msg_snd(msqid, i + 1);
    i += 2;
  }
  exit(0);
}
Esempio n. 4
0
void
parent(int msqid)
{
  int i = 1;

  for (i = 1; i < 32000; i += 2) {
    printf("Server: %d\n", i);
    fflush(stdout);
    msg_snd(msqid, i);
    msg_rcv(msqid, i + 1);
    sleep(1);
  }
  exit(0);
}
char* parser(char* command, char** ppl_cnt){
    char uname[USER_NAME_MAX_LENGTH];   
    char msg[MAX_MSG_LENGTH]; 
    char rname[ROOM_NAME_MAX_LENGTH];
    
    int i;
    
    for(i = 0; i < USER_NAME_MAX_LENGTH; ++i){
        uname[i] = '\0';
    }
    for(i = 0; i < MAX_MSG_LENGTH; ++i){
        msg[i] = '\0';
    }
    
    if(strncmp(command, "msg ", 4) == 0){       //wysylanie wiadomosci
        for(i = 4; command[i]!=' ' && i < USER_NAME_MAX_LENGTH + 3; ++i){
            uname[i-4] = command[i];
        }
        uname[USER_NAME_MAX_LENGTH - 1] = '\0';
             
        if(command[i] != ' '){
            while(command[i]!=' '){
                ++i;
            }
        }
        int j;

        for(j=0; j < 255 && command[i+j+1]!='\0'; ++j){
            msg[j] = command[i+j+1];
        }
        msg[i+j] = '\0';
        
        return msg_snd(uname, msg, ppl_cnt);
    }else if(strncmp(command, "logout", 6) == 0){       //wylogowanie z systemu
        logout();    
        return "logged out";
    }else if(strncmp(command, "channel ",8) == 0){      //wejscie do kanalu
        for(i = 8; command[i]!=' ' && i < ROOM_NAME_MAX_LENGTH + 7; ++i){
            rname[i-8] = command[i];
        }
        rname[ROOM_NAME_MAX_LENGTH - 1] = '\0';
        
        return enter_channel(rname);
    }
    
    if(strcmp(command, "") == 0){
        return NULL;
    }
return "Wrong command";
}