Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6. #include <unistd.h>
  7.  
  8. int main(){
  9.  
  10. int fpipe1=0,fpipe2=0,connectMessageSize=7;
  11. unsigned char sizeFirst=0;
  12. char *request=NULL;
  13.  
  14. mkfifo("RESP_PIPE_11548",0600);
  15.  
  16. fpipe1=open("RESP_PIPE_11548",O_RDWR);
  17. if(fpipe1==-1){
  18. perror("ERROR OPENING FILE!");
  19. exit(1);
  20. }
  21.  
  22. fpipe2=open("REQ_PIPE_11548",O_RDWR);
  23. if(fpipe2==-1){
  24. perror("ERROR OPENING FILE!");
  25. exit(1);
  26. }
  27.  
  28. if(write(fpipe1,"CONNECT",connectMessageSize)<0){
  29. perror("ERROR\ncannot create the response pipe | cannot open the request pipe");
  30. exit(1);
  31. }
  32.  
  33. printf("SUCCESS\n");
  34.  
  35. //AICI PUSCA
  36. printf("PUSCA\n");
  37. if(read(fpipe2,&sizeFirst,sizeof(unsigned char))<0){
  38. perror("ERROR\ncannot read from file");
  39. exit(1);
  40. }
  41. printf("NU A PUSCAT\n");
  42. request=(char*)malloc(sizeFirst*sizeof(char));
  43.  
  44. int readingSize=sizeFirst*sizeof(char);
  45.  
  46. if(read(fpipe2,&request,readingSize)<0){
  47. perror("ERROR\ncannot read request from file!");
  48. exit(1);
  49. }
  50. printf("verif: %s",request);
  51.  
  52. free(request);
  53. close(fpipe1);
  54. close(fpipe2);
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement