changeset 32007:b8514776c9ec

Handle failures to create a socket.
author reimar
date Wed, 08 Sep 2010 18:42:27 +0000
parents 3133252ce3fa
children 221819bef85e
files udp_sync.c
diffstat 1 files changed, 5 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/udp_sync.c	Wed Sep 08 18:37:55 2010 +0000
+++ b/udp_sync.c	Wed Sep 08 18:42:27 2010 +0000
@@ -74,6 +74,7 @@
 
 // gets a datagram from the master with or without blocking.  updates
 // master_position if successful.  if the master has exited, returns 1.
+// returns -1 on error.
 // otherwise, returns 0.
 int get_udp(int blocking, float *master_position)
 {
@@ -93,6 +94,8 @@
         done_init_yet = 1;
 
         sockfd = socket(AF_INET, SOCK_DGRAM, 0);
+        if (sockfd == -1)
+            return -1;
 
         servaddr.sin_family      = AF_INET;
         servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
@@ -144,6 +147,8 @@
         done_init_yet = 1;
 
         sockfd = socket(AF_INET, SOCK_DGRAM, 0);
+        if (sockfd == -1)
+            exit_player(EXIT_ERROR);
 
         // Enable broadcast
         setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &one, sizeof(one));