]> git.proxmox.com Git - mirror_frr.git/commitdiff
2005-05-03 Paul Jakma <paul@dishone.st>
authorpaul <paul>
Tue, 3 May 2005 09:07:56 +0000 (09:07 +0000)
committerpaul <paul>
Tue, 3 May 2005 09:07:56 +0000 (09:07 +0000)
* stream.h: Add comment about the special zero-ing ability of
  stream_put.
  (stream_recvmsg, stream_write) should return ssize_t and size_t
  respectively. Should both be extern linkage.
  (stream_recvfrom) Stream aware wrapper around recvfrom, in style
  of stream_read_try.
* stream.c: (stream_recvfrom) new function, wrapper around recvfrom.
  (stream_recvmsg, stream_write) ssize_t and size_t return values

lib/ChangeLog
lib/stream.c
lib/stream.h

index 8da9870e194b5a2fc3bc67c499849e7309cb86e6..fb5b1309cf81c9d0e6f3aaea4b7b56f27b34be3b 100644 (file)
@@ -1,3 +1,14 @@
+2005-05-03 Paul Jakma <paul@dishone.st>
+
+       * stream.h: Add comment about the special zero-ing ability of
+         stream_put.
+         (stream_recvmsg, stream_write) should return ssize_t and size_t
+         respectively. Should both be extern linkage.
+         (stream_recvfrom) Stream aware wrapper around recvfrom, in style
+         of stream_read_try.
+       * stream.c: (stream_recvfrom) new function, wrapper around recvfrom.
+         (stream_recvmsg, stream_write) ssize_t and size_t return values
+         
 2005-04-27 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
 
        Add wall-clock timing statistics to 'show thread cpu' output.
index b71b8ee9259c1017eca66df129bdf112a2f566ac..d8c1088299cf9a790a70b69a9eb24041223785e0 100644 (file)
@@ -368,6 +368,8 @@ stream_get_ipv4 (struct stream *s)
  *
  * XXX: This uses CHECK_SIZE and hence has funny semantics -> Size will wrap
  * around. This should be fixed once the stream updates are working.
+ *
+ * stream_write() is saner
  */
 void
 stream_put (struct stream *s, void *src, size_t size)
@@ -630,12 +632,44 @@ stream_read_try(struct stream *s, int fd, size_t size)
   return -1;
 }
 
+/* Read up to size bytes into the stream from the fd, using recvmsgfrom
+ * whose arguments match the remaining arguments to this function
+ */
+ssize_t 
+stream_recvfrom (struct stream *s, int fd, size_t size, int flags,
+                 struct sockaddr *from, socklen_t *fromlen)                     
+{
+  ssize_t nbytes;
+
+  STREAM_VERIFY_SANE(s);
+  
+  if (STREAM_WRITEABLE(s) < size)
+    {
+      STREAM_BOUND_WARN (s, "put");
+      /* Fatal (not transient) error, since retrying will not help
+         (stream is too small to contain the desired data). */
+      return -1;
+    }
+
+  if ((nbytes = recvfrom (fd, s->data + s->endp, size, 
+                          flags, from, fromlen)) >= 0)
+    {
+      s->endp += nbytes;
+      return nbytes;
+    }
+  /* Error: was it transient (return -2) or fatal (return -1)? */
+  if (ERRNO_IO_RETRY(errno))
+    return -2;
+  zlog_warn("%s: read failed on fd %d: %s", __func__, fd, safe_strerror(errno));
+  return -1;
+}
+
 /* Read up to smaller of size or SIZE_REMAIN() bytes to the stream, starting
  * from endp.
  * First iovec will be used to receive the data.
  * Stream need not be empty.
  */
-int
+ssize_t
 stream_recvmsg (struct stream *s, int fd, struct msghdr *msgh, int flags, 
                 size_t size)
 {
@@ -666,7 +700,7 @@ stream_recvmsg (struct stream *s, int fd, struct msghdr *msgh, int flags,
 }
   
 /* Write data to buffer. */
-int
+size_t
 stream_write (struct stream *s, u_char *ptr, size_t size)
 {
 
index 1f6c3772bf426117cd1b3827deb506b287514e8e..7565fac84082d0a5c859432a17dcc2a92e42f48d 100644 (file)
  * use stream_forward_endp() to effectively create arbitrary zero-fill
  * padding. However, note that stream_reset() does *not* zero-out the
  * stream. This property should **not** be relied upon.
- * 
- * A Good stream user should ensure it writes all bytes. (the zero-fill
- * guarantee may be removed in future, however, the zero-filling may
- * possibly be moved to stream_forward_endp() instead, maybe..)
+ *
+ * Best practice is to use stream_put (<stream *>, NULL, <size>) to zero out
+ * any part of a stream which isn't otherwise written to.
  */
 
 /* Stream buffer. */
@@ -143,7 +142,7 @@ void stream_set_getp (struct stream *, size_t);
 void stream_forward_getp (struct stream *, size_t);
 void stream_forward_endp (struct stream *, size_t);
 
-void stream_put (struct stream *, void *, size_t);
+void stream_put (struct stream *, void *, size_t); /* NULL source zeroes */
 int stream_putc (struct stream *, u_char);
 int stream_putc_at (struct stream *, size_t, u_char);
 int stream_putw (struct stream *, u_int16_t);
@@ -184,9 +183,11 @@ int stream_read_unblock (struct stream *, int, size_t);
  */
 extern ssize_t stream_read_try(struct stream *s, int fd, size_t size);
 
-int stream_recvmsg (struct stream *s, int fd, struct msghdr *,
+extern ssize_t stream_recvmsg (struct stream *s, int fd, struct msghdr *,
                     int flags, size_t size);
-int stream_write (struct stream *, u_char *, size_t);
+extern ssize_t stream_recvfrom (struct stream *s, int fd, size_t len, int flags,
+                     struct sockaddr *from, socklen_t *fromlen);
+size_t stream_write (struct stream *, u_char *, size_t);
 
 void stream_reset (struct stream *); /* reset the stream. See Note above */
 int stream_flush (struct stream *, int);