]> git.pond.sub.org Git - empserver/commitdiff
(wu,typed_wu): close() a sent telegram before waking up other threads.
authorMarc Olzheim <marcolz@stack.nl>
Sat, 26 Mar 2005 00:23:25 +0000 (00:23 +0000)
committerMarc Olzheim <marcolz@stack.nl>
Sat, 26 Mar 2005 00:23:25 +0000 (00:23 +0000)
Remove s_char and register on the way.

include/prototypes.h
src/lib/subs/wu.c

index 515458c37168413514ff688da8c267157984732b..78718aff0d74fd1b9a943ad5293351881593f2bb 100644 (file)
@@ -709,8 +709,8 @@ extern int trechk(register natid, register natid, int);
 /* in item.h */
 /* wu.c */
 extern void clear_telegram_is_new(natid);
-extern int typed_wu(natid, natid, s_char *, int);
-extern int wu(natid, natid, s_char *, ...) ATTRIBUTE((format (printf, 3, 4)));
+extern int typed_wu(natid, natid, char *, int);
+extern int wu(natid, natid, char *, ...) ATTRIBUTE((format (printf, 3, 4)));
 
 /*
  * src/lib/update/ *.c 
index 8fd675d7b27b7edaced4050bf1619498b10d81d2..da7af3dbbd5d61f0a6559aebc6a011f01822664b 100644 (file)
@@ -80,11 +80,11 @@ telegram_is_new(natid to, struct telstr *tel)
 
 /*VARARGS*/
 int
-wu(natid from, natid to, s_char *format, ...)
+wu(natid from, natid to, char *format, ...)
 {
     struct natstr *np;
     va_list ap;
-    s_char buf[4096];
+    char buf[4096];
 
     va_start(ap, format);
     (void)vsprintf(buf, format, ap);
@@ -99,9 +99,9 @@ wu(natid from, natid to, s_char *format, ...)
 }
 
 int
-typed_wu(natid from, natid to, s_char *message, int type)
+typed_wu(natid from, natid to, char *message, int type)
 {
-    register s_char *bp;
+    char *bp;
     int len;
     struct telstr tel;
     struct natstr *np;
@@ -109,8 +109,9 @@ typed_wu(natid from, natid to, s_char *message, int type)
     struct iovec iov[2];
 #endif
     int fd;
-    s_char box[1024];
+    char box[1024];
     int notify = 0;
+    int write_ok = 0;
     int new_tele = 0;
     struct player *other;
 
@@ -154,7 +155,12 @@ typed_wu(natid from, natid to, s_char *message, int type)
        (write(fd, message, len) != len)) {
 #endif
        logerror("telegram 'write' to #%d failed", to);
-    } else if (type == TEL_ANNOUNCE) {
+    } else
+       write_ok = 1;
+
+    if (close(fd) == -1) {
+       logerror("telegram 'write' to #%d failed to close.", to);
+    } else if (write_ok && type == TEL_ANNOUNCE) {
        for (to = 0; NULL != (np = getnatp(to)); to++) {
            if (!(np->nat_stat & STAT_NORM) &&
                !(np->nat_stat & STAT_SANCT))
@@ -167,7 +173,7 @@ typed_wu(natid from, natid to, s_char *message, int type)
            if (notify)
                player_wakeup_all(to);
        }
-    } else {
+    } else if (write_ok) {
        notify = (np->nat_tgms == 0);
        new_tele = telegram_is_new(to, &tel);
        np->nat_tgms += new_tele || notify;
@@ -185,6 +191,5 @@ typed_wu(natid from, natid to, s_char *message, int type)
            player_wakeup_all(to);
     }
 
-    close(fd);
     return 0;
 }