Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. keep_doing = 1;
  2. while (keep_doing == 1) {
  3. // Start Timer
  4. sa.sa_handler = sig_handler;
  5. sigemptyset(&sa.sa_mask);
  6. sa.sa_flags = 0;
  7. assert(sigaction(SIGALRM, &sa, NULL) != -1);
  8. assert(sigaction(SIGCHLD, &sa, NULL) != -1);
  9. printf("Timer starts\n");
  10. assert((chld_process = fork()) != -1);
  11. time_t start = 0;
  12.  
  13. if (chld_process == 0) {
  14. // Receiving packet from server if possible
  15. recvPacket();
  16. printf("Received Packet\n");
  17. exit(EXIT_SUCCESS);
  18. }
  19. timeTaken(start); // Print time it took for packet to arrive
  20. if (result == OK) { // 5. Process which type of packet it is
  21. printf("Received ACK from Server, now processing Packet %hd\n", ntohs(pkt.pkt_type));
  22. if (ntohs(pkt.pkt_type) == 3) { // Confirm(3)
  23. if (next_line < numOfRows) { // Send Req(2) to server
  24. printf("Packet 3: next_line %d\n", next_line);
  25. updateSeq();
  26. sendPacket(2, db[next_line].input_line);
  27. next_line++;
  28. } else {
  29. keep_doing = 0;
  30. }
  31. } else if (ntohs(pkt.pkt_type) == 4) { // Error(4): Incorrect Name/Pass, resend Registration/Login(1) packet
  32. printf("Packet 4: Incorrect name or incorrect seq_no\n");
  33. retry();
  34. } else if (ntohs(pkt.pkt_type) ==1){
  35. printf("Packet 1: This shouldn't happen\n\n");
  36. } else {
  37. printf("error: else\n\n");
  38. printf("Current: Packet Type: %hd Sequence Number: %hd Port Number: %ld Client Name: %s Data: %s\n\n", ntohs(pkt.pkt_type), ntohs(pkt.sequence_no), ntohl(pkt.port_no), pkt.client_name, pkt.data);
  39. exit(0);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement