summaryrefslogtreecommitdiffabout
path: root/src/syslog-port.c
Side-by-side diff
Diffstat (limited to 'src/syslog-port.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/syslog-port.c124
1 files changed, 22 insertions, 102 deletions
diff --git a/src/syslog-port.c b/src/syslog-port.c
index 4b27ef9..4388c10 100644
--- a/src/syslog-port.c
+++ b/src/syslog-port.c
@@ -28,7 +28,7 @@ typedef off_t scm_t_off;
#endif
#define GAMMA_SYSLOG_PORT_BUFSIZE 1024
-static scm_t_bits scm_tc16_syslog_port;
+static scm_t_port_type *scm_syslog_port_type;
struct _gamma_syslog_port {
int prio;
};
@@ -37,118 +37,40 @@ static SCM
_make_syslog_port(int prio)
{
struct _gamma_syslog_port *dp;
- SCM port;
- scm_port *pt;
- dp = scm_gc_malloc (sizeof (struct _gamma_syslog_port), "syslog-port");
+ dp = scm_gc_typed_calloc (struct _gamma_syslog_port);
dp->prio = prio;
-
- port = scm_new_port_table_entry(scm_tc16_syslog_port);
- pt = SCM_PTAB_ENTRY(port);
- pt->rw_random = 0;
- pt->write_buf = scm_gc_malloc(GAMMA_SYSLOG_PORT_BUFSIZE,
- "syslog port buffer");
- pt->write_pos = pt->write_buf;
- pt->write_buf_size = GAMMA_SYSLOG_PORT_BUFSIZE;
- pt->write_end = pt->write_buf + pt->write_buf_size;
- SCM_SET_CELL_TYPE(port,
- (scm_tc16_syslog_port |
- SCM_OPN | SCM_WRTNG | SCM_BUFLINE));
- SCM_SETSTREAM(port, dp);
- return port;
+ return scm_c_make_port(scm_syslog_port_type,
+ SCM_OPN | SCM_WRTNG | SCM_BUFLINE,
+ (scm_t_bits) dp);
}
#define SYSLOG_PORT(x) ((struct _gamma_syslog_port *) SCM_STREAM (x))
-static SCM
-_syslog_port_mark(SCM port)
-{
- return SCM_BOOL_F;
-}
-
static void
-_syslog_port_flush(SCM port)
-{
- struct _gamma_syslog_port *dp = SYSLOG_PORT(port);
- scm_port *pt = SCM_PTAB_ENTRY(port);
- size_t size = pt->write_pos - pt->write_buf;
- unsigned char *nl = memchr(pt->write_buf, '\n', size);
- int wrsize;
-
- if (!nl)
- return;
-
- wrsize = nl - pt->write_buf;
-
- *nl = 0;
- syslog (dp->prio, "%s", (char *) pt->write_buf);
- *nl = '\n';
-
- if (wrsize < size) {
- size_t write_start;
-
- nl++;
- write_start = pt->write_pos - nl;
- memmove(pt->write_buf, nl, write_start);
- pt->write_pos = pt->write_buf + write_start;
- } else
- pt->write_pos = pt->write_buf;
-}
-
-static int
_syslog_port_close(SCM port)
{
struct _gamma_syslog_port *dp = SYSLOG_PORT(port);
-
- if (dp) {
- _syslog_port_flush(port);
- SCM_SETSTREAM(port, NULL);
- scm_gc_free(dp, sizeof(struct _gamma_syslog_port),
- "syslog-port");
- }
- return 0;
+ /* nothing */
}
-static scm_sizet
+static size_t
_syslog_port_free(SCM port)
+/* FIXME: basically, a no-op */
{
_syslog_port_close(port);
return 0;
}
-static int
-_syslog_port_fill_input(SCM port)
-{
- return EOF;
-}
-
-static void
-_syslog_port_write(SCM port, const void *data, size_t size)
+static size_t
+_syslog_port_write(SCM port, SCM src, size_t start, size_t count)
{
- scm_port *pt = SCM_PTAB_ENTRY (port);
- size_t space = pt->write_end - pt->write_pos;
- if (space < size) {
- size_t start = pt->write_pos - pt->write_buf;
- size_t new_size = pt->write_buf_size;
-
- do {
- /*FIXME*/
- new_size *= 2;
- } while (new_size - start < size);
-
- pt->write_buf = scm_gc_realloc(pt->write_buf,
- pt->write_buf_size,
- new_size,
- "syslog port buffer");
- pt->write_buf_size = new_size;
- pt->write_end = pt->write_buf + pt->write_buf_size;
- pt->write_pos = pt->write_buf + start;
- }
- memcpy(pt->write_pos, data, size);
- pt->write_pos += size;
-
- if (memchr (data, '\n', size))
- _syslog_port_flush(port);
+ struct _gamma_syslog_port *dp = SYSLOG_PORT(port);
+ syslog(dp->prio, "%*.*s",
+ (int) count,
+ (int) count,
+ SCM_BYTEVECTOR_CONTENTS(src) + start);
+ return count;
}
static scm_t_off
@@ -180,15 +102,13 @@ SCM_DEFINE_PUBLIC(scm_open_syslog_port, "open-syslog-port", 1, 0, 0,
void
_gamma_init_syslog_port()
{
- scm_tc16_syslog_port = scm_make_port_type("syslog-port",
- _syslog_port_fill_input,
+ scm_syslog_port_type = scm_make_port_type("syslog-port",
+ NULL,
_syslog_port_write);
- scm_set_port_mark(scm_tc16_syslog_port, _syslog_port_mark);
- scm_set_port_free(scm_tc16_syslog_port, _syslog_port_free);
- scm_set_port_print(scm_tc16_syslog_port, _syslog_port_print);
- scm_set_port_flush(scm_tc16_syslog_port, _syslog_port_flush);
- scm_set_port_close(scm_tc16_syslog_port, _syslog_port_close);
- scm_set_port_seek(scm_tc16_syslog_port, _syslog_port_seek);
+ scm_set_port_free(scm_syslog_port_type, _syslog_port_free);
+ scm_set_port_print(scm_syslog_port_type, _syslog_port_print);
+ scm_set_port_close(scm_syslog_port_type, _syslog_port_close);
+ scm_set_port_seek(scm_syslog_port_type, _syslog_port_seek);
#include <syslog-port.x>
}

Return to:

Send suggestions and report system problems to the System administrator.