Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- keep_doing = 1;
- while (keep_doing == 1) {
- // Start Timer
- sa.sa_handler = sig_handler;
- sigemptyset(&sa.sa_mask);
- sa.sa_flags = 0;
- assert(sigaction(SIGALRM, &sa, NULL) != -1);
- assert(sigaction(SIGCHLD, &sa, NULL) != -1);
- printf("Timer starts\n");
- assert((chld_process = fork()) != -1);
- time_t start = 0;
- if (chld_process == 0) {
- // Receiving packet from server if possible
- recvPacket();
- printf("Received Packet\n");
- exit(EXIT_SUCCESS);
- }
- timeTaken(start); // Print time it took for packet to arrive
- if (result == OK) { // 5. Process which type of packet it is
- printf("Received ACK from Server, now processing Packet %hd\n", ntohs(pkt.pkt_type));
- if (ntohs(pkt.pkt_type) == 3) { // Confirm(3)
- if (next_line < numOfRows) { // Send Req(2) to server
- printf("Packet 3: next_line %d\n", next_line);
- updateSeq();
- sendPacket(2, db[next_line].input_line);
- next_line++;
- } else {
- keep_doing = 0;
- }
- } else if (ntohs(pkt.pkt_type) == 4) { // Error(4): Incorrect Name/Pass, resend Registration/Login(1) packet
- printf("Packet 4: Incorrect name or incorrect seq_no\n");
- retry();
- } else if (ntohs(pkt.pkt_type) ==1){
- printf("Packet 1: This shouldn't happen\n\n");
- } else {
- printf("error: else\n\n");
- 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);
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement