/*******************************************************************************/ /* mser.cpp -- The server process */ #include #include "local6.h" void process_msg(char *, int); void removeQ(); int mid; // Must be global for signal handling int main(int argc, char *argv[]) { int n; MESSAGE msg; int ser_pid = getpid(); if(signal(SIGINT, removeQ) == SIG_ERR) perror("signal"); /* Create and gain access to message queue*/ mid = msgget(getuid(), IPC_CREAT | 0777); while (1) { if ((n=msgrcv(mid, &msg, sizeof(msg), SERVER, MSG_NOERROR)) == -1) { perror("Server: msgrcv"); exit(2); } else { /* send back to client */ process_msg(msg.buffer, strlen(msg.buffer)); msg.msg_type=msg.sender; if (msgsnd(mid, &msg, sizeof(msg), MSG_NOERROR ) == -1) { perror("Server: msgsnd"); exit(3); } } } exit(0); } /* Conver lower case alphabetics to upper case */ void process_msg(char *buf, int len) { int idx; for(idx =0; idx < len; ++idx) if(isalpha(*(buf + idx))) *(buf+idx) = toupper(*(buf+idx)); else buf[idx]+=1; printf("Processed to %s\n",buf); } void removeQ() {msgctl(mid,IPC_RMID, (struct msqid_ds *) 0); }