This source file includes following definitions.
- soo_read
- soo_write
- soo_ioctl
- soo_poll
- soo_stat
- soo_close
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/file.h>
38 #include <sys/proc.h>
39 #include <sys/mbuf.h>
40 #include <sys/protosw.h>
41 #include <sys/socket.h>
42 #include <sys/socketvar.h>
43 #include <sys/ioctl.h>
44 #include <sys/poll.h>
45 #include <sys/stat.h>
46
47 #include <net/if.h>
48 #include <net/route.h>
49
50 struct fileops socketops = {
51 soo_read, soo_write, soo_ioctl, soo_poll, soo_kqfilter,
52 soo_stat, soo_close
53 };
54
55
56 int
57 soo_read(struct file *fp, off_t *poff, struct uio *uio, struct ucred *cred)
58 {
59
60 return (soreceive((struct socket *)fp->f_data, (struct mbuf **)0,
61 uio, (struct mbuf **)0, (struct mbuf **)0, (int *)0));
62 }
63
64
65 int
66 soo_write(struct file *fp, off_t *poff, struct uio *uio, struct ucred *cred)
67 {
68
69 return (sosend((struct socket *)fp->f_data, (struct mbuf *)0,
70 uio, (struct mbuf *)0, (struct mbuf *)0, 0));
71 }
72
73 int
74 soo_ioctl(struct file *fp, u_long cmd, caddr_t data, struct proc *p)
75 {
76 struct socket *so = (struct socket *)fp->f_data;
77
78 switch (cmd) {
79
80 case FIONBIO:
81 if (*(int *)data)
82 so->so_state |= SS_NBIO;
83 else
84 so->so_state &= ~SS_NBIO;
85 return (0);
86
87 case FIOASYNC:
88 if (*(int *)data) {
89 so->so_state |= SS_ASYNC;
90 so->so_rcv.sb_flags |= SB_ASYNC;
91 so->so_snd.sb_flags |= SB_ASYNC;
92 } else {
93 so->so_state &= ~SS_ASYNC;
94 so->so_rcv.sb_flags &= ~SB_ASYNC;
95 so->so_snd.sb_flags &= ~SB_ASYNC;
96 }
97 return (0);
98
99 case FIONREAD:
100 *(int *)data = so->so_rcv.sb_datacc;
101 return (0);
102
103 case SIOCSPGRP:
104 so->so_pgid = *(int *)data;
105 so->so_siguid = p->p_cred->p_ruid;
106 so->so_sigeuid = p->p_ucred->cr_uid;
107 return (0);
108
109 case SIOCGPGRP:
110 *(int *)data = so->so_pgid;
111 return (0);
112
113 case SIOCATMARK:
114 *(int *)data = (so->so_state&SS_RCVATMARK) != 0;
115 return (0);
116 }
117
118
119
120
121
122 if (IOCGROUP(cmd) == 'i')
123 return (ifioctl(so, cmd, data, p));
124 if (IOCGROUP(cmd) == 'r')
125 return (rtioctl(cmd, data, p));
126 return ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL,
127 (struct mbuf *)cmd, (struct mbuf *)data, (struct mbuf *)0));
128 }
129
130 int
131 soo_poll(struct file *fp, int events, struct proc *p)
132 {
133 struct socket *so = (struct socket *)fp->f_data;
134 int revents = 0;
135 int s = splsoftnet();
136
137 if (events & (POLLIN | POLLRDNORM)) {
138 if (soreadable(so))
139 revents |= events & (POLLIN | POLLRDNORM);
140 }
141 if (events & (POLLOUT | POLLWRNORM)) {
142 if (sowriteable(so))
143 revents |= events & (POLLOUT | POLLWRNORM);
144 }
145 if (events & (POLLPRI | POLLRDBAND)) {
146 if (so->so_oobmark || (so->so_state & SS_RCVATMARK))
147 revents |= events & (POLLPRI | POLLRDBAND);
148 }
149 if (revents == 0) {
150 if (events & (POLLIN | POLLPRI | POLLRDNORM | POLLRDBAND)) {
151 selrecord(p, &so->so_rcv.sb_sel);
152 so->so_rcv.sb_flags |= SB_SEL;
153 }
154 if (events & (POLLOUT | POLLWRNORM)) {
155 selrecord(p, &so->so_snd.sb_sel);
156 so->so_snd.sb_flags |= SB_SEL;
157 }
158 }
159 splx(s);
160 return (revents);
161 }
162
163 int
164 soo_stat(struct file *fp, struct stat *ub, struct proc *p)
165 {
166 struct socket *so = (struct socket *)fp->f_data;
167
168 bzero((caddr_t)ub, sizeof (*ub));
169 ub->st_mode = S_IFSOCK;
170 return ((*so->so_proto->pr_usrreq)(so, PRU_SENSE,
171 (struct mbuf *)ub, (struct mbuf *)0,
172 (struct mbuf *)0));
173 }
174
175
176 int
177 soo_close(struct file *fp, struct proc *p)
178 {
179 int error = 0;
180
181 if (fp->f_data)
182 error = soclose((struct socket *)fp->f_data);
183 fp->f_data = 0;
184 return (error);
185 }