2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
6 #include <aros/asmcall.h>
7 #include <aros/symbolsets.h>
8 #include <proto/exec.h>
10 #include "bsdsocket_intern.h"
11 #include "bsdsocket_util.h"
13 extern APTR BSDSocket_FuncTable
[];
15 static AROS_UFH2(LONG
, TaskKeyCompare
,
16 AROS_UFHA(const struct AVLNode
*, td
, A0
),
17 AROS_UFHA(AVLKey
, key
, A1
))
21 AVLKey id
= ((struct TaskNode
*)td
)->task
;
33 static AROS_UFH2(LONG
, TaskNodeCompare
,
34 AROS_UFHA(const struct AVLNode
*, td1
, A0
),
35 AROS_UFHA(const struct AVLNode
*, td2
, A1
))
39 IPTR t1
= (IPTR
)((struct TaskNode
*)td1
)->task
;
40 IPTR t2
= (IPTR
)((struct TaskNode
*)td2
)->task
;
52 AROS_LH1(struct TaskBase
*, BSDSocket_OpenLib
,
53 AROS_LHA (ULONG
, version
, D0
),
54 struct bsdsocketBase
*, SocketBase
, 1, BSDSocket
)
59 struct Task
*task
= FindTask(NULL
);
60 struct TaskNode
*tn
= (struct TaskNode
*)AVL_FindNode(SocketBase
->tasks
, task
, TaskKeyCompare
);
62 D(bug("[OpenLib] Task 0x%p\n", task
));
65 D(bug("[OpenLib] Found TaskBase 0x%p\n", tb
));
67 APTR pool
= CreatePool(MEMF_ANY
, 2048, 1024);
69 D(bug("[OpenLib] Created pool 0x%p\n", pool
));
73 tb
= (struct TaskBase
*)MakeLibrary(BSDSocket_FuncTable
, NULL
, NULL
, sizeof(struct TaskBase
), NULL
);
74 D(bug("[OpenLib] Created TaskBase 0x%p\n", tb
));
81 tb
->lib
.lib_Node
.ln_Name
= SocketBase
->lib
.lib_Node
.ln_Name
;
82 tb
->lib
.lib_Node
.ln_Type
= NT_LIBRARY
;
83 tb
->lib
.lib_Node
.ln_Pri
= SocketBase
->lib
.lib_Node
.ln_Pri
;
84 tb
->lib
.lib_Flags
= LIBF_CHANGED
;
85 tb
->lib
.lib_Version
= SocketBase
->lib
.lib_Version
;
86 tb
->lib
.lib_Revision
= SocketBase
->lib
.lib_Revision
;
87 tb
->lib
.lib_IdString
= SocketBase
->lib
.lib_IdString
;
93 tb
->glob
= SocketBase
;
95 tb
->errnoPtr
= &tb
->errnoVal
;
96 tb
->errnoSize
= sizeof(tb
->errnoVal
);
97 tb
->sigintr
= SIGBREAKF_CTRL_C
;
99 SetDTableSize(FD_SETSIZE
, tb
);
101 AVL_AddNode(&SocketBase
->tasks
, &tb
->n
.node
, TaskNodeCompare
);
106 tb
->lib
.lib_OpenCnt
++;
107 SocketBase
->lib
.lib_OpenCnt
++;
108 D(bug("[socket] Task open count %u, global open count %u\n", tb
->lib
.lib_OpenCnt
, SocketBase
->lib
.lib_OpenCnt
));
116 AROS_LH0(BPTR
, BSDSocket_CloseLib
,
117 struct TaskBase
*, tb
, 2, BSDSocket
)
121 struct bsdsocketBase
*SocketBase
= tb
->glob
;
123 D(bug("[CloseLib] TaskBase 0x%p\n", tb
));
125 tb
->lib
.lib_OpenCnt
--;
126 SocketBase
->lib
.lib_OpenCnt
--;
127 D(bug("[CloseLib] Task open count %u, global open count %u\n", tb
->lib
.lib_OpenCnt
, SocketBase
->lib
.lib_OpenCnt
));
129 if (!tb
->lib
.lib_OpenCnt
)
134 D(bug("[CloseLib] dTableSize is %u\n", tb
->dTableSize
));
135 for (i
= 0; i
< tb
->dTableSize
; i
++)
136 IntCloseSocket(i
, tb
);
138 AVL_RemNodeByAddress(&SocketBase
->tasks
, &tb
->n
.node
);
140 DeletePool(tb
->pool
);
142 addr
= (APTR
)tb
- tb
->lib
.lib_NegSize
;
143 FreeMem(addr
, tb
->lib
.lib_NegSize
+ tb
->lib
.lib_PosSize
);
146 if (SocketBase
->lib
.lib_OpenCnt
)
149 if (SocketBase
->lib
.lib_Flags
& LIBF_DELEXP
)
150 return AROS_LC1(BPTR
, BSDSocket_ExpungeLib
,
151 AROS_LCA(struct bsdsocketBase
*, SocketBase
, D0
),
152 struct bsdsocketBase
*, SocketBase
, 3, BSDSocket
);