INN commit: trunk/innfeed (endpoint.c endpoint.h)

INN Commit rra at isc.org
Fri Jun 24 17:54:10 UTC 2011


    Date: Friday, June 24, 2011 @ 10:54:10
  Author: iulius
Revision: 9212

fix compilation issues and useless prototypes

* Remove the useless timerCallback() function.

* Add a missing argument in a call to prepareWrite().

* "len" should be a socklen_t and not an int.

* "program" was not declared as a char*.

* Better names for variables.

* Remove useless prototypes, and make a few functions as static.

* Typos in comments.

Thanks for Florian Schlichting for the main part of the patch.

Modified:
  trunk/innfeed/endpoint.c
  trunk/innfeed/endpoint.h

------------+
 endpoint.c |   78 ++++++++++++++++++++++-------------------------------------
 endpoint.h |   50 ++++++++++++++++++-------------------
 2 files changed, 55 insertions(+), 73 deletions(-)

Modified: endpoint.c
===================================================================
--- endpoint.c	2011-06-24 16:59:14 UTC (rev 9211)
+++ endpoint.c	2011-06-24 17:54:10 UTC (rev 9212)
@@ -345,19 +345,19 @@
 
 
 
-/* Request a read to be done next time there's data. The endpoint
- * ENDP is what will do the read. BUFF is the Buffer the data should
- * go into. FUNC is the callback function to call when the read is
- * complete. CLIENTDATA is the client data to pass back into the
+/* Request a read to be done next time there's data. The endpoint ENDP
+ * is what will do the read. BUFFERS is the array of Buffers the data
+ * should go into. FUNC is the callback function to call when the read
+ * is complete. CLIENTDATA is the client data to pass back into the
  * callback function. MINLEN is the minimum amount of data to
- * read. If MINLEN is 0 then then BUFF must be filled, otherwise at
+ * read. If MINLEN is 0 then then BUFFERS must be filled, otherwise at
  * least MINLEN bytes must be read.
  *
- * BUFF can be null, in which case no read is actually done, but the
+ * BUFFERS can be NULL, in which case no read is actually done, but the
  * callback function will be called still. This is useful for
  * listening sockets.
  *
- * Returns 0 if the read couln't be prepared (for example if a read
+ * Returns 0 if the read couldn't be prepared (for example if a read
  * is already outstanding).
  */
 
@@ -400,12 +400,12 @@
 
 
 
-/* Request a write to be done at a later point. ENDP is the EndPoint
- * to do the write. BUFF is the Buffer to write from. FUNC is the
- * function to call when the write is complete. CLIENTDATA is some
+/* Request a write to be done at a later point. ENDP is the EndPoint to
+ * do the write. BUFFERS is the array of Buffers to write from. FUNC is
+ * the function to call when the write is complete. CLIENTDATA is some
  * data to hand back to the callback function.
  *
- * If BUFF is null, then no write will actually by done, but the
+ * If BUFFERS is NULL, then no write will actually by done, but the
  * callback function will still be called. This is useful for
  * connecting sockets.
  *
@@ -527,7 +527,7 @@
 }
 
 
-/* Updates a an existing timeout request to go off TIMETOSLEEP seconds from
+/* Updates an existing timeout request to go off TIMETOSLEEP seconds from
    now, or queues a new request.  Always returns a new ID. */
 TimeoutId updateSleep (TimeoutId tid, EndpTCB func, int timeToSleep,
                        void *clientData) 
@@ -1383,23 +1383,12 @@
 
 
 
-
 #if defined (WANT_MAIN)
 
-
 #define BUFF_SIZE 100
 
-
-void timerCallback (void *cd) ;
-void timerCallback (void *cd)
+static void lineIsWritten (EndPoint ep, IoStatus status, Buffer *buffers, void *d UNUSED)
 {
-  d_printf (1,"Callback \n") ;
-}
-
-  
-void lineIsWritten (EndPoint ep, IoStatus status, Buffer *buffer, void *data);
-void lineIsWritten (EndPoint ep, IoStatus status, Buffer *buffer, void *data)
-{
   int i ;
   
   if (status == IoDone)
@@ -1413,12 +1402,12 @@
       errno = oldErrno ;
     }
 
-  for (i = 0 ; buffer && buffer [i] ; i++)
-    delBuffer (buffer [i]) ;
+  for (i = 0 ; buffers && buffers[i] ; i++) {
+    delBuffer (buffers[i]);
+  }
 }
 
-void lineIsRead (EndPoint myEp, IoStatus status, Buffer *buffer, void *data);
-void lineIsRead (EndPoint myEp, IoStatus status, Buffer *buffer, void *d)
+static void lineIsRead (EndPoint myEp, IoStatus status, Buffer *buffers, void *d UNUSED)
 {
   Buffer *writeBuffers, *readBuffers ;
   Buffer newBuff1, newBuff2 ;
@@ -1445,13 +1434,13 @@
     }
   
   
-  data = bufferBase (buffer[0]) ;
-  len = bufferDataSize (buffer[0]) ;
+  data = bufferBase (buffers[0]);
+  len = bufferDataSize (buffers[0]);
   
   if (data [len - 1] == '\r' || data [len - 1] == '\n')
-    bufferDecrDataSize (buffer [0],1) ;
+    bufferDecrDataSize (buffers[0], 1);
   if (data [len - 1] == '\r' || data [len - 1] == '\n')
-    bufferDecrDataSize (buffer [0],1) ;
+    bufferDecrDataSize (buffers[0], 1);
 
   data [len] = '\0' ;
   
@@ -1469,19 +1458,14 @@
   strlcpy (p,"\" very tasty\n", bufferSize (newBuff2)) ;
   bufferSetDataSize (newBuff2,strlen (p)) ;
 
-  writeBuffers = makeBufferArray (newBuff1,buffer[0],newBuff2,NULL) ;
+  writeBuffers = makeBufferArray (newBuff1, buffers[0], newBuff2, NULL);
   readBuffers = makeBufferArray (newInputBuffer,NULL) ;
   
-  prepareWrite (myEp,writeBuffers,lineIsWritten,NULL) ;
-  prepareRead (myEp,readBuffers,lineIsRead,NULL,1) ;
-
-#if 0
-  myEp->registerWake (&timerCallback,theTime() + 7,0) ;
-#endif
+  prepareWrite(myEp, writeBuffers, NULL, lineIsWritten, NULL);
+  prepareRead(myEp, readBuffers, lineIsRead, NULL, 1);
 }
 
 
-static void printDate (TimeoutId tid, void *data) ;
 static void printDate (TimeoutId tid, void *data)
 {
   char dateString[30];
@@ -1501,7 +1485,6 @@
 
 TimeoutId rm ;
 
-static void Timeout (TimeoutId tid, void *data) ;
 static void Timeout (TimeoutId tid, void *data)
 {
   static int seeded ;
@@ -1541,14 +1524,13 @@
 }
 
 
-void newConn (EndPoint ep, IoStatus status, Buffer *buffer, void *d) ;
-void newConn (EndPoint ep, IoStatus status, Buffer *buffer, void *d)
+static void newConn (EndPoint ep, IoStatus status UNUSED, Buffer *buffers UNUSED, void *d UNUSED)
 {
   EndPoint newEp ;
   struct sockaddr_in in ;
   Buffer *readBuffers ;
   Buffer newBuff = newBuffer (BUFF_SIZE) ;
-  int len = sizeof (in) ;
+  socklen_t len = sizeof (in);
   int fd ;
 
   memset (&in, 0, sizeof (in)) ;
@@ -1563,11 +1545,11 @@
   
   newEp = newEndPoint (fd) ;
 
-  prepareRead (ep, NULL, newConn,NULL,0) ;
+  prepareRead(ep, NULL, newConn, NULL, 0);
 
   readBuffers = makeBufferArray (newBuff,NULL) ;
 
-  prepareRead (newEp, readBuffers, lineIsRead, NULL, 1) ;
+  prepareRead(newEp, readBuffers, lineIsRead, NULL, 1);
 
   d_printf (1,"Set up a new connection\n");
 }
@@ -1582,7 +1564,7 @@
   time_t t = theTime() ;
 
 
-  program = strrchr (argv[0],'/') ;
+  char * program = strrchr (argv[0],'/') ;
 
   if (!program)
     program = argv [0] ;
@@ -1612,7 +1594,7 @@
   
   accConn = newEndPoint (accFd) ;
 
-  prepareRead (accConn,NULL,newConn,NULL,0) ;
+  prepareRead(accConn, NULL, newConn, NULL, 0);
 
   prepareSleep (Timeout,5,(void *) 0x10) ;
 

Modified: endpoint.h
===================================================================
--- endpoint.h	2011-06-24 16:59:14 UTC (rev 9211)
+++ endpoint.h	2011-06-24 17:54:10 UTC (rev 9212)
@@ -5,12 +5,12 @@
 **  Written by James Brister <brister at vix.com>
 **
 **  The EndPoint objects are encapsulations of file descriptors that normally
-**  do blocking i/o (i.e. NOT fd's hooked to a disk file).  The EndPoint class
-**  provides methods for reqesting read/writes to happen when next possible
-**  and for the requestor to be notified when the i/o is complete (or failed
+**  do blocking I/O (i.e. NOT fd's hooked to a disk file).  The EndPoint class
+**  provides methods for requesting read/writes to happen when next possible
+**  and for the requestor to be notified when the I/O is complete (or failed
 **  for some reason).  Facilities for timeout notifications are provided too.
 **
-**  We should add a way to cancel prepared read/write.
+**  We should add a way to cancel prepared read/writes.
 */
 
 #if ! defined ( endpoint_h__ )
@@ -29,23 +29,23 @@
 
 
 
-/* These typedefs really lives in misc.h
+/* These typedefs really live in misc.h.
  *
  *****************************************
  *             
- * The basic (opqaue to the outside world) type.
+ * The basic (opaque to the outside world) type:
  *              
  *      typedef struct endpoint_s *EndPoint ;
  *
  *****************************************
  *
- * The returns status of an IO request
+ * The return status of an I/O request:
  *
  *      typedef enum {
- *          IoDone,                     i/o completed successfully 
- *          IoIncomplete,               i/o still got more to read/write
- *          IoProgress,                 i/o still got more to read/write
- *          IoFailed                    i/o failed
+ *          IoDone,                     I/O completed successfully 
+ *          IoIncomplete,               I/O still got more to read/write
+ *          IoProgress,                 I/O still got more to read/write
+ *          IoFailed                    I/O failed
  *      } IoStatus ;
  *
  * The completion callbacks are never called with the status IoIncomplete or
@@ -53,18 +53,18 @@
  *
  *****************************************
  *
- * typedef for function callback when IO is complete (or failed).
+ * typedef for function callback when I/O is complete (or failed).
  *      E is the EndPoint
  *      I is the status of the IO
- *      B is the buffer the IO was to read to or write from.
+ *      B is the buffer the IO was to read to or write from
  *      D is the client data originally given to prepare{Write,Read}
  *
  * typedef void (*EndpRWCB) (EndPoint e, IoStatus i, Buffer b, void *d) ;
  *
  *****************************************
  *
- * typedef for function callback when a timer has gone off. D is the client
- * data given to prepare{Sleep,Wake}
+ * typedef for function callback when a timer has gone off.  D is the client
+ * data given to prepare{Sleep,Wake}:
  *
  * typedef void (*EndpTCB) (void *d) ;
  *
@@ -74,14 +74,14 @@
 EndPoint newEndPoint (int fd) ;
 
 /* shutdown the file descriptor and delete the endpoint. */
-void delEndPoint (EndPoint endp) ;
+void delEndPoint (EndPoint ep);
 
 /* return the file descriptor the endpoint is managing */
 int endPointFd (EndPoint endp) ;
 
 /* Request a read when available. Reads MINLEN bytes into the
- * buffers in BUFFS. BUFFS is an array of Buffers, the last of which
- * must be NULL. Note that ownership of BUFFS is never asserted, but
+ * buffers in BUFFERS. BUFFERS is an array of Buffers, the last of which
+ * must be NULL. Note that ownership of BUFFERS is never asserted, but
  * the ownership of the Buffers in it is. So if an EndPoint is
  * deleted while a read is pending the Buffers will be released, but
  * the array won't be. If MINLEN is 0 then the buffers must be
@@ -90,15 +90,15 @@
  * callback. Returns non-zero if can be scheduled for processing.
  */
 int prepareRead (EndPoint endp,
-                 Buffer *buffs,
+                 Buffer *buffers,
                  EndpRWCB func,
                  void *clientData,
                  int minlen) ;
 
 /* Request a write when possible. All the data in the buffers in
- * BUFFS will be written out the endpoint. BUFFS is a NULL
- * terminated array of Buffers. See prepareWrite for a discussion on
- * the ownership of BUFFS and the Buffers inside BUFFS. The PROGRESS
+ * BUFFERS will be written out the endpoint. BUFFERS is a NULL
+ * terminated array of Buffers. See prepareRead for a discussion on
+ * the ownership of BUFFERS and the Buffers inside BUFFERS. The PROGRESS
  * callback function will be called and the CLIENTDATA value will be
  * passed through to it whenever any data is written except for the
  * final write.  The DONE callback function will be called and the
@@ -106,7 +106,7 @@
  * Returns non-zero if scheduled succesfully.
  */
 int prepareWrite (EndPoint endp,
-                  Buffer *buffs,
+                  Buffer *buffers,
                   EndpRWCB progress,
                   EndpRWCB done,
                   void *clientData) ;
@@ -144,9 +144,9 @@
      been serviced. */
 void *addWorkCallback (EndPoint endp, EndpWorkCbk cbk, void *data) ;
 
-void setSigHandler (int sig, void (*)(int)) ;
+void setSigHandler (int signum, void (*ptr)(int));
 
-/* remove the timeout that was previously requested. Retuesn true if
+/* remove the timeout that was previously requested. Returns true if
    succesfully removed, false otherwise. 0 is a legal parameter value, in
    which case the function simply returns. */
 bool removeTimeout (TimeoutId tid) ;




More information about the inn-committers mailing list