version 1.111.2.14, 2008/03/17 09:15:34 |
version 1.111.2.15, 2008/03/24 09:39:02 |
|
|
/* $NetBSD$ */ |
/* $NetBSD$ */ |
|
|
/*- |
/*- |
* Copyright (c) 2002, 2007 The NetBSD Foundation, Inc. |
* Copyright (c) 2002, 2007, 2008 The NetBSD Foundation, Inc. |
* All rights reserved. |
* All rights reserved. |
* |
* |
* This code is derived from software contributed to The NetBSD Foundation |
* This code is derived from software contributed to The NetBSD Foundation |
|
|
fsocreate(int domain, struct socket **sop, int type, int protocol, |
fsocreate(int domain, struct socket **sop, int type, int protocol, |
struct lwp *l, int *fdout) |
struct lwp *l, int *fdout) |
{ |
{ |
struct filedesc *fdp; |
|
struct socket *so; |
struct socket *so; |
struct file *fp; |
struct file *fp; |
int fd, error; |
int fd, error; |
|
|
fdp = l->l_proc->p_fd; |
if ((error = fd_allocfile(&fp, &fd)) != 0) |
/* falloc() will use the desciptor for us */ |
|
if ((error = falloc(l, &fp, &fd)) != 0) |
|
return (error); |
return (error); |
fp->f_flag = FREAD|FWRITE; |
fp->f_flag = FREAD|FWRITE; |
fp->f_type = DTYPE_SOCKET; |
fp->f_type = DTYPE_SOCKET; |
fp->f_ops = &socketops; |
fp->f_ops = &socketops; |
error = socreate(domain, &so, type, protocol, l); |
error = socreate(domain, &so, type, protocol, l); |
if (error != 0) { |
if (error != 0) { |
FILE_UNUSE(fp, l); |
fd_abort(curproc, fp, fd); |
fdremove(fdp, fd); |
|
ffree(fp); |
|
} else { |
} else { |
if (sop != NULL) |
if (sop != NULL) |
*sop = so; |
*sop = so; |
fp->f_data = so; |
fp->f_data = so; |
FILE_SET_MATURE(fp); |
fd_affix(curproc, fp, fd); |
FILE_UNUSE(fp, l); |
|
*fdout = fd; |
*fdout = fd; |
} |
} |
return error; |
return error; |
Line 1678 filt_sordetach(struct knote *kn) |
|
Line 1672 filt_sordetach(struct knote *kn) |
|
{ |
{ |
struct socket *so; |
struct socket *so; |
|
|
so = (struct socket *)kn->kn_fp->f_data; |
so = ((file_t *)kn->kn_obj)->f_data; |
SLIST_REMOVE(&so->so_rcv.sb_sel.sel_klist, kn, knote, kn_selnext); |
SLIST_REMOVE(&so->so_rcv.sb_sel.sel_klist, kn, knote, kn_selnext); |
if (SLIST_EMPTY(&so->so_rcv.sb_sel.sel_klist)) |
if (SLIST_EMPTY(&so->so_rcv.sb_sel.sel_klist)) |
so->so_rcv.sb_flags &= ~SB_KNOTE; |
so->so_rcv.sb_flags &= ~SB_KNOTE; |
Line 1690 filt_soread(struct knote *kn, long hint) |
|
Line 1684 filt_soread(struct knote *kn, long hint) |
|
{ |
{ |
struct socket *so; |
struct socket *so; |
|
|
so = (struct socket *)kn->kn_fp->f_data; |
so = ((file_t *)kn->kn_obj)->f_data; |
kn->kn_data = so->so_rcv.sb_cc; |
kn->kn_data = so->so_rcv.sb_cc; |
if (so->so_state & SS_CANTRCVMORE) { |
if (so->so_state & SS_CANTRCVMORE) { |
kn->kn_flags |= EV_EOF; |
kn->kn_flags |= EV_EOF; |
Line 1709 filt_sowdetach(struct knote *kn) |
|
Line 1703 filt_sowdetach(struct knote *kn) |
|
{ |
{ |
struct socket *so; |
struct socket *so; |
|
|
so = (struct socket *)kn->kn_fp->f_data; |
so = ((file_t *)kn->kn_obj)->f_data; |
SLIST_REMOVE(&so->so_snd.sb_sel.sel_klist, kn, knote, kn_selnext); |
SLIST_REMOVE(&so->so_snd.sb_sel.sel_klist, kn, knote, kn_selnext); |
if (SLIST_EMPTY(&so->so_snd.sb_sel.sel_klist)) |
if (SLIST_EMPTY(&so->so_snd.sb_sel.sel_klist)) |
so->so_snd.sb_flags &= ~SB_KNOTE; |
so->so_snd.sb_flags &= ~SB_KNOTE; |
Line 1721 filt_sowrite(struct knote *kn, long hint |
|
Line 1715 filt_sowrite(struct knote *kn, long hint |
|
{ |
{ |
struct socket *so; |
struct socket *so; |
|
|
so = (struct socket *)kn->kn_fp->f_data; |
so = ((file_t *)kn->kn_obj)->f_data; |
kn->kn_data = sbspace(&so->so_snd); |
kn->kn_data = sbspace(&so->so_snd); |
if (so->so_state & SS_CANTSENDMORE) { |
if (so->so_state & SS_CANTSENDMORE) { |
kn->kn_flags |= EV_EOF; |
kn->kn_flags |= EV_EOF; |
Line 1744 filt_solisten(struct knote *kn, long hin |
|
Line 1738 filt_solisten(struct knote *kn, long hin |
|
{ |
{ |
struct socket *so; |
struct socket *so; |
|
|
so = (struct socket *)kn->kn_fp->f_data; |
so = ((file_t *)kn->kn_obj)->f_data; |
|
|
/* |
/* |
* Set kn_data to number of incoming connections, not |
* Set kn_data to number of incoming connections, not |
Line 1767 soo_kqfilter(struct file *fp, struct kno |
|
Line 1761 soo_kqfilter(struct file *fp, struct kno |
|
struct socket *so; |
struct socket *so; |
struct sockbuf *sb; |
struct sockbuf *sb; |
|
|
so = (struct socket *)kn->kn_fp->f_data; |
so = ((file_t *)kn->kn_obj)->f_data; |
switch (kn->kn_filter) { |
switch (kn->kn_filter) { |
case EVFILT_READ: |
case EVFILT_READ: |
if (so->so_options & SO_ACCEPTCONN) |
if (so->so_options & SO_ACCEPTCONN) |
Line 1788 soo_kqfilter(struct file *fp, struct kno |
|
Line 1782 soo_kqfilter(struct file *fp, struct kno |
|
return (0); |
return (0); |
} |
} |
|
|
|
static int |
|
sodopoll(struct socket *so, int events) |
|
{ |
|
int revents; |
|
|
|
revents = 0; |
|
|
|
if (events & (POLLIN | POLLRDNORM)) |
|
if (soreadable(so)) |
|
revents |= events & (POLLIN | POLLRDNORM); |
|
|
|
if (events & (POLLOUT | POLLWRNORM)) |
|
if (sowritable(so)) |
|
revents |= events & (POLLOUT | POLLWRNORM); |
|
|
|
if (events & (POLLPRI | POLLRDBAND)) |
|
if (so->so_oobmark || (so->so_state & SS_RCVATMARK)) |
|
revents |= events & (POLLPRI | POLLRDBAND); |
|
|
|
return revents; |
|
} |
|
|
|
int |
|
sopoll(struct socket *so, int events) |
|
{ |
|
int revents = 0; |
|
int s; |
|
|
|
if ((revents = sodopoll(so, events)) != 0) |
|
return revents; |
|
|
|
KERNEL_LOCK(1, curlwp); |
|
s = splsoftnet(); |
|
|
|
if ((revents = sodopoll(so, events)) == 0) { |
|
if (events & (POLLIN | POLLPRI | POLLRDNORM | POLLRDBAND)) { |
|
selrecord(curlwp, &so->so_rcv.sb_sel); |
|
so->so_rcv.sb_flags |= SB_SEL; |
|
} |
|
|
|
if (events & (POLLOUT | POLLWRNORM)) { |
|
selrecord(curlwp, &so->so_snd.sb_sel); |
|
so->so_snd.sb_flags |= SB_SEL; |
|
} |
|
} |
|
|
|
splx(s); |
|
KERNEL_UNLOCK_ONE(curlwp); |
|
|
|
return revents; |
|
} |
|
|
|
|
#include <sys/sysctl.h> |
#include <sys/sysctl.h> |
|
|
static int sysctl_kern_somaxkva(SYSCTLFN_PROTO); |
static int sysctl_kern_somaxkva(SYSCTLFN_PROTO); |