]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Cleaned up sk_reallocate() and friends.
authorMartin Mares <mj@ucw.cz>
Sat, 5 Jun 2004 08:56:43 +0000 (08:56 +0000)
committerMartin Mares <mj@ucw.cz>
Sat, 5 Jun 2004 08:56:43 +0000 (08:56 +0000)
Also, removed the `if (s)' test, because I believe that as the whole
socket interface doesn't accent NULL pointers, sk_reallocate() shouldn't
be the only exception.

sysdep/unix/io.c

index b216e63b1b90761371051f91509018440cd9dbdf..4030b86beb5eafb5cc776fa3423a596d57172b4c 100644 (file)
@@ -422,14 +422,37 @@ sk_next(sock *s)
 }
 
 static void
-sk_free(resource *r)
+sk_alloc_bufs(sock *s)
 {
-  sock *s = (sock *) r;
+  if (!s->rbuf && s->rbsize)
+    s->rbuf = s->rbuf_alloc = xmalloc(s->rbsize);
+  s->rpos = s->rbuf;
+  if (!s->tbuf && s->tbsize)
+    s->tbuf = s->tbuf_alloc = xmalloc(s->tbsize);
+  s->tpos = s->ttx = s->tbuf;
+}
 
+static void
+sk_free_bufs(sock *s)
+{
   if (s->rbuf_alloc)
-    xfree(s->rbuf_alloc);
+    {
+      xfree(s->rbuf_alloc);
+      s->rbuf = s->rbuf_alloc = NULL;
+    }
   if (s->tbuf_alloc)
-    xfree(s->tbuf_alloc);
+    {
+      xfree(s->tbuf_alloc);
+      s->tbuf = s->tbuf_alloc = NULL;
+    }
+}
+
+static void
+sk_free(resource *r)
+{
+  sock *s = (sock *) r;
+
+  sk_free_bufs(s);
   if (s->fd >= 0)
     {
       close(s->fd);
@@ -440,6 +463,13 @@ sk_free(resource *r)
     }
 }
 
+void
+sk_reallocate(sock *s)
+{
+  sk_free_bufs(s);
+  sk_alloc_bufs(s);
+}
+
 static void
 sk_dump(resource *r)
 {
@@ -588,31 +618,6 @@ bad:
   return err;
 }
 
-static void
-sk_alloc_bufs(sock *s)
-{
-  if (!s->rbuf && s->rbsize)
-    s->rbuf = s->rbuf_alloc = xmalloc(s->rbsize);
-  s->rpos = s->rbuf;
-  if (!s->tbuf && s->tbsize)
-    s->tbuf = s->tbuf_alloc = xmalloc(s->tbsize);
-  s->tpos = s->ttx = s->tbuf;
-}
-
-void
-sk_reallocate(sock *s)
-{
-  if(!s) return;
-
-  if (s->rbuf_alloc)
-    xfree(s->rbuf_alloc);
-  s->rbuf = NULL;
-  if (s->tbuf_alloc)
-    xfree(s->tbuf_alloc);
-  s->tbuf = NULL;
-  sk_alloc_bufs(s);
-}
-
 static void
 sk_tcp_connected(sock *s)
 {