revert between 56095 -> 55830 in arch
[AROS.git] / workbench / network / stacks / AROSTCP / bsdsocket / api / amiga_api.h
blob1fc92dd2258aeb6c85c31ee8ae6d395d122eb10c
1 /*
2 * Copyright (C) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
3 * Helsinki University of Technology, Finland.
4 * All rights reserved.
5 * Copyright (C) 2005 - 2007 The AROS Dev Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19 * MA 02111-1307, USA.
23 #ifndef AMIGA_API_H
24 #define AMIGA_API_H
26 #ifndef EXEC_TYPES_H
27 #error <exec/types.h> not included.
28 #endif
30 #ifndef EXEC_LIBRARIES_H
31 #error <exec/libraries.h> not included.
32 #endif
34 #ifndef EXEC_SEMAPHORES_H
35 #error <exec/semaphores.h> not included.
36 #endif
38 #ifndef EXEC_TASKS_H
39 #include <exec/tasks.h>
40 #endif
42 #ifndef SYS_CDEFS_H
43 #include <sys/cdefs.h>
44 #endif
46 #ifndef SYS_TYPES_H
47 #include <sys/types.h>
48 #endif
50 #ifndef SYS_QUEUE_H
51 #include "sys/queue2.h"
52 #endif
54 #ifndef API_RESOLV_H
55 #include <api/resolv.h>
56 #endif
58 #include <proto/exec.h>
59 #include <kern/amiga_config.h>
61 enum apistate {
62 API_SCRATCH, /* api not initialized */
63 API_INITIALIZED, /* librarybase created */
64 API_SHOWN, /* librarybase made visible */
65 API_HIDDEN, /* librarybase hidden */
66 API_FUNCTIONPATCHED /* Api functions set to return -1 */
68 extern enum apistate api_state;
70 #ifdef __MORPHOS__
71 #pragma pack(2)
72 #endif
74 struct LibInitTable {
75 UBYTE byte1; UBYTE offset1; UBYTE ln_type; UBYTE pad0;
76 UBYTE byte2; UBYTE offset2; UBYTE lib_flags; UBYTE pad1;
77 UBYTE long3; UBYTE offset3; ULONG ln_Name;
78 UBYTE word4; UBYTE offset4; UWORD lib_Version;
79 UBYTE word5; UBYTE offset5; UWORD lib_Revision;
80 UBYTE long6; UBYTE offset6; ULONG lib_IdString;
81 UBYTE end7;
84 #ifdef __MORPHOS__
85 #pragma pack()
86 #endif
88 extern struct LibInitTable Miami_initTable;
89 extern struct Library *MasterMiamiBase;
91 struct newselbuf;
94 * structure for holding size and address of some dynamically allocated buffers
95 * such as selitems for WaitSelect() and netdatabase entry structures
97 struct DataBuffer {
98 int db_Size;
99 void * db_Addr;
102 typedef int (* ASM fdCallback_t)(REG(d0, int fd), REG(d1, int action));
104 struct SocketBase {
105 struct Library libNode;
106 /* -- "Global" Errno -- */
107 BYTE flags;
108 BYTE errnoSize; /* 1, 2 or 4 */
109 /* -- now we are longword aligned -- */
110 UBYTE * errnoPtr; /* this points to errno */
111 LONG defErrno;
112 /* Task pointer of owner task */
113 struct Task * thisTask;
114 /* task priority changes (WORDS so we keep structure longword aligned) */
115 BYTE myPri; /* task's priority just after libcall */
116 BYTE libCallPri; /* task's priority during library call */
117 /* note: not long word aligned at this point */
118 /* -- descriptor sets -- */
119 WORD dTableSize; /* long word aligned again */
120 struct socket ** dTable;
121 fdCallback_t fdCallback;
122 /* AmiTCP signal masks */
123 ULONG sigIntrMask;
124 ULONG sigIOMask;
125 ULONG sigUrgMask;
126 ULONG sigEventMask;
127 /* -- these are used by tsleep()/wakeup() -- */
128 const char * p_wmesg;
129 queue_chain_t p_sleep_link;
130 caddr_t p_wchan; /* event process is awaiting */
131 struct timerequest * tsleep_timer;
132 struct MsgPort * timerPort;
133 /* -- pointer to select buffer during Select() -- */
134 struct newselbuf * p_sb;
135 /* -- per process fields used by various 'library' functions -- */
136 /* buffer for inet_ntoa */
137 char inet_ntoa[20]; /* xxx.xxx.xxx.xxx\0 */
138 /* -- pointers for data buffers that MAY be used -- */
139 struct DataBuffer selitems;
140 struct DataBuffer hostents;
141 struct DataBuffer netents;
142 struct DataBuffer protoents;
143 struct DataBuffer servents;
144 /* -- variables for the syslog (see netinclude:sys/syslog.h) -- */
145 UBYTE LogStat; /* status */
146 UBYTE LogMask; /* mask for log events */
147 UWORD LogFacility; /* facility code */
148 const char * LogTag; /* tag string for the log events */
149 /* -- resolver variables -- */
150 LONG * hErrnoPtr;
151 LONG defHErrno;
152 LONG res_socket; /* socket used for resolver comm. */
153 struct state res_state;
154 /* -- socket events -- */
155 struct SignalSemaphore EventLock;
156 struct MinList EventList;
157 /* -- buffer for string returns -- */
158 UBYTE result_str[REPLYBUFLEN + 1];
159 /* -- NetDB pointers for getXXXent() and friends -- */
160 struct HostentNode *HostentNode;
161 struct ProtoentNode *ProtoentNode;
165 * Socket base flags
167 #define SBFB_COMPAT43 0L /* compat 43 code (without sockaddr_len) */
169 #define SBFF_COMPAT43 1L
172 * macro for getting error value pointed by the library base. All but
173 * the lowest byte of the errno are assumed to stay zero.
175 int readErrnoValue(struct SocketBase *);
177 extern struct SignalSemaphore syscall_semaphore;
178 extern struct List releasedSocketList;
181 * Functions to put and remove application library to/from exec library list
183 BOOL api_init(VOID);
184 BOOL api_show(VOID);
185 VOID api_hide(VOID);
186 VOID api_setfunctions(VOID);
187 VOID api_sendbreaktotasks(VOID);
188 VOID api_deinit(VOID);
190 /* Function which sets Errno value */
192 VOID writeErrnoValue(struct SocketBase *, int);
195 * inline functions which changes (raises) task priority while it is
196 * executing library functions
199 static inline void ObtainSyscallSemaphore(struct SocketBase *libPtr)
201 extern struct Task *AROSTCP_Task;
203 ObtainSemaphore(&syscall_semaphore);
204 libPtr->myPri = SetTaskPri(libPtr->thisTask,
205 libPtr->libCallPri = AROSTCP_Task->tc_Node.ln_Pri);
208 static inline void ReleaseSyscallSemaphore(struct SocketBase *libPtr)
210 if (libPtr->libCallPri != (libPtr->myPri = SetTaskPri(libPtr->thisTask,
211 libPtr->myPri)))
212 SetTaskPri(libPtr->thisTask, libPtr->myPri);
213 ReleaseSemaphore(&syscall_semaphore);
217 * inline function for searching library base when taskpointer is known
220 static inline struct SocketBase *FindSocketBase(struct Task *task)
222 extern struct List socketBaseList;
223 struct Node *libNode;
225 Forbid();
226 for (libNode = socketBaseList.lh_Head; libNode->ln_Succ;
227 libNode = libNode->ln_Succ)
228 if (((struct SocketBase *)libNode)->thisTask == task) {
229 Permit();
230 return (struct SocketBase *)libNode;
232 /* here if Task wasn't in socketBaseList */
233 Permit();
234 return NULL;
237 #endif /* !AMIGA_API_H */