home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / comm / tcp / amitcp / src / l / inet-handler / handler.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-05  |  3.3 KB  |  144 lines

  1. /*
  2.  * handler.h
  3.  *
  4.  * Author: Tomi Ollila <too@cs.hut.fi>
  5.  *
  6.  * Copyright (c) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
  7.  *                    All rights reserved.
  8.  *
  9.  * Created: Sun Sep  5 22:46:50 1993 too
  10.  * Last modified: Mon Nov 15 23:26:52 1993 too
  11.  *
  12.  * $Id: handler.h,v 1.2 1993/11/17 12:06:50 too Exp too $
  13.  *
  14.  * HISTORY
  15.  * $Log: handler.h,v $
  16.  * Revision 1.2  1993/11/17  12:06:50  too
  17.  * *** empty log message ***
  18.  *
  19.  * Revision 1.1  1993/10/24  12:50:39  too
  20.  * Initial revision
  21.  *
  22.  */
  23.  
  24. #ifndef _HANDLER_H_
  25. #define _HANDLER_H_
  26.  
  27. #ifndef EXEC_MEMORY_H
  28. #include <exec/memory.h>
  29. #endif
  30.  
  31. #ifndef DEVICES_TIMER_H
  32. #include <devices/timer.h>
  33. #endif
  34.  
  35. #if !defined (_MULDIV_H_) && defined (__GNUC__)
  36. #include "muldiv.h"
  37. #endif
  38.  
  39. /*
  40.  * Timer stuff
  41.  */
  42.  
  43. static inline void Send_Timeout(struct timerequest * tr, LONG microtime)
  44. {
  45. #ifdef __GNUC__
  46.   divmodu(tr->tr_time.tv_secs, tr->tr_time.tv_micro, microtime, 1000000);
  47. #else
  48.   tr->tr_time.tv_secs = microtime / 1000000;
  49.   tr->tr_time.tv_micro = microtime % 1000000;
  50. #endif  
  51.   SendIO((struct IORequest *)tr);
  52. }
  53.  
  54. static inline void Abort_Timeout(struct timerequest * tr)
  55. {
  56.   AbortIO((struct IORequest *)tr);
  57.   WaitIO((struct IORequest *)tr);
  58. }
  59.  
  60. /***************************************************************************/
  61.  
  62. /*
  63.  * Macros for using packet information.
  64.  */
  65. #define msgToPkt(msg) ((struct DosPacket *)msg->mn_Node.ln_Name)
  66. #define pktReplyTask(pkt) (pkt->dp_Port->mp_SigTask)
  67.  
  68. /*
  69.  * Misc macros.
  70.  */
  71. #define EmptyList(list) (((struct List *)list)->lh_Head->ln_Succ == NULL)
  72.  
  73. static inline void * getBuffer(struct List * list, int size)
  74. {
  75.   if (EmptyList(list))
  76.     return AllocMem(size, MEMF_PUBLIC);
  77.   else
  78.     return RemHead(list);
  79. }
  80.  
  81. static inline void * getBufferInitNew(struct List * list, int size,
  82.                       void * nd, int nds)
  83. {
  84.   if (EmptyList(list)) {
  85.     void * p;
  86.     if ((p = AllocMem(size, MEMF_PUBLIC | MEMF_CLEAR)) != NULL)
  87.       CopyMem(nd, p, nds);
  88.     return p;
  89.   }
  90.   else
  91.     return RemHead(list);
  92. }
  93.  
  94. /***************************************************************************/
  95.  
  96. /*
  97.  * scan through list and execute 'code' for each list item.
  98.  */
  99. #define For_Each_List_Item(list, type, node, code) do { \
  100.    type node; \
  101.    for (node = (type)((struct List *)(list))->lh_Head; \
  102.     ((struct Node *)node)->ln_Succ; \
  103.     node = (type)((struct Node *)node)->ln_Succ) \
  104.      code } while (0)
  105.  
  106. /*
  107.  * same as before, but cache next node since current item is FreeMem()med
  108.  */
  109. #define For_Each_List_Item_CacheNext(list, type, node, code) do { \
  110.    type node; \
  111.    struct Node * next; \
  112.    for (node = (type)((struct List *)(list))->lh_Head; \
  113.     (next = ((struct Node *)node)->ln_Succ); \
  114.     node = (type)next) \
  115.      code } while (0)
  116.  
  117. #if 0
  118. #define For_Each_List_Item_CacheNext2(list, type, node, code) do { \
  119.    type node; \
  120.    struct Node * next = ((struct List *)(list))->lh_Head; \
  121.    for (node = (type)((struct List *)(list))->lh_Head; \
  122.     next; \
  123.     node = (type)next) \
  124.      { next = ((struct Node *)node)->ln_Succ; code } } while (0)
  125.  
  126. #define For_Each_List_Item_CacheNext2(list, type, node, code) do { \
  127.    type node; \
  128.    struct Node * next = ((struct List *)(list))->lh_Head; \
  129.      \
  130.    while (1) { \
  131.      node = (type)next; \
  132.      next = next->ln_Succ; \
  133.      if (next) \
  134.        code \
  135.      else \
  136.        break; \
  137.      } \
  138.    } while (0)
  139.  
  140. #endif
  141.  
  142. #endif /* _HANDLER_H_ */
  143.  
  144.