Changeset View
Changeset View
Standalone View
Standalone View
head/sys/kern/kern_sendfile.c
Show First 20 Lines • Show All 501 Lines • ▼ Show 20 Lines | sendfile_getsock(struct thread *td, int s, struct file **sock_fp, | ||||
*/ | */ | ||||
error = getsock_cap(td, s, cap_rights_init(&rights, CAP_SEND), | error = getsock_cap(td, s, cap_rights_init(&rights, CAP_SEND), | ||||
sock_fp, NULL, NULL); | sock_fp, NULL, NULL); | ||||
if (error != 0) | if (error != 0) | ||||
return (error); | return (error); | ||||
*so = (*sock_fp)->f_data; | *so = (*sock_fp)->f_data; | ||||
if ((*so)->so_type != SOCK_STREAM) | if ((*so)->so_type != SOCK_STREAM) | ||||
return (EINVAL); | return (EINVAL); | ||||
if (((*so)->so_state & SS_ISCONNECTED) == 0) | |||||
return (ENOTCONN); | |||||
return (0); | return (0); | ||||
} | } | ||||
int | int | ||||
vn_sendfile(struct file *fp, int sockfd, struct uio *hdr_uio, | vn_sendfile(struct file *fp, int sockfd, struct uio *hdr_uio, | ||||
struct uio *trl_uio, off_t offset, size_t nbytes, off_t *sent, int flags, | struct uio *trl_uio, off_t offset, size_t nbytes, off_t *sent, int flags, | ||||
struct thread *td) | struct thread *td) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | if (so->so_snd.sb_state & SBS_CANTSENDMORE) { | ||||
SOCKBUF_UNLOCK(&so->so_snd); | SOCKBUF_UNLOCK(&so->so_snd); | ||||
goto done; | goto done; | ||||
} else if (so->so_error) { | } else if (so->so_error) { | ||||
error = so->so_error; | error = so->so_error; | ||||
so->so_error = 0; | so->so_error = 0; | ||||
SOCKBUF_UNLOCK(&so->so_snd); | SOCKBUF_UNLOCK(&so->so_snd); | ||||
goto done; | goto done; | ||||
} | } | ||||
if ((so->so_state & SS_ISCONNECTED) == 0) { | |||||
SOCKBUF_UNLOCK(&so->so_snd); | |||||
error = ENOTCONN; | |||||
goto done; | |||||
} | |||||
space = sbspace(&so->so_snd); | space = sbspace(&so->so_snd); | ||||
if (space < rem && | if (space < rem && | ||||
(space <= 0 || | (space <= 0 || | ||||
space < so->so_snd.sb_lowat)) { | space < so->so_snd.sb_lowat)) { | ||||
if (so->so_state & SS_NBIO) { | if (so->so_state & SS_NBIO) { | ||||
SOCKBUF_UNLOCK(&so->so_snd); | SOCKBUF_UNLOCK(&so->so_snd); | ||||
error = EAGAIN; | error = EAGAIN; | ||||
goto done; | goto done; | ||||
▲ Show 20 Lines • Show All 404 Lines • Show Last 20 Lines |