changeset 32008:221819bef85e

Use sockfd value to detect if we initialized already instead of a separate variable.
author reimar
date Wed, 08 Sep 2010 18:44:22 +0000
parents b8514776c9ec
children 31db5ee9280d
files udp_sync.c
diffstat 1 files changed, 4 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/udp_sync.c	Wed Sep 08 18:42:27 2010 +0000
+++ b/udp_sync.c	Wed Sep 08 18:44:22 2010 +0000
@@ -85,14 +85,11 @@
     int chars_received = -1;
     int n;
 
-    static int done_init_yet = 0;
-    static int sockfd;
-    if (!done_init_yet) {
+    static int sockfd = -1;
+    if (sockfd == -1) {
         struct timeval tv = { .tv_sec = 30 };
         struct sockaddr_in servaddr = { 0 };
 
-        done_init_yet = 1;
-
         sockfd = socket(AF_INET, SOCK_DGRAM, 0);
         if (sockfd == -1)
             return -1;
@@ -136,16 +133,13 @@
 
 void send_udp(const char *send_to_ip, int port, char *mesg)
 {
-    static int done_init_yet = 0;
-    static int sockfd;
+    static int sockfd = -1;
     static struct sockaddr_in socketinfo;
 
-    if (!done_init_yet) {
+    if (sockfd == -1) {
         static const int one = 1;
         int ip_valid = 0;
 
-        done_init_yet = 1;
-
         sockfd = socket(AF_INET, SOCK_DGRAM, 0);
         if (sockfd == -1)
             exit_player(EXIT_ERROR);