From 0daaeb1882f918a279970db7bd9a7313881ca4c0 Mon Sep 17 00:00:00 2001 Message-Id: <0daaeb1882f918a279970db7bd9a7313881ca4c0.1717543471.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sun, 13 Jan 2002 13:33:54 +0000 Subject: [PATCH] Packet handler functions now have a @typedef@ name. Organization: Straylight/Edgeware From: mdw --- man/pkbuf.3 | 27 +++++++++++++++------------ man/selpk.3 | 19 +++++++------------ pkbuf.c | 14 ++++++-------- pkbuf.h | 25 +++++++++++++------------ selpk.c | 14 ++++++-------- selpk.h | 16 +++++++--------- 6 files changed, 54 insertions(+), 61 deletions(-) diff --git a/man/pkbuf.3 b/man/pkbuf.3 index 9d26463..cdc6bac 100644 --- a/man/pkbuf.3 +++ b/man/pkbuf.3 @@ -18,10 +18,7 @@ pkbuf \- split packets out of asynchronously received blocks .BI "size_t pkbuf_free(pkbuf *" pk ", octet **" p ); .BI "void pkbuf_snarf(pkbuf *" pk ", const void *" p ", size_t " sz ); .BI "void pkbuf_want(pkbuf *" pk ", size_t " want ); -.BI "void pkbuf_init(pkbuf *" pk , -.BI " void (*" func ")(octet *" b ", size_t " sz ", pkbuf *" pk , -.BI " size_t *" keep ", void *" p ), -.BI " void *" pk ); +.BI "void pkbuf_init(pkbuf *" pk ", pkbuf_func *" func ", void *" p ); .BI "void pkbuf_destroy(pkbuf *" pk ); .fi .SH "DESCRIPTION" @@ -49,14 +46,13 @@ A pointer to the block of memory to use for the packet buffer. The packet buffer will allocate memory to store incoming data automatically: this structure just contains bookkeeping information. .TP -.nf -.BI "void (*" func ")(octet *" b ", size_t " sz ", pkbuf *" p , -.BI " size_t *" keep ", void *" p ) -.fi +.BI "pkbuf_func *" func The .I packet-handler function to which the packet buffer should pass packets of data when -they're received. +they're received. See +.B "Packet breaking and the handler function" +below. .TP .BI "void *" p A pointer argument to be passed to the function when a packet arrives. @@ -134,7 +130,7 @@ The function is trivially implemented in terms of the more complex .B pkbuf_free / pkbuf_flush interface. -.SS "Packet breaking and the handler fucntion" +.SS "Packet breaking and the handler function" The function .B pkbuf_want is used to inform the packet buffer of the expected length of the next @@ -144,8 +140,15 @@ to the packet buffer and a size .I sz of the packet. .PP -When enough data has arrived, the packet-handler function is called, and -passed: +When enough data has arrived, the packet-handler function is called. +This has the signature +.IP +.nf +.BI "void (*" func ")(octet *" b ", size_t " sz ", pkbuf *" p , +.BI " size_t *" keep ", void *" p ); +.fi +.PP +It is passed: .TP .BI "octet *" b A pointer to the packet data in the buffer, or zero to signify diff --git a/man/selpk.3 b/man/selpk.3 index 1163d69..665a883 100644 --- a/man/selpk.3 +++ b/man/selpk.3 @@ -14,12 +14,8 @@ selpk \- packet-buffering input selector .BI "void selpk_enable(selpk *" pk ); .BI "void selpk_disable(selpk *" pk ); .BI "void selpk_want(selpk *" pk ", size_t " sz ); -.BI "void selpk_init(selpk *" pk , -.BI " sel_state *" s , -.BI " int " fd , -.BI " void (*" func ")(octet *" b ", size_t " sz ", pkbuf *" pk , -.BI " size_t *" keep ", void *" p ), -.BI " void *" p ); +.BI "void selpk_init(selpk *" pk ", sel_state *" s ", int " fd , +.BI " pkbuf *" func ", void *" p ); .BI "void selpk_destroy(selpk *" b ); .fi .SH DESCRIPTION @@ -57,18 +53,17 @@ for more details about multiplexors, and how this whole system works. .BI "int " fd The file descriptor of the stream the selector should read from. .TP -.nf -.BI "void (*" func ")(octet *" b ", size_t " sz ", pkbuf *" p , -.BI " size_t *" keep ", void *" p ) -.fi +.BI "pkbuf_func *" func The .I "packet handler" -function. It is passed a pointer to each packet read from the file (or +function. It is given a pointer to each packet read from the file (or null to indicate end-of-file) and an arbitrary pointer (the .I p argument to .B selpk_init -described below). +described below). See +.BR pkbuf (3) +for full details. .TP .BI "void *" p A pointer argument passed to diff --git a/pkbuf.c b/pkbuf.c index 629f531..dcc4d79 100644 --- a/pkbuf.c +++ b/pkbuf.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: pkbuf.c,v 1.4 2001/02/03 16:23:33 mdw Exp $ + * $Id: pkbuf.c,v 1.5 2002/01/13 13:33:51 mdw Exp $ * * Simple packet buffering * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: pkbuf.c,v $ + * Revision 1.5 2002/01/13 13:33:51 mdw + * Packet handler functions now have a @typedef@ name. + * * Revision 1.4 2001/02/03 16:23:33 mdw * Bug fix: handle a disable during a close-induced flush without dumping * core. @@ -233,9 +236,7 @@ void pkbuf_want(pkbuf *pk, size_t want) /* --- @pkbuf_init@ --- * * * Arguments: @pkbuf *pk@ = pointer to buffer block - * @void (*func)(octet *b, size_t sz, pkbuf *pk,@ - * @size_t *keep, void *p)@ = - * handler function + * @pkbuf *func@ = handler function * @void *p@ = argument pointer for @func@ * * Returns: --- @@ -244,10 +245,7 @@ void pkbuf_want(pkbuf *pk, size_t want) * the provided function for handling. */ -void pkbuf_init(pkbuf *pk, - void (*func)(octet */*b*/, size_t /*sz*/, - pkbuf */*pk*/, size_t */*keep*/, void */*p*/), - void *p) +void pkbuf_init(pkbuf *pk, pkbuf_func *func, void *p) { pk->func = func; pk->p = p; diff --git a/pkbuf.h b/pkbuf.h index 00c437b..3305992 100644 --- a/pkbuf.h +++ b/pkbuf.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: pkbuf.h,v 1.3 2001/02/03 16:23:33 mdw Exp $ + * $Id: pkbuf.h,v 1.4 2002/01/13 13:33:51 mdw Exp $ * * Simple packet buffering * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: pkbuf.h,v $ + * Revision 1.4 2002/01/13 13:33:51 mdw + * Packet handler functions now have a @typedef@ name. + * * Revision 1.3 2001/02/03 16:23:33 mdw * Bug fix: handle a disable during a close-induced flush without dumping * core. @@ -63,14 +66,18 @@ /*----- Data structures ---------------------------------------------------*/ +struct pkbuf; + +typedef void pkbuf_func(octet */*b*/, size_t /*sz*/, + struct pkbuf */*pk*/, size_t */*keep*/, + void */*p*/); + typedef struct pkbuf { size_t sz; /* Size of current buffer */ size_t len; /* Length of data in the buffer */ size_t want; /* Want this many bytes for packet */ unsigned f; /* Various state flags */ - void (*func)(octet */*b*/, size_t /*sz*/, - struct pkbuf */*pk*/, size_t */*keep*/, - void */*p*/); /* Handler function */ + pkbuf_func *func; /* Handler function */ void *p; /* Argument for handler */ arena *a; /* Memory allocation arena */ octet *buf; /* Actual buffer space */ @@ -164,9 +171,7 @@ extern void pkbuf_want(pkbuf */*pk*/, size_t /*want*/); /* --- @pkbuf_init@ --- * * * Arguments: @pkbuf *pk@ = pointer to buffer block - * @void (*func)(octet *b, size_t sz, pkbuf *pk,@ - * @size_t *keep, void *p)@ = - * handler function + * @pkbuf_func *func@ = handler function * @void *p@ = argument pointer for @func@ * * Returns: --- @@ -175,11 +180,7 @@ extern void pkbuf_want(pkbuf */*pk*/, size_t /*want*/); * the provided function for handling. */ -extern void pkbuf_init(pkbuf */*pk*/, - void (*/*func*/)(octet */*b*/, size_t /*sz*/, - pkbuf */*pk*/, size_t */*keep*/, - void */*p*/), - void */*p*/); +extern void pkbuf_init(pkbuf */*pk*/, pkbuf_func */*func*/, void */*p*/); /* --- @pkbuf_destroy@ --- * * diff --git a/selpk.c b/selpk.c index 9d077b6..4d1b5eb 100644 --- a/selpk.c +++ b/selpk.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: selpk.c,v 1.1 2000/06/17 10:39:19 mdw Exp $ + * $Id: selpk.c,v 1.2 2002/01/13 13:33:51 mdw Exp $ * * Packet-buffering select handler * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: selpk.c,v $ + * Revision 1.2 2002/01/13 13:33:51 mdw + * Packet handler functions now have a @typedef@ name. + * * Revision 1.1 2000/06/17 10:39:19 mdw * Experimental new support for packet buffering. * @@ -145,7 +148,7 @@ void selpk_want(selpk *pk, size_t sz) * Arguments: @selpk *pk@ = pointer to buffer block * @sel_state *s@ = pointer to select state to attach to * @int fd@ = file descriptor to listen to - * @void (*func)(char *s, void *p)@ = function to call + * @pkbuf_func *func@ = function to call * @void *p@ = argument for function * * Returns: --- @@ -153,12 +156,7 @@ void selpk_want(selpk *pk, size_t sz) * Use: Initializes a buffer block. */ -void selpk_init(selpk *pk, - sel_state *s, - int fd, - void (*func)(octet */*b*/, size_t /*sz*/, pkbuf */*pk*/, - size_t */*keep*/, void */*p*/), - void *p) +void selpk_init(selpk *pk, sel_state *s, int fd, pkbuf_func *func, void *p) { pkbuf_init(&pk->pk, func, p); pk->pk.f &= ~PKBUF_ENABLE; diff --git a/selpk.h b/selpk.h index 5aeed22..4f84048 100644 --- a/selpk.h +++ b/selpk.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: selpk.h,v 1.2 2000/07/16 18:56:00 mdw Exp $ + * $Id: selpk.h,v 1.3 2002/01/13 13:33:51 mdw Exp $ * * Packet-buffering select handler * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: selpk.h,v $ + * Revision 1.3 2002/01/13 13:33:51 mdw + * Packet handler functions now have a @typedef@ name. + * * Revision 1.2 2000/07/16 18:56:00 mdw * Fix a function declaration which slipped through the net. * @@ -105,7 +108,7 @@ extern void selpk_want(selpk */*pk*/, size_t /*sz*/); * Arguments: @selpk *pk@ = pointer to buffer block * @sel_state *s@ = pointer to select state to attach to * @int fd@ = file descriptor to listen to - * @void (*func)(...)@ = function to call + * @pkbuf_func *func@ = function to call * @void *p@ = argument for function * * Returns: --- @@ -113,13 +116,8 @@ extern void selpk_want(selpk */*pk*/, size_t /*sz*/); * Use: Initializes a buffer block. */ -extern void selpk_init(selpk */*pk*/, - sel_state */*s*/, - int /*fd*/, - void (*/*func*/)(octet */*b*/, size_t /*sz*/, - pkbuf */*pk*/, size_t */*keep*/, - void */*p*/), - void */*p*/); +extern void selpk_init(selpk */*pk*/, sel_state */*s*/, int /*fd*/, + pkbuf_func */*func*/, void */*p*/); /* --- @selpk_destroy@ --- * * -- [mdw]