2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
9 #include "bsdsocket_intern.h"
10 #include "bsdsocket_util.h"
12 void SetError(int error
, struct TaskBase
*libPtr
)
14 switch (libPtr
->errnoSize
)
17 *(UQUAD
*)libPtr
->errnoPtr
= (UQUAD
)error
;
21 *(ULONG
*)libPtr
->errnoPtr
= (ULONG
)error
;
25 *(UWORD
*)libPtr
->errnoPtr
= (UWORD
)error
;
29 *(UBYTE
*)libPtr
->errnoPtr
= (UBYTE
)error
;
33 D(bug("[SetErrno] Bogus errno size %u for TaskBase 0x%p\n", libPtr
->errnoSize
, libPtr
));
38 ULONG
SetDTableSize(ULONG size
, struct TaskBase
*taskBase
)
40 struct Socket
**old
= taskBase
->dTable
;
41 struct Socket
**table
;
42 ULONG oldsize
= taskBase
->dTableSize
* sizeof(struct Socket
*);
43 ULONG newsize
= size
* sizeof(struct Socket
*);
46 /* FIXME: just a temporary measure */
47 if (size
< taskBase
->dTableSize
)
50 table
= AllocPooled(taskBase
->pool
, newsize
);
55 memset(table
, 0, newsize
);
58 CopyMem(old
, table
, oldsize
);
60 taskBase
->dTable
= table
;
61 taskBase
->dTableSize
= size
;
64 FreePooled(taskBase
->pool
, old
, oldsize
);
69 int GetFreeFD(struct TaskBase
*taskBase
)
73 for (i
= 0; i
< taskBase
->dTableSize
; i
++)
75 if (!taskBase
->dTable
[i
])
79 SetError(EMFILE
, taskBase
);
83 struct Socket
*GetSocket(int s
, struct TaskBase
*taskBase
)
87 if (s
>= taskBase
->dTableSize
)
89 SetError(ENOTSOCK
, taskBase
);
93 sd
= taskBase
->dTable
[s
];
95 SetError(ENOTSOCK
, taskBase
);
100 struct WSsockaddr
*MakeSockAddr(const struct sockaddr
*src
, int len
, struct TaskBase
*taskBase
)
102 struct WSsockaddr
*sa
= AllocPooled(taskBase
->pool
, len
);
106 CopyMem(src
, sa
, len
);
107 sa
->sa_family
= src
->sa_family
;
110 SetError(ENOMEM
, taskBase
);