root / lab4 / .minix-src / include / minix / sockevent.h @ 13
History | View | Annotate | Download (5.57 KB)
1 |
#ifndef _MINIX_SOCKEVENT_H
|
---|---|
2 |
#define _MINIX_SOCKEVENT_H
|
3 |
|
4 |
#include <minix/sockdriver.h> |
5 |
|
6 |
/* Socket events. */
|
7 |
#define SEV_BIND 0x01 /* a pending bind operation has ended */ |
8 |
#define SEV_CONNECT 0x02 /* a pending connect operation has ended */ |
9 |
#define SEV_ACCEPT 0x04 /* pending accept operations may be resumed */ |
10 |
#define SEV_SEND 0x08 /* pending send operations may be resumed */ |
11 |
#define SEV_RECV 0x10 /* pending receive operations may be resumed */ |
12 |
#define SEV_CLOSE 0x20 /* a pending close operation has ended */ |
13 |
|
14 |
/* Socket flags. */
|
15 |
#define SFL_SHUT_RD 0x01 /* socket has been shut down for reading */ |
16 |
#define SFL_SHUT_WR 0x02 /* socket has been shut down for writing */ |
17 |
#define SFL_CLOSING 0x04 /* socket close operation in progress */ |
18 |
#define SFL_CLONED 0x08 /* socket has been cloned but not accepted */ |
19 |
#define SFL_TIMER 0x10 /* socket is on list of timers */ |
20 |
|
21 |
/*
|
22 |
* Special return value from sop_recv callback functions. This pseudo-value
|
23 |
* is used to differentiate between zero-sized packets and actual EOF.
|
24 |
*/
|
25 |
#define SOCKEVENT_EOF 1 |
26 |
|
27 |
struct sockevent_ops;
|
28 |
struct sockevent_proc;
|
29 |
|
30 |
/* Socket structure. None of its fields must ever be accessed directly. */
|
31 |
struct sock {
|
32 |
sockid_t sock_id; /* socket identifier */
|
33 |
unsigned char sock_events; /* pending events (SEV_) */ |
34 |
unsigned char sock_flags; /* internal flags (SFL_) */ |
35 |
unsigned char sock_domain; /* domain, address family (PF_, AF_) */ |
36 |
int sock_type; /* type: stream, datagram.. (SOCK_) */ |
37 |
int sock_err; /* pending error code < 0, 0 if none */ |
38 |
unsigned int sock_opt; /* generic option flags (SO_) */ |
39 |
clock_t sock_linger; /* SO_LINGER value, in ticks or time */
|
40 |
clock_t sock_stimeo; /* SO_SNDTIMEO value, in clock ticks */
|
41 |
clock_t sock_rtimeo; /* SO_RCVTIMEO value, in clock ticks */
|
42 |
size_t sock_slowat; /* SO_SNDLOWAT value, in bytes */
|
43 |
size_t sock_rlowat; /* SO_RCVLOWAT value, in bytes */
|
44 |
const struct sockevent_ops *sock_ops; /* socket operations table */ |
45 |
SIMPLEQ_ENTRY(sock) sock_next; /* list for pending events */
|
46 |
SLIST_ENTRY(sock) sock_hash; /* list for hash table */
|
47 |
SLIST_ENTRY(sock) sock_timer; /* list of socks with timers */
|
48 |
struct sockevent_proc *sock_proc; /* list of suspended calls */ |
49 |
struct sockdriver_select sock_select; /* pending select query */ |
50 |
unsigned int sock_selops; /* pending select operations, or 0 */ |
51 |
}; |
52 |
|
53 |
/* Socket operations table. */
|
54 |
struct sockevent_ops {
|
55 |
int (* sop_pair)(struct sock * sock1, struct sock * sock2, |
56 |
endpoint_t user_endpt); |
57 |
int (* sop_bind)(struct sock * sock, const struct sockaddr * addr, |
58 |
socklen_t addr_len, endpoint_t user_endpt); |
59 |
int (* sop_connect)(struct sock * sock, const struct sockaddr * addr, |
60 |
socklen_t addr_len, endpoint_t user_endpt); |
61 |
int (* sop_listen)(struct sock * sock, int backlog); |
62 |
sockid_t (* sop_accept)(struct sock * sock, struct sockaddr * addr, |
63 |
socklen_t * addr_len, endpoint_t user_endpt, |
64 |
struct sock ** newsockp);
|
65 |
int (* sop_test_accept)(struct sock * sock); |
66 |
int (* sop_pre_send)(struct sock * sock, size_t len, socklen_t ctl_len, |
67 |
const struct sockaddr * addr, socklen_t addr_len, |
68 |
endpoint_t user_endpt, int flags);
|
69 |
int (* sop_send)(struct sock * sock, |
70 |
const struct sockdriver_data * data, size_t len, size_t * off, |
71 |
const struct sockdriver_data * ctl, socklen_t ctl_len, |
72 |
socklen_t * ctl_off, const struct sockaddr * addr, |
73 |
socklen_t addr_len, endpoint_t user_endpt, int flags, size_t min);
|
74 |
int (* sop_test_send)(struct sock * sock, size_t min); |
75 |
int (* sop_pre_recv)(struct sock * sock, endpoint_t user_endpt, |
76 |
int flags);
|
77 |
int (* sop_recv)(struct sock * sock, |
78 |
const struct sockdriver_data * data, size_t len, size_t * off, |
79 |
const struct sockdriver_data * ctl, socklen_t ctl_len, |
80 |
socklen_t * ctl_off, struct sockaddr * addr, socklen_t * addr_len,
|
81 |
endpoint_t user_endpt, int flags, size_t min, int * rflags); |
82 |
int (* sop_test_recv)(struct sock * sock, size_t min, size_t * size); |
83 |
int (* sop_ioctl)(struct sock * sock, unsigned long request, |
84 |
const struct sockdriver_data * data, endpoint_t user_endpt); |
85 |
void (* sop_setsockmask)(struct sock * sock, unsigned int mask); |
86 |
int (* sop_setsockopt)(struct sock * sock, int level, int name, |
87 |
const struct sockdriver_data * data, socklen_t len); |
88 |
int (* sop_getsockopt)(struct sock * sock, int level, int name, |
89 |
const struct sockdriver_data * data, socklen_t * len); |
90 |
int (* sop_getsockname)(struct sock * sock, struct sockaddr * addr, |
91 |
socklen_t * addr_len); |
92 |
int (* sop_getpeername)(struct sock * sock, struct sockaddr * addr, |
93 |
socklen_t * addr_len); |
94 |
int (* sop_shutdown)(struct sock * sock, unsigned int flags); |
95 |
int (* sop_close)(struct sock * sock, int force); |
96 |
void (* sop_free)(struct sock * sock); |
97 |
}; |
98 |
|
99 |
typedef sockid_t (* sockevent_socket_cb_t)(int domain, int type, int protocol, |
100 |
endpoint_t user_endpt, struct sock ** sock,
|
101 |
const struct sockevent_ops ** ops); |
102 |
|
103 |
void sockevent_init(sockevent_socket_cb_t socket_cb);
|
104 |
void sockevent_process(const message * m_ptr, int ipc_status); |
105 |
|
106 |
void sockevent_clone(struct sock * sock, struct sock * newsock, |
107 |
sockid_t newid); |
108 |
|
109 |
void sockevent_raise(struct sock * sock, unsigned int mask); |
110 |
void sockevent_set_error(struct sock * sock, int err); |
111 |
void sockevent_set_shutdown(struct sock * sock, unsigned int flags); |
112 |
|
113 |
#define sockevent_get_domain(sock) ((int)((sock)->sock_domain)) |
114 |
#define sockevent_get_type(sock) ((sock)->sock_type)
|
115 |
#define sockevent_get_opt(sock) ((sock)->sock_opt)
|
116 |
#define sockevent_is_listening(sock) (!!((sock)->sock_opt & SO_ACCEPTCONN))
|
117 |
#define sockevent_is_shutdown(sock, mask) ((sock)->sock_flags & (mask))
|
118 |
#define sockevent_is_closing(sock) (!!((sock)->sock_flags & SFL_CLOSING))
|
119 |
|
120 |
#endif /* !_MINIX_SOCKEVENT_H */ |