Advertisement
d1cor

mq1_b.c

Sep 27th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. /*******************************************
  2. * Author     : Diego Cordoba / @d1cor      *
  3. * Contact    : um.edu.ar / juncotic.com    *
  4. *******************************************/
  5.  
  6. #include<stdio.h>
  7. #include<stdlib.h>
  8. #include<sys/types.h>
  9. #include<sys/stat.h>
  10. #include<unistd.h>
  11. #include<string.h>
  12. #include<fcntl.h>
  13. #include<errno.h>
  14. #include<sys/ipc.h>
  15. #include<sys/msg.h>
  16. #include<mqueue.h>
  17. #define MSG_SIZE 128
  18.  
  19. #define SERVER_QUEUE_NAME   "/test"
  20. #define QUEUE_PERMISSIONS 0660
  21. #define MAX_MESSAGES 10
  22. #define MAX_MSG_SIZE 256
  23. #define MSG_BUFFER_SIZE MAX_MSG_SIZE + 10
  24.  
  25.  
  26.  
  27. int main(int argc, char** argv) {
  28.  
  29.     char *error;
  30.  
  31.     mqd_t msg_id;
  32.  
  33.     struct mq_attr attr;
  34.  
  35.     attr.mq_flags = 0;
  36.     attr.mq_maxmsg = MAX_MESSAGES;
  37.     attr.mq_msgsize = MAX_MSG_SIZE;
  38.     attr.mq_curmsgs = 0;
  39.  
  40.     if ((msg_id = mq_open (SERVER_QUEUE_NAME, O_WRONLY , QUEUE_PERMISSIONS, &attr)) == -1) {
  41.         perror ("Server: mq_open (client)");
  42.         exit (1);
  43.     }
  44.  
  45.     char buffer [MSG_BUFFER_SIZE];
  46.  
  47.     if (mq_send (msg_id, *(argv+1), strlen(*(argv+1)), 0) == -1) {
  48.         perror ("Client: Not able to send message to server");
  49.     }
  50.  
  51.  
  52.  
  53.     return 0;
  54.  
  55. err:
  56.     fprintf(stderr,"ERROR %s (%d) - %s\n",error,errno,strerror(errno));
  57.     exit(errno);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement