[PATCH] move client logging to log-buffer.[ch]

Alexey Mahotkin <[email protected]>
Newsgroups gmane.comp.version-control.cvs.bugs
Message-ID <[email protected]>

2003-04-24  Alexey Mahotkin <[email protected]>

Move logging buffer code to separate log-buffer.[ch]


 src/Makefile.am  |    1 
 src/Makefile.in  |   56 +++++++++--------
 src/client.c     |  157 -------------------------------------------------
 src/log-buffer.c |  173 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/log-buffer.h |   20 ++++++
 5 files changed, 224 insertions(+), 183 deletions(-)

--- ccvs/src/client.c~log-buffer	Thu Apr 24 23:03:50 2003
+++ ccvs-alexm/src/client.c	Thu Apr 24 23:05:12 2003
@@ -21,6 +21,7 @@
 #include "getline.h"
 #include "edit.h"
 #include "buffer.h"
+#include "log-buffer.h"
 
 #ifdef CLIENT_SUPPORT
 
@@ -406,162 +407,6 @@ static struct buffer *to_server;
 static struct buffer *from_server;
 
 
-/* We want to be able to log data sent between us and the server.  We
-   do it using log buffers.  Each log buffer has another buffer which
-   handles the actual I/O, and a file to log information to.
-
-   This structure is the closure field of a log buffer.  */
-
-struct log_buffer
-{
-    /* The underlying buffer.  */
-    struct buffer *buf;
-    /* The file to log information to.  */
-    FILE *log;
-};
-
-static struct buffer *log_buffer_initialize
-  PROTO((struct buffer *, FILE *, int, void (*) (struct buffer *)));
-static int log_buffer_input PROTO((void *, char *, int, int, int *));
-static int log_buffer_output PROTO((void *, const char *, int, int *));
-static int log_buffer_flush PROTO((void *));
-static int log_buffer_block PROTO((void *, int));
-static int log_buffer_shutdown PROTO((struct buffer *));
-
-/* Create a log buffer.  */
-
-static struct buffer *
-log_buffer_initialize (buf, fp, input, memory)
-     struct buffer *buf;
-     FILE *fp;
-     int input;
-     void (*memory) PROTO((struct buffer *));
-{
-    struct log_buffer *n;
-
-    n = (struct log_buffer *) xmalloc (sizeof *n);
-    n->buf = buf;
-    n->log = fp;
-    return buf_initialize (input ? log_buffer_input : NULL,
-			   input ? NULL : log_buffer_output,
-			   input ? NULL : log_buffer_flush,
-			   log_buffer_block,
-			   log_buffer_shutdown,
-			   memory,
-			   n);
-}
-
-/* The input function for a log buffer.  */
-
-static int
-log_buffer_input (closure, data, need, size, got)
-     void *closure;
-     char *data;
-     int need;
-     int size;
-     int *got;
-{
-    struct log_buffer *lb = (struct log_buffer *) closure;
-    int status;
-    size_t n_to_write;
-
-    if (lb->buf->input == NULL)
-	abort ();
-
-    status = (*lb->buf->input) (lb->buf->closure, data, need, size, got);
-    if (status != 0)
-	return status;
-
-    if (*got > 0)
-    {
-	n_to_write = *got;
-	if (fwrite (data, 1, n_to_write, lb->log) != n_to_write)
-	    error (0, errno, "writing to log file");
-    }
-
-    return 0;
-}
-
-/* The output function for a log buffer.  */
-
-static int
-log_buffer_output (closure, data, have, wrote)
-     void *closure;
-     const char *data;
-     int have;
-     int *wrote;
-{
-    struct log_buffer *lb = (struct log_buffer *) closure;
-    int status;
-    size_t n_to_write;
-
-    if (lb->buf->output == NULL)
-	abort ();
-
-    status = (*lb->buf->output) (lb->buf->closure, data, have, wrote);
-    if (status != 0)
-	return status;
-
-    if (*wrote > 0)
-    {
-	n_to_write = *wrote;
-	if (fwrite (data, 1, n_to_write, lb->log) != n_to_write)
-	    error (0, errno, "writing to log file");
-    }
-
-    return 0;
-}
-
-/* The flush function for a log buffer.  */
-
-static int
-log_buffer_flush (closure)
-     void *closure;
-{
-    struct log_buffer *lb = (struct log_buffer *) closure;
-
-    if (lb->buf->flush == NULL)
-	abort ();
-
-    /* We don't really have to flush the log file here, but doing it
-       will let tail -f on the log file show what is sent to the
-       network as it is sent.  */
-    if (fflush (lb->log) != 0)
-        error (0, errno, "flushing log file");
-
-    return (*lb->buf->flush) (lb->buf->closure);
-}
-
-/* The block function for a log buffer.  */
-
-static int
-log_buffer_block (closure, block)
-     void *closure;
-     int block;
-{
-    struct log_buffer *lb = (struct log_buffer *) closure;
-
-    if (block)
-	return set_block (lb->buf);
-    else
-	return set_nonblock (lb->buf);
-}
-
-/* The shutdown function for a log buffer.  */
-
-static int
-log_buffer_shutdown (buf)
-     struct buffer *buf;
-{
-    struct log_buffer *lb = (struct log_buffer *) buf->closure;
-    int retval;
-
-    retval = buf_shutdown (lb->buf);
-    if (fclose (lb->log) < 0)
-	error (0, errno, "closing log file");
-    return retval;
-}
-
 /*
  * Read a line from the server.  Result does not include the terminating \n.
  *
--- /dev/null	Wed Jan  1 02:48:46 2003
+++ ccvs-alexm/src/log-buffer.c	Thu Apr 24 23:03:50 2003
@@ -0,0 +1,173 @@
+/* CVS client logging buffer.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.  */
+
+#include <config.h>
+
+#include <stdio.h>
+
+#include "cvs.h"
+#include "buffer.h"
+
+/* We want to be able to log data sent between us and the server.  We
+   do it using log buffers.  Each log buffer has another buffer which
+   handles the actual I/O, and a file to log information to.
+
+   This structure is the closure field of a log buffer.  */
+
+struct log_buffer
+{
+    /* The underlying buffer.  */
+    struct buffer *buf;
+    /* The file to log information to.  */
+    FILE *log;
+};
+
+static int log_buffer_input PROTO((void *, char *, int, int, int *));
+static int log_buffer_output PROTO((void *, const char *, int, int *));
+static int log_buffer_flush PROTO((void *));
+static int log_buffer_block PROTO((void *, int));
+static int log_buffer_shutdown PROTO((struct buffer *));
+
+/* Create a log buffer.  */
+
+struct buffer *
+log_buffer_initialize (buf, fp, input, memory)
+     struct buffer *buf;
+     FILE *fp;
+     int input;
+     void (*memory) PROTO((struct buffer *));
+{
+    struct log_buffer *n;
+
+    n = (struct log_buffer *) xmalloc (sizeof *n);
+    n->buf = buf;
+    n->log = fp;
+    return buf_initialize (input ? log_buffer_input : NULL,
+			   input ? NULL : log_buffer_output,
+			   input ? NULL : log_buffer_flush,
+			   log_buffer_block,
+			   log_buffer_shutdown,
+			   memory,
+			   n);
+}
+
+/* The input function for a log buffer.  */
+
+static int
+log_buffer_input (closure, data, need, size, got)
+     void *closure;
+     char *data;
+     int need;
+     int size;
+     int *got;
+{
+    struct log_buffer *lb = (struct log_buffer *) closure;
+    int status;
+    size_t n_to_write;
+
+    if (lb->buf->input == NULL)
+	abort ();
+
+    status = (*lb->buf->input) (lb->buf->closure, data, need, size, got);
+    if (status != 0)
+	return status;
+
+    if (*got > 0)
+    {
+	n_to_write = *got;
+	if (fwrite (data, 1, n_to_write, lb->log) != n_to_write)
+	    error (0, errno, "writing to log file");
+    }
+
+    return 0;
+}
+
+/* The output function for a log buffer.  */
+
+static int
+log_buffer_output (closure, data, have, wrote)
+     void *closure;
+     const char *data;
+     int have;
+     int *wrote;
+{
+    struct log_buffer *lb = (struct log_buffer *) closure;
+    int status;
+    size_t n_to_write;
+
+    if (lb->buf->output == NULL)
+	abort ();
+
+    status = (*lb->buf->output) (lb->buf->closure, data, have, wrote);
+    if (status != 0)
+	return status;
+
+    if (*wrote > 0)
+    {
+	n_to_write = *wrote;
+	if (fwrite (data, 1, n_to_write, lb->log) != n_to_write)
+	    error (0, errno, "writing to log file");
+    }
+
+    return 0;
+}
+
+/* The flush function for a log buffer.  */
+
+static int
+log_buffer_flush (closure)
+     void *closure;
+{
+    struct log_buffer *lb = (struct log_buffer *) closure;
+
+    if (lb->buf->flush == NULL)
+	abort ();
+
+    /* We don't really have to flush the log file here, but doing it
+       will let tail -f on the log file show what is sent to the
+       network as it is sent.  */
+    if (fflush (lb->log) != 0)
+        error (0, errno, "flushing log file");
+
+    return (*lb->buf->flush) (lb->buf->closure);
+}
+
+/* The block function for a log buffer.  */
+
+static int
+log_buffer_block (closure, block)
+     void *closure;
+     int block;
+{
+    struct log_buffer *lb = (struct log_buffer *) closure;
+
+    if (block)
+	return set_block (lb->buf);
+    else
+	return set_nonblock (lb->buf);
+}
+
+/* The shutdown function for a log buffer.  */
+
+static int
+log_buffer_shutdown (buf)
+     struct buffer *buf;
+{
+    struct log_buffer *lb = (struct log_buffer *) buf->closure;
+    int retval;
+
+    retval = buf_shutdown (lb->buf);
+    if (fclose (lb->log) < 0)
+	error (0, errno, "closing log file");
+    return retval;
+}
+
--- /dev/null	Wed Jan  1 02:48:46 2003
+++ ccvs-alexm/src/log-buffer.h	Thu Apr 24 23:03:50 2003
@@ -0,0 +1,20 @@
+/* CVS client logging buffer.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.  */
+
+
+#ifndef LOG_BUFFER_H__
+#define LOG_BUFFER_H__
+
+struct buffer *log_buffer_initialize
+  PROTO((struct buffer *, FILE *, int, void (*) (struct buffer *)));
+
+#endif LOG_BUFFER_H__
--- ccvs/src/Makefile.am~log-buffer	Thu Apr 24 23:03:50 2003
+++ ccvs-alexm/src/Makefile.am	Thu Apr 24 23:06:52 2003
@@ -54,6 +54,7 @@ cvs_SOURCES = \
 	import.c \
 	lock.c \
 	log.c \
+	log-buffer.c log-buffer.h \
 	login.c \
 	logmsg.c \
 	main.c \
--- ccvs/src/Makefile.in~log-buffer	Thu Apr 24 23:03:50 2003
+++ ccvs-alexm/src/Makefile.in	Thu Apr 24 23:06:56 2003
@@ -146,6 +146,7 @@ cvs_SOURCES = \
 	import.c \
 	lock.c \
 	log.c \
+	log-buffer.c log-buffer.h \
 	login.c \
 	logmsg.c \
 	main.c \
@@ -226,17 +227,17 @@ am_cvs_OBJECTS = add.$(OBJEXT) admin.$(O
 	expand_path.$(OBJEXT) fileattr.$(OBJEXT) filesubr.$(OBJEXT) \
 	find_names.$(OBJEXT) hardlink.$(OBJEXT) hash.$(OBJEXT) \
 	history.$(OBJEXT) ignore.$(OBJEXT) import.$(OBJEXT) \
-	lock.$(OBJEXT) log.$(OBJEXT) login.$(OBJEXT) logmsg.$(OBJEXT) \
-	main.$(OBJEXT) mkmodules.$(OBJEXT) modules.$(OBJEXT) \
-	myndbm.$(OBJEXT) no_diff.$(OBJEXT) parseinfo.$(OBJEXT) \
-	patch.$(OBJEXT) rcs.$(OBJEXT) rcscmds.$(OBJEXT) \
-	recurse.$(OBJEXT) release.$(OBJEXT) remove.$(OBJEXT) \
-	repos.$(OBJEXT) root.$(OBJEXT) rsh-client.$(OBJEXT) \
-	run.$(OBJEXT) scramble.$(OBJEXT) server.$(OBJEXT) \
-	socket-client.$(OBJEXT) status.$(OBJEXT) subr.$(OBJEXT) \
-	tag.$(OBJEXT) update.$(OBJEXT) version.$(OBJEXT) \
-	vers_ts.$(OBJEXT) watch.$(OBJEXT) wrapper.$(OBJEXT) \
-	zlib.$(OBJEXT)
+	lock.$(OBJEXT) log.$(OBJEXT) log-buffer.$(OBJEXT) \
+	login.$(OBJEXT) logmsg.$(OBJEXT) main.$(OBJEXT) \
+	mkmodules.$(OBJEXT) modules.$(OBJEXT) myndbm.$(OBJEXT) \
+	no_diff.$(OBJEXT) parseinfo.$(OBJEXT) patch.$(OBJEXT) \
+	rcs.$(OBJEXT) rcscmds.$(OBJEXT) recurse.$(OBJEXT) \
+	release.$(OBJEXT) remove.$(OBJEXT) repos.$(OBJEXT) \
+	root.$(OBJEXT) rsh-client.$(OBJEXT) run.$(OBJEXT) \
+	scramble.$(OBJEXT) server.$(OBJEXT) socket-client.$(OBJEXT) \
+	status.$(OBJEXT) subr.$(OBJEXT) tag.$(OBJEXT) update.$(OBJEXT) \
+	version.$(OBJEXT) vers_ts.$(OBJEXT) watch.$(OBJEXT) \
+	wrapper.$(OBJEXT) zlib.$(OBJEXT)
 cvs_OBJECTS = $(am_cvs_OBJECTS)
 cvs_LDFLAGS =
 SCRIPTS = $(bin_SCRIPTS)
@@ -263,22 +264,22 @@ am__depfiles_maybe = depfiles
 @AMDEP_TRUE@	./$(DEPDIR)/hardlink.Po ./$(DEPDIR)/hash.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/history.Po ./$(DEPDIR)/ignore.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/import.Po ./$(DEPDIR)/lock.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/log.Po ./$(DEPDIR)/login.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/logmsg.Po ./$(DEPDIR)/main.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/mkmodules.Po ./$(DEPDIR)/modules.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/myndbm.Po ./$(DEPDIR)/no_diff.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/parseinfo.Po ./$(DEPDIR)/patch.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/rcs.Po ./$(DEPDIR)/rcscmds.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/recurse.Po ./$(DEPDIR)/release.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/remove.Po ./$(DEPDIR)/repos.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/root.Po ./$(DEPDIR)/rsh-client.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/run.Po ./$(DEPDIR)/scramble.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/server.Po ./$(DEPDIR)/socket-client.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/status.Po ./$(DEPDIR)/subr.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/tag.Po ./$(DEPDIR)/update.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/vers_ts.Po ./$(DEPDIR)/version.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/watch.Po ./$(DEPDIR)/wrapper.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/zlib.Po
+@AMDEP_TRUE@	./$(DEPDIR)/log-buffer.Po ./$(DEPDIR)/log.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/login.Po ./$(DEPDIR)/logmsg.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/main.Po ./$(DEPDIR)/mkmodules.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/modules.Po ./$(DEPDIR)/myndbm.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/no_diff.Po ./$(DEPDIR)/parseinfo.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/patch.Po ./$(DEPDIR)/rcs.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/rcscmds.Po ./$(DEPDIR)/recurse.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/release.Po ./$(DEPDIR)/remove.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/repos.Po ./$(DEPDIR)/root.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/rsh-client.Po ./$(DEPDIR)/run.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/scramble.Po ./$(DEPDIR)/server.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/socket-client.Po ./$(DEPDIR)/status.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/subr.Po ./$(DEPDIR)/tag.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/update.Po ./$(DEPDIR)/vers_ts.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/version.Po ./$(DEPDIR)/watch.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/wrapper.Po ./$(DEPDIR)/zlib.Po
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 CCLD = $(CC)
@@ -382,6 +383,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ignore.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/import.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lock.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log-buffer.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/login.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/logmsg.Po@am__quote@

_


--alexm
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.