home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / comm / amitcp-3.0ß2.lha / AmiTCP / src / amitcp / api / amiga_libcallentry.h < prev    next >
C/C++ Source or Header  |  1994-02-16  |  6KB  |  186 lines

  1. /*
  2.  * $Id: amiga_libcallentry.h,v 3.3 1994/02/15 23:18:42 jraja Exp $
  3.  * 
  4.  * Copyright (c) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
  5.  *                    Helsinki University of Technology, Finland.
  6.  *                    All rights reserved.
  7.  *
  8.  * Created: Mon Feb 15 13:37:42 1993 too
  9.  * Last modified: Wed Feb 16 01:18:01 1994 jraja
  10.  * 
  11.  * HISTORY
  12.  * $Log: amiga_libcallentry.h,v $
  13.  * Revision 3.3  1994/02/15  23:18:42  jraja
  14.  * Changed sdFind() to return the sd via LONG * instead of ULONG * to be
  15.  * consistent with API types.
  16.  *
  17.  * Revision 3.2  1994/01/18  22:53:22  jraja
  18.  * Added macros CHECK_TASK_NULL() and CHECK_TASK_VOID().
  19.  *
  20.  * Revision 3.1  1994/01/04  14:17:16  too
  21.  * Removed obsolete fdAlloc. It is now replaced by sdFind which uses
  22.  * new socket uasge bitmask to find free socket index.
  23.  * ..prototype for sdFind added
  24.  *
  25.  * Revision 1.20  1993/06/04  11:16:15  jraja
  26.  * Fixes for first public release.
  27.  *
  28.  * Revision 1.19  1993/05/17  01:02:04  ppessi
  29.  * Changed RCS version
  30.  *
  31.  * Revision 1.18  1993/05/15  10:06:42  too
  32.  * Removed macros AMI_ENTRY() and API_EXIT()
  33.  *
  34.  * Revision 1.17  93/04/26  11:52:33  11:52:33  too (Tomi Ollila)
  35.  * Changed include paths of amiga_api.h, amiga_libcallentry.h and amiga_raf.h
  36.  * from kern to api
  37.  * 
  38.  * Revision 1.16  93/04/26  10:54:08  10:54:08  too (Tomi Ollila)
  39.  * Added CHECK_TASK2().
  40.  * Removed setting of errno when task checking fails
  41.  * 
  42.  * Revision 1.15  93/04/06  17:57:28  17:57:28  too (Tomi Ollila)
  43.  * Changed FIndTask(NULL):s to SysBase->ThisTask
  44.  * 
  45.  * Revision 1.14  93/03/30  16:51:52  16:51:52  too (Tomi Ollila)
  46.  * Fixed API_entry etc macros. added prototype for writeErrnoValue().
  47.  * moved fdAlloc here from amiga_generic.c
  48.  * 
  49.  * Revision 1.13  93/03/15  14:35:08  14:35:08  jraja (Jarno Tapio Rajahalme)
  50.  * Changed little wrongTaskErrorFmt's declaration.
  51.  * (To make it compile with SASC).
  52.  * 
  53.  * Revision 1.12  93/03/14  16:06:22  16:06:22  too (Tomi Ollila)
  54.  * Moved declaration of wrongTaskErrorFrm from here to amiga_api.c
  55.  * 
  56.  * Revision 1.11  93/03/13  14:01:12  14:01:12  too (Tomi Ollila)
  57.  * Added macros CHSCK_TASK and API_STDRETURN to replace macros
  58.  * API_ENTRY and API_EXIT, which are left untill all uses are removed.
  59.  * 
  60.  * Revision 1.10  93/03/12  00:59:54  00:59:54  too (Tomi Ollila)
  61.  * Changed errno to errnoPtr, so user can set it anywhere wanted
  62.  * 
  63.  * Revision 1.9  93/03/04  09:43:20  09:43:20  jraja (Jarno Tapio Rajahalme)
  64.  * Fixed includes.
  65.  * 
  66.  * Revision 1.8  93/03/02  16:55:16  16:55:16  ppessi (Pekka Pessi)
  67.  * af.h
  68.  * 
  69.  * Revision 1.1  93/02/28  22:39:30  22:39:30  ppessi (Pekka Pessi)
  70.  *     Separated RAF macros to amiga_raf.h
  71.  * 
  72.  * Revision 1.7  93/02/26  13:22:41  13:22:41  too (Tomi Ollila)
  73.  * code checked w/ too, ppessi and jraja
  74.  * 
  75.  * Revision 1.6  93/02/25  16:46:59  16:46:59  too (Tomi Ollila)
  76.  * Added #include <sys/errno.h>
  77.  * 
  78.  * Revision 1.5  93/02/25  13:01:58  13:01:58  too (Tomi Ollila)
  79.  * Added static inlines, sys/cdefs etc.
  80.  * 
  81.  * Revision 1.4  93/02/24  10:57:08  10:57:08  too (Tomi Ollila)
  82.  * some getSock discussion added.
  83.  * 
  84.  * Revision 1.3  93/02/17  14:40:18  14:40:18  too (Tomi Ollila)
  85.  * Added RAFs to make libcall writing easier and more readable.
  86.  * 
  87.  * Revision 1.2  93/02/16  16:01:12  16:01:12  too (Tomi Ollila)
  88.  * fixed semaphore and SetTaskPri (forbid/permit removed)
  89.  * 
  90.  * Revision 1.1  93/02/16  15:39:57  15:39:57  too (Tomi Ollila)
  91.  * Initial revision
  92.  * 
  93.  * 
  94.  */
  95.  
  96. #ifndef AMIGA_LIBCALLENTRY_H
  97. #define AMIGA_LIBCALLENTRY_H
  98.  
  99. #ifndef AMIGA_API_H
  100. #error include amiga_api.h before this (libcallentry.h)
  101. #endif
  102.  
  103. #ifndef SYS_CDEFS_H
  104. #include <sys/cdefs.h>
  105. #endif
  106.  
  107. #ifndef SYS_ERRNO_H
  108. #include <sys/errno.h>
  109. #endif
  110.  
  111. #ifndef SYS_SYSLOG_H
  112. #include <sys/syslog.h>
  113. #endif
  114.  
  115. /*
  116.  * The following macros are written in each socket library functions
  117.  * (execpt Errno()). they makes sure that the task that calls library
  118.  * functions is the opener task of the socketbase it is using.
  119.  */
  120.  
  121. extern const char wrongTaskErrorFmt[];
  122.  
  123. #define CHECK_TASK()                    \
  124.   if (libPtr->thisTask != SysBase->ThisTask) {        \
  125.     struct Task * wTask = SysBase->ThisTask;        \
  126.     log(LOG_CRIT, wrongTaskErrorFmt, wTask,        \
  127.     wTask->tc_Node.ln_Name,    libPtr->thisTask,    \
  128.     libPtr->thisTask->tc_Node.ln_Name);        \
  129.     return -1;                        \
  130.   }      
  131.  
  132. #define CHECK_TASK_NULL()                \
  133.   if (libPtr->thisTask != SysBase->ThisTask) {        \
  134.     struct Task * wTask = SysBase->ThisTask;        \
  135.     log(LOG_CRIT, wrongTaskErrorFmt, wTask,        \
  136.     wTask->tc_Node.ln_Name,    libPtr->thisTask,    \
  137.     libPtr->thisTask->tc_Node.ln_Name);        \
  138.     return NULL;                    \
  139.   }      
  140.  
  141. #define CHECK_TASK2() CHECK_TASK_NULL()
  142.  
  143. #define CHECK_TASK_VOID()                \
  144.   if (libPtr->thisTask != SysBase->ThisTask) {        \
  145.     struct Task * wTask = SysBase->ThisTask;        \
  146.     log(LOG_CRIT, wrongTaskErrorFmt, wTask,        \
  147.     wTask->tc_Node.ln_Name,    libPtr->thisTask,    \
  148.     libPtr->thisTask->tc_Node.ln_Name);        \
  149.     return;                        \
  150.   }      
  151.  
  152. #define API_STD_RETURN(error, ret)    \
  153.   if (error == 0)            \
  154.     return ret;                \
  155.   writeErrnoValue(libPtr, error);    \
  156.   return -1;
  157.                         
  158. /*
  159.  * getSock() gets a socket referenced by given filedescriptor if exists,
  160.  * returns EBADF (bad file descriptor) if not. (because this now uses
  161.  * struct socket * pointer and those are often register variables, perhaps
  162.  * some kind of change is to be done here).
  163.  */
  164.  
  165. static inline LONG getSock(struct SocketBase *p, int fd, struct socket **sop)
  166. {
  167.   register struct socket *so;
  168.   
  169.   if ((unsigned)fd >= p->dTableSize || (so = p->dTable[(short)fd]) == NULL)
  170.     return (EBADF);
  171.   *sop = so;
  172.   return 0;
  173. }
  174.  
  175. /*
  176.  * Prototype for sdFind. This is located in amiga_syscalls.c and replaces
  177.  * fdAlloc there. libPtr->nextDToSearch is dumped.
  178.  */
  179. LONG sdFind(struct SocketBase * libPtr, LONG *fdp);
  180.  
  181. #ifndef AMIGA_RAF_H
  182. #include <api/amiga_raf.h>
  183. #endif
  184.  
  185. #endif /* !AMIGA_LIBCALLENTRY_H */
  186.