removed nonblocking sockets for causing problems and not being necessary

Thu, 17 Apr 2014 11:55:36 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 17 Apr 2014 11:55:36 +0200
changeset 45
e14a1d9aa91d
parent 44
1891d88cbd10
child 46
4dcfb4c58b6d

removed nonblocking sockets for causing problems and not being necessary

src/game.c file | annotate | diff | comparison | revisions
src/network.c file | annotate | diff | comparison | revisions
src/network.h file | annotate | diff | comparison | revisions
     1.1 --- a/src/game.c	Thu Apr 17 11:41:02 2014 +0200
     1.2 +++ b/src/game.c	Thu Apr 17 11:55:36 2014 +0200
     1.3 @@ -327,12 +327,6 @@
     1.4  
     1.5  static int recvmove(GameState *gamestate, GameInfo *gameinfo, int opponent) {
     1.6      
     1.7 -    if (net_setnonblocking(opponent, 1)) {
     1.8 -        printw("Cannot setup nonblocking IO on network socket");
     1.9 -        cbreak(); getch();
    1.10 -        exit(EXIT_FAILURE);
    1.11 -    }
    1.12 -    
    1.13      struct timeval timeout;
    1.14      while (1) {
    1.15          timecontrol(gamestate, gameinfo);
    1.16 @@ -402,6 +396,9 @@
    1.17                  } else {
    1.18                      net_send_code(opponent, NETCODE_DECLINE);
    1.19                  }
    1.20 +                break;
    1.21 +            default:
    1.22 +                printw("\nInvalid network request.");
    1.23              }
    1.24          }
    1.25      }
     2.1 --- a/src/network.c	Thu Apr 17 11:41:02 2014 +0200
     2.2 +++ b/src/network.c	Thu Apr 17 11:55:36 2014 +0200
     2.3 @@ -29,7 +29,6 @@
     2.4  
     2.5  #include <stdlib.h>
     2.6  #include <string.h>
     2.7 -#include <fcntl.h>
     2.8  #include "network.h"
     2.9  
    2.10  #define new_socket() socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    2.11 @@ -132,23 +131,5 @@
    2.12  }
    2.13  
    2.14  void net_recieve_data(int socket, void *data, size_t len) {
    2.15 -    recv(socket, data, len, 0);
    2.16 +    recv(socket, data, len, MSG_WAITALL);
    2.17  }
    2.18 -
    2.19 -int net_setnonblocking(int socket, _Bool nonblocking) {
    2.20 -    int opts = fcntl(socket, F_GETFL);
    2.21 -	if (opts < 0) {
    2.22 -		return 1;
    2.23 -	}
    2.24 -    
    2.25 -    if (nonblocking) {
    2.26 -        opts |= O_NONBLOCK;
    2.27 -    } else {
    2.28 -        opts &= ~O_NONBLOCK;
    2.29 -    }
    2.30 -	if (fcntl(socket, F_SETFL, opts) < 0) {
    2.31 -		return 1;
    2.32 -	}
    2.33 -    
    2.34 -    return 0;
    2.35 -}
     3.1 --- a/src/network.h	Thu Apr 17 11:41:02 2014 +0200
     3.2 +++ b/src/network.h	Thu Apr 17 11:55:36 2014 +0200
     3.3 @@ -74,8 +74,6 @@
     3.4  uint8_t net_recieve_code(int socket);
     3.5  void net_recieve_data(int socket, void *data, size_t len);
     3.6  
     3.7 -int net_setnonblocking(int socket, _Bool nonblocking);
     3.8 -
     3.9  #ifdef	__cplusplus
    3.10  }
    3.11  #endif

mercurial