fix round-trip timing: rexmt timer shouldn't screw rtt up,
[unix-history] / usr / src / sys / kern / sys_socket.c
CommitLineData
94368568 1/* sys_socket.c 6.3 84/08/29 */
48aab316 2
94368568
JB
3#include "param.h"
4#include "systm.h"
5#include "dir.h"
6#include "user.h"
7#include "file.h"
8#include "mbuf.h"
9#include "protosw.h"
10#include "socket.h"
11#include "socketvar.h"
12#include "ioctl.h"
13#include "uio.h"
14#include "stat.h"
48aab316
SL
15
16#include "../net/if.h"
17#include "../net/route.h"
18
92438dfc 19int soo_rw(), soo_ioctl(), soo_select(), soo_close();
48aab316 20struct fileops socketops =
92438dfc 21 { soo_rw, soo_ioctl, soo_select, soo_close };
48aab316
SL
22
23soo_rw(fp, rw, uio)
24 struct file *fp;
25 enum uio_rw rw;
26 struct uio *uio;
27{
28 int soreceive(), sosend();
29
30 return (
31 (*(rw==UIO_READ?soreceive:sosend))
32 ((struct socket *)fp->f_data, 0, uio, 0, 0));
33}
34
35soo_ioctl(fp, cmd, data)
36 struct file *fp;
37 int cmd;
38 register caddr_t data;
39{
40 register struct socket *so = (struct socket *)fp->f_data;
41
42 switch (cmd) {
43
44 case FIONBIO:
45 if (*(int *)data)
46 so->so_state |= SS_NBIO;
47 else
48 so->so_state &= ~SS_NBIO;
1116b929 49 return (0);
48aab316
SL
50
51 case FIOASYNC:
52 if (*(int *)data)
53 so->so_state |= SS_ASYNC;
54 else
55 so->so_state &= ~SS_ASYNC;
1116b929 56 return (0);
48aab316 57
8b899dbe
SL
58 case FIONREAD:
59 *(int *)data = so->so_rcv.sb_cc;
1116b929 60 return (0);
8b899dbe 61
48aab316
SL
62 case SIOCSPGRP:
63 so->so_pgrp = *(int *)data;
1116b929 64 return (0);
48aab316
SL
65
66 case SIOCGPGRP:
67 *(int *)data = so->so_pgrp;
1116b929 68 return (0);
48aab316
SL
69
70 case SIOCATMARK:
71 *(int *)data = (so->so_state&SS_RCVATMARK) != 0;
1116b929 72 return (0);
48aab316 73 }
1116b929
SL
74 /*
75 * Interface/routing/protocol specific ioctls:
76 * interface and routing ioctls should have a
77 * different entry since a socket's unnecessary
78 */
79#define cmdbyte(x) (((x) >> 8) & 0xff)
80 if (cmdbyte(cmd) == 'i')
81 return (ifioctl(cmd, data));
82 if (cmdbyte(cmd) == 'r')
83 return (rtioctl(cmd, data));
84 return ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL,
85 (struct mbuf *)cmd, (struct mbuf *)data, (struct mbuf *)0));
48aab316
SL
86}
87
88soo_select(fp, which)
89 struct file *fp;
90 int which;
91{
92 register struct socket *so = (struct socket *)fp->f_data;
93 register int s = splnet();
94
95 switch (which) {
96
97 case FREAD:
98 if (soreadable(so)) {
99 splx(s);
100 return (1);
101 }
102 sbselqueue(&so->so_rcv);
103 break;
104
105 case FWRITE:
106 if (sowriteable(so)) {
107 splx(s);
108 return (1);
109 }
110 sbselqueue(&so->so_snd);
111 break;
112 }
113 splx(s);
114 return (0);
115}
116
502b634a 117/*ARGSUSED*/
92438dfc
SL
118soo_stat(so, ub)
119 register struct socket *so;
48aab316
SL
120 register struct stat *ub;
121{
48aab316
SL
122
123 bzero((caddr_t)ub, sizeof (*ub));
48aab316
SL
124 return ((*so->so_proto->pr_usrreq)(so, PRU_SENSE,
125 (struct mbuf *)ub, (struct mbuf *)0,
126 (struct mbuf *)0));
48aab316
SL
127}
128
129soo_close(fp)
130 struct file *fp;
131{
ec04fec2
SL
132 int error = 0;
133
134 if (fp->f_data)
135 error = soclose((struct socket *)fp->f_data);
48aab316
SL
136 fp->f_data = 0;
137 return (error);
138}