raw: Extract sock_list in a file
[swifty.git] / src / raw / swift_list.h
1 #ifndef __SOCK_LIST
2
3 #define __SOCK_LIST
4
5 enum sock_rw_state {
6         STATE_NO_SHUT,
7         STATE_SHUT_RD,
8         STATE_SHUT_WR,
9         STATE_SHUT_RDWR
10 };
11
12 enum sock_bind_state {
13         STATE_NOTBOUND,
14         STATE_BOUND
15 };
16
17 /* socket management structure */
18 struct sock_list {
19         int s;
20         struct sockaddr_sw addr;
21         enum sock_rw_state rw_state;
22         enum sock_bind_state bind_state;
23         struct sock_list *next;
24         struct sock_list *prev;
25 };
26
27 static struct sock_list sock_list_head = {
28         .next = &sock_list_head,
29         .prev = &sock_list_head
30 };
31
32 /*
33  * Add new socket to list. Called by sw_socket "syscall".
34  */
35 struct sock_list *list_add_socket(int s);
36
37 /*
38  * Bind socket to given address. Called by sw_bind "syscall".
39  */
40
41 struct sock_list *list_update_socket_address(int s, __CONST_SOCKADDR_ARG addr);
42
43 /*
44  * Get list element containing socket s. Called by sw_send* "syscalls".
45  */
46
47 struct sock_list *list_elem_from_socket(int s);
48
49 /*
50  * Get list element containing address addr. Called by sw_bind "syscall".
51  */
52
53 struct sock_list *list_elem_from_address(__CONST_SOCKADDR_ARG addr);
54
55 /*
56  * Remove socket from list. Called by sw_close "syscall".
57  */
58
59 int list_remove_socket(int s);
60
61 /*
62  * Check if a socket is bound.
63  */
64 int list_socket_is_bound(int s);
65
66 #endif