sys_socket.c (271976) | sys_socket.c (274421) |
---|---|
1/*- 2 * Copyright (c) 1982, 1986, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 16 unchanged lines hidden (view full) --- 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)sys_socket.c 8.1 (Berkeley) 6/10/93 30 */ 31 32#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1982, 1986, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 16 unchanged lines hidden (view full) --- 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)sys_socket.c 8.1 (Berkeley) 6/10/93 30 */ 31 32#include <sys/cdefs.h> |
33__FBSDID("$FreeBSD: head/sys/kern/sys_socket.c 271976 2014-09-22 16:20:47Z jhb $"); | 33__FBSDID("$FreeBSD: head/sys/kern/sys_socket.c 274421 2014-11-12 09:57:15Z glebius $"); |
34 35#include <sys/param.h> 36#include <sys/systm.h> 37#include <sys/domain.h> 38#include <sys/file.h> 39#include <sys/filedesc.h> 40#include <sys/malloc.h> 41#include <sys/proc.h> --- 128 unchanged lines hidden (view full) --- 170 SOCKBUF_LOCK(&so->so_snd); 171 so->so_snd.sb_flags &= ~SB_ASYNC; 172 SOCKBUF_UNLOCK(&so->so_snd); 173 } 174 break; 175 176 case FIONREAD: 177 /* Unlocked read. */ | 34 35#include <sys/param.h> 36#include <sys/systm.h> 37#include <sys/domain.h> 38#include <sys/file.h> 39#include <sys/filedesc.h> 40#include <sys/malloc.h> 41#include <sys/proc.h> --- 128 unchanged lines hidden (view full) --- 170 SOCKBUF_LOCK(&so->so_snd); 171 so->so_snd.sb_flags &= ~SB_ASYNC; 172 SOCKBUF_UNLOCK(&so->so_snd); 173 } 174 break; 175 176 case FIONREAD: 177 /* Unlocked read. */ |
178 *(int *)data = so->so_rcv.sb_cc; | 178 *(int *)data = sbavail(&so->so_rcv); |
179 break; 180 181 case FIONWRITE: 182 /* Unlocked read. */ | 179 break; 180 181 case FIONWRITE: 182 /* Unlocked read. */ |
183 *(int *)data = so->so_snd.sb_cc; | 183 *(int *)data = sbavail(&so->so_snd); |
184 break; 185 186 case FIONSPACE: | 184 break; 185 186 case FIONSPACE: |
187 if ((so->so_snd.sb_hiwat < so->so_snd.sb_cc) || | 187 /* Unlocked read. */ 188 if ((so->so_snd.sb_hiwat < sbused(&so->so_snd)) || |
188 (so->so_snd.sb_mbmax < so->so_snd.sb_mbcnt)) 189 *(int *)data = 0; 190 else 191 *(int *)data = sbspace(&so->so_snd); 192 break; 193 194 case FIOSETOWN: 195 error = fsetown(*(int *)data, &so->so_sigio); --- 53 unchanged lines hidden (view full) --- 249 return (sopoll(so, events, fp->f_cred, td)); 250} 251 252static int 253soo_stat(struct file *fp, struct stat *ub, struct ucred *active_cred, 254 struct thread *td) 255{ 256 struct socket *so = fp->f_data; | 189 (so->so_snd.sb_mbmax < so->so_snd.sb_mbcnt)) 190 *(int *)data = 0; 191 else 192 *(int *)data = sbspace(&so->so_snd); 193 break; 194 195 case FIOSETOWN: 196 error = fsetown(*(int *)data, &so->so_sigio); --- 53 unchanged lines hidden (view full) --- 250 return (sopoll(so, events, fp->f_cred, td)); 251} 252 253static int 254soo_stat(struct file *fp, struct stat *ub, struct ucred *active_cred, 255 struct thread *td) 256{ 257 struct socket *so = fp->f_data; |
258 struct sockbuf *sb; |
|
257#ifdef MAC 258 int error; 259#endif 260 261 bzero((caddr_t)ub, sizeof (*ub)); 262 ub->st_mode = S_IFSOCK; 263#ifdef MAC 264 error = mac_socket_check_stat(active_cred, so); 265 if (error) 266 return (error); 267#endif 268 /* 269 * If SBS_CANTRCVMORE is set, but there's still data left in the 270 * receive buffer, the socket is still readable. 271 */ | 259#ifdef MAC 260 int error; 261#endif 262 263 bzero((caddr_t)ub, sizeof (*ub)); 264 ub->st_mode = S_IFSOCK; 265#ifdef MAC 266 error = mac_socket_check_stat(active_cred, so); 267 if (error) 268 return (error); 269#endif 270 /* 271 * If SBS_CANTRCVMORE is set, but there's still data left in the 272 * receive buffer, the socket is still readable. 273 */ |
272 SOCKBUF_LOCK(&so->so_rcv); 273 if ((so->so_rcv.sb_state & SBS_CANTRCVMORE) == 0 || 274 so->so_rcv.sb_cc != 0) | 274 sb = &so->so_rcv; 275 SOCKBUF_LOCK(sb); 276 if ((sb->sb_state & SBS_CANTRCVMORE) == 0 || sbavail(sb)) |
275 ub->st_mode |= S_IRUSR | S_IRGRP | S_IROTH; | 277 ub->st_mode |= S_IRUSR | S_IRGRP | S_IROTH; |
276 ub->st_size = so->so_rcv.sb_cc - so->so_rcv.sb_ctl; 277 SOCKBUF_UNLOCK(&so->so_rcv); 278 /* Unlocked read. */ 279 if ((so->so_snd.sb_state & SBS_CANTSENDMORE) == 0) | 278 ub->st_size = sbavail(sb) - sb->sb_ctl; 279 SOCKBUF_UNLOCK(sb); 280 281 sb = &so->so_snd; 282 SOCKBUF_LOCK(sb); 283 if ((sb->sb_state & SBS_CANTSENDMORE) == 0) |
280 ub->st_mode |= S_IWUSR | S_IWGRP | S_IWOTH; | 284 ub->st_mode |= S_IWUSR | S_IWGRP | S_IWOTH; |
285 SOCKBUF_UNLOCK(sb); |
|
281 ub->st_uid = so->so_cred->cr_uid; 282 ub->st_gid = so->so_cred->cr_gid; 283 return (*so->so_proto->pr_usrreqs->pru_sense)(so, ub); 284} 285 286/* 287 * API socket close on file pointer. We call soclose() to close the socket 288 * (including initiating closing protocols). soclose() will sorele() the --- 72 unchanged lines hidden --- | 286 ub->st_uid = so->so_cred->cr_uid; 287 ub->st_gid = so->so_cred->cr_gid; 288 return (*so->so_proto->pr_usrreqs->pru_sense)(so, ub); 289} 290 291/* 292 * API socket close on file pointer. We call soclose() to close the socket 293 * (including initiating closing protocols). soclose() will sorele() the --- 72 unchanged lines hidden --- |