本文整理汇总了C++中SOCK_UNLOCK函数的典型用法代码示例。如果您正苦于以下问题:C++ SOCK_UNLOCK函数的具体用法?C++ SOCK_UNLOCK怎么用?C++ SOCK_UNLOCK使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SOCK_UNLOCK函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mac_socket_label_set
int
mac_socket_label_set(struct ucred *cred, struct socket *so,
struct label *label)
{
int error;
/*
* We acquire the socket lock when we perform the test and set, but
* have to release it as the pcb code needs to acquire the pcb lock,
* which will precede the socket lock in the lock order. However,
* this is fine, as any race will simply result in the inpcb being
* refreshed twice, but still consistently, as the inpcb code will
* acquire the socket lock before refreshing, holding both locks.
*/
SOCK_LOCK(so);
error = mac_socket_check_relabel(cred, so, label);
if (error) {
SOCK_UNLOCK(so);
return (error);
}
mac_socket_relabel(cred, so, label);
SOCK_UNLOCK(so);
/*
* If the protocol has expressed interest in socket layer changes,
* such as if it needs to propagate changes to a cached pcb label
* from the socket, notify it of the label change while holding the
* socket lock.
*/
if (so->so_proto->pr_usrreqs->pru_sosetlabel != NULL)
(so->so_proto->pr_usrreqs->pru_sosetlabel)(so);
return (0);
}
示例2: svc_vc_create
/*
* Usage:
* xprt = svc_vc_create(sock, send_buf_size, recv_buf_size);
*
* Creates, registers, and returns a (rpc) tcp based transporter.
* Once *xprt is initialized, it is registered as a transporter
* see (svc.h, xprt_register). This routine returns
* a NULL if a problem occurred.
*
* The filedescriptor passed in is expected to refer to a bound, but
* not yet connected socket.
*
* Since streams do buffered io similar to stdio, the caller can specify
* how big the send and receive buffers are via the second and third parms;
* 0 => use the system default.
*/
SVCXPRT *
svc_vc_create(SVCPOOL *pool, struct socket *so, size_t sendsize,
size_t recvsize)
{
SVCXPRT *xprt = NULL;
struct sockaddr* sa;
int error;
SOCK_LOCK(so);
if (so->so_state & (SS_ISCONNECTED|SS_ISDISCONNECTED)) {
SOCK_UNLOCK(so);
CURVNET_SET(so->so_vnet);
error = so->so_proto->pr_usrreqs->pru_peeraddr(so, &sa);
CURVNET_RESTORE();
if (error)
return (NULL);
xprt = svc_vc_create_conn(pool, so, sa);
free(sa, M_SONAME);
return (xprt);
}
SOCK_UNLOCK(so);
xprt = svc_xprt_alloc();
sx_init(&xprt->xp_lock, "xprt->xp_lock");
xprt->xp_pool = pool;
xprt->xp_socket = so;
xprt->xp_p1 = NULL;
xprt->xp_p2 = NULL;
xprt->xp_ops = &svc_vc_rendezvous_ops;
CURVNET_SET(so->so_vnet);
error = so->so_proto->pr_usrreqs->pru_sockaddr(so, &sa);
CURVNET_RESTORE();
if (error) {
goto cleanup_svc_vc_create;
}
memcpy(&xprt->xp_ltaddr, sa, sa->sa_len);
free(sa, M_SONAME);
xprt_register(xprt);
solisten(so, -1, curthread);
SOCKBUF_LOCK(&so->so_rcv);
xprt->xp_upcallset = 1;
soupcall_set(so, SO_RCV, svc_vc_soupcall, xprt);
SOCKBUF_UNLOCK(&so->so_rcv);
return (xprt);
cleanup_svc_vc_create:
if (xprt) {
sx_destroy(&xprt->xp_lock);
svc_xprt_free(xprt);
}
return (NULL);
}
示例3: tcp_usr_abort
/*
* Abort the TCP. Drop the connection abruptly.
*/
static void
tcp_usr_abort(struct socket *so)
{
struct inpcb *inp;
struct tcpcb *tp = NULL;
TCPDEBUG0;
inp = sotoinpcb(so);
KASSERT(inp != NULL, ("tcp_usr_abort: inp == NULL"));
INP_INFO_WLOCK(&tcbinfo);
INP_LOCK(inp);
KASSERT(inp->inp_socket != NULL,
("tcp_usr_abort: inp_socket == NULL"));
/*
* If we still have full TCP state, and we're not dropped, drop.
*/
if (!(inp->inp_vflag & INP_TIMEWAIT) &&
!(inp->inp_vflag & INP_DROPPED)) {
tp = intotcpcb(inp);
TCPDEBUG1();
tcp_drop(tp, ECONNABORTED);
TCPDEBUG2(PRU_ABORT);
}
if (!(inp->inp_vflag & INP_DROPPED)) {
SOCK_LOCK(so);
so->so_state |= SS_PROTOREF;
SOCK_UNLOCK(so);
inp->inp_vflag |= INP_SOCKREF;
}
INP_UNLOCK(inp);
INP_INFO_WUNLOCK(&tcbinfo);
}
示例4: do_getopt_accept_filter
int
do_getopt_accept_filter(struct socket *so, struct sockopt *sopt)
{
struct accept_filter_arg *afap;
int error;
error = 0;
afap = malloc(sizeof(*afap), M_TEMP,
M_WAITOK | M_ZERO);
SOCK_LOCK(so);
if ((so->so_options & SO_ACCEPTCONN) == 0) {
error = EINVAL;
goto out;
}
if ((so->so_options & SO_ACCEPTFILTER) == 0) {
error = EINVAL;
goto out;
}
strcpy(afap->af_name, so->so_accf->so_accept_filter->accf_name);
if (so->so_accf->so_accept_filter_str != NULL)
strcpy(afap->af_arg, so->so_accf->so_accept_filter_str);
out:
SOCK_UNLOCK(so);
if (error == 0)
error = sooptcopyout(sopt, afap, sizeof(*afap));
free(afap, M_TEMP);
return (error);
}
示例5: audit_arg_file
/*
* Audit information about a file, either the file's vnode info, or its
* socket address info.
*/
void
audit_arg_file(struct proc *p, struct file *fp)
{
struct kaudit_record *ar;
struct socket *so;
struct inpcb *pcb;
struct vnode *vp;
int vfslocked;
ar = currecord();
if (ar == NULL)
return;
switch (fp->f_type) {
case DTYPE_VNODE:
case DTYPE_FIFO:
/*
* XXXAUDIT: Only possibly to record as first vnode?
*/
vp = fp->f_vnode;
vfslocked = VFS_LOCK_GIANT(vp->v_mount);
vn_lock(vp, LK_SHARED | LK_RETRY);
audit_arg_vnode1(vp);
VOP_UNLOCK(vp, 0);
VFS_UNLOCK_GIANT(vfslocked);
break;
case DTYPE_SOCKET:
so = (struct socket *)fp->f_data;
if (INP_CHECK_SOCKAF(so, PF_INET)) {
SOCK_LOCK(so);
ar->k_ar.ar_arg_sockinfo.so_type =
so->so_type;
ar->k_ar.ar_arg_sockinfo.so_domain =
INP_SOCKAF(so);
ar->k_ar.ar_arg_sockinfo.so_protocol =
so->so_proto->pr_protocol;
SOCK_UNLOCK(so);
pcb = (struct inpcb *)so->so_pcb;
INP_RLOCK(pcb);
ar->k_ar.ar_arg_sockinfo.so_raddr =
pcb->inp_faddr.s_addr;
ar->k_ar.ar_arg_sockinfo.so_laddr =
pcb->inp_laddr.s_addr;
ar->k_ar.ar_arg_sockinfo.so_rport =
pcb->inp_fport;
ar->k_ar.ar_arg_sockinfo.so_lport =
pcb->inp_lport;
INP_RUNLOCK(pcb);
ARG_SET_VALID(ar, ARG_SOCKINFO);
}
break;
default:
/* XXXAUDIT: else? */
break;
}
}
示例6: ng_ksocket_connect
static int
ng_ksocket_connect(hook_p hook)
{
node_p node = NG_HOOK_NODE(hook);
const priv_p priv = NG_NODE_PRIVATE(node);
struct socket *const so = priv->so;
/* Add our hook for incoming data and other events */
priv->so->so_upcallarg = (caddr_t)node;
priv->so->so_upcall = ng_ksocket_incoming;
SOCKBUF_LOCK(&priv->so->so_rcv);
priv->so->so_rcv.sb_flags |= SB_UPCALL;
SOCKBUF_UNLOCK(&priv->so->so_rcv);
SOCKBUF_LOCK(&priv->so->so_snd);
priv->so->so_snd.sb_flags |= SB_UPCALL;
SOCKBUF_UNLOCK(&priv->so->so_snd);
SOCK_LOCK(priv->so);
sosetstate(priv->so, SS_NBIO);
SOCK_UNLOCK(priv->so);
/*
* --Original comment--
* On a cloned socket we may have already received one or more
* upcalls which we couldn't handle without a hook. Handle
* those now.
* We cannot call the upcall function directly
* from here, because until this function has returned our
* hook isn't connected.
*
* ---meta comment for -current ---
* XXX This is dubius.
* Upcalls between the time that the hook was
* first created and now (on another processesor) will
* be earlier on the queue than the request to finalise the hook.
* By the time the hook is finalised,
* The queued upcalls will have happenned and the code
* will have discarded them because of a lack of a hook.
* (socket not open).
*
* This is a bad byproduct of the complicated way in which hooks
* are now created (3 daisy chained async events).
*
* Since we are a netgraph operation
* We know that we hold a lock on this node. This forces the
* request we make below to be queued rather than implemented
* immediatly which will cause the upcall function to be called a bit
* later.
* However, as we will run any waiting queued operations immediatly
* after doing this one, if we have not finalised the other end
* of the hook, those queued operations will fail.
*/
if (priv->flags & KSF_CLONED) {
ng_send_fn(node, NULL, &ng_ksocket_incoming2, so, M_WAITOK | M_NULLOK);
}
return (0);
}
示例7: icl_conn_connect_tcp
static int
icl_conn_connect_tcp(struct icl_conn *ic, int domain, int socktype,
int protocol, struct sockaddr *from_sa, struct sockaddr *to_sa)
{
struct socket *so;
int error;
int interrupted = 0;
error = socreate(domain, &so, socktype, protocol,
curthread->td_ucred, curthread);
if (error != 0)
return (error);
if (from_sa != NULL) {
error = sobind(so, from_sa, curthread);
if (error != 0) {
soclose(so);
return (error);
}
}
error = soconnect(so, to_sa, curthread);
if (error != 0) {
soclose(so);
return (error);
}
SOCK_LOCK(so);
while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) {
error = msleep(&so->so_timeo, SOCK_MTX(so), PSOCK | PCATCH,
"icl_connect", 0);
if (error) {
if (error == EINTR || error == ERESTART)
interrupted = 1;
break;
}
}
if (error == 0) {
error = so->so_error;
so->so_error = 0;
}
SOCK_UNLOCK(so);
if (error != 0) {
soclose(so);
return (error);
}
error = icl_conn_handoff_sock(ic, so);
if (error != 0)
soclose(so);
return (error);
}
示例8: p9fs_connect
/*
* XXX Need to implement reconnecting as necessary. If that were to be
* needed, most likely all current vnodes would have to be renegotiated
* or otherwise invalidated (a la NFS "stale file handle").
*/
static int
p9fs_connect(struct mount *mp)
{
struct p9fsmount *p9mp = VFSTOP9(mp);
struct p9fs_session *p9s = &p9mp->p9_session;
struct socket *so;
int error;
error = socreate(p9s->p9s_sockaddr.sa_family, &p9s->p9s_sock,
p9s->p9s_socktype, p9s->p9s_proto, curthread->td_ucred, curthread);
if (error != 0) {
vfs_mount_error(mp, "socreate");
goto out;
}
so = p9s->p9s_sock;
error = soconnect(so, &p9s->p9s_sockaddr, curthread);
SOCK_LOCK(so);
while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) {
error = msleep(&so->so_timeo, SOCK_MTX(so), PSOCK | PCATCH,
"connec", 0);
if (error)
break;
}
if (error == 0) {
error = so->so_error;
so->so_error = 0;
}
SOCK_UNLOCK(so);
if (error) {
vfs_mount_error(mp, "soconnect");
if (error == EINTR)
so->so_state &= ~SS_ISCONNECTING;
goto out;
}
if (so->so_proto->pr_flags & PR_CONNREQUIRED)
p9fs_setsockopt(so, SO_KEEPALIVE);
if (so->so_proto->pr_protocol == IPPROTO_TCP)
p9fs_setsockopt(so, TCP_NODELAY);
SOCKBUF_LOCK(&so->so_rcv);
soupcall_set(so, SO_RCV, p9fs_client_upcall, p9mp);
SOCKBUF_UNLOCK(&so->so_rcv);
error = 0;
out:
return (error);
}
示例9: sowakeup_aio
void
sowakeup_aio(struct socket *so, struct sockbuf *sb)
{
SOCKBUF_LOCK_ASSERT(sb);
sb->sb_flags &= ~SB_AIO;
if (sb->sb_flags & SB_AIO_RUNNING)
return;
sb->sb_flags |= SB_AIO_RUNNING;
if (sb == &so->so_snd)
SOCK_LOCK(so);
soref(so);
if (sb == &so->so_snd)
SOCK_UNLOCK(so);
soaio_enqueue(&sb->sb_aiotask);
}
示例10: tcp_usr_listen
/*
* Prepare to accept connections.
*/
static int
tcp_usr_listen(struct socket *so, int backlog, struct thread *td)
{
int error = 0;
struct inpcb *inp;
struct tcpcb *tp = NULL;
//printf("%s: called\n", __FUNCTION__);
TCPDEBUG0;
INP_INFO_WLOCK(&tcbinfo);
inp = sotoinpcb(so);
KASSERT(inp != NULL, ("tcp_usr_listen: inp == NULL"));
INP_LOCK(inp);
if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
error = EINVAL;
goto out;
}
tp = intotcpcb(inp);
TCPDEBUG1();
SOCK_LOCK(so);
error = solisten_proto_check(so);
//printf("%s: error=%d\n", __FUNCTION__, error);
#ifdef MAXHE_TODO
if (error == 0 && inp->inp_lport == 0)
error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
#else
if (error == 0 && inp->inp_lport == 0)
error = in_pcbbind(inp, (struct sockaddr *)0, NULL);
#endif // MAXHE_TODO
if (error == 0) {
tp->t_state = TCPS_LISTEN;
//printf("%s: solisten_proto backlog=%d\n", __FUNCTION__, backlog);
solisten_proto(so, backlog);
}
SOCK_UNLOCK(so);
//printf("%s: called done\n", __FUNCTION__);
out:
//printf("%s: called out\n", __FUNCTION__);
TCPDEBUG2(PRU_LISTEN);
INP_UNLOCK(inp);
INP_INFO_WUNLOCK(&tcbinfo);
return (error);
}
示例11: udp6_disconnect
static int
udp6_disconnect(struct socket *so)
{
struct inpcb *inp;
struct inpcbinfo *pcbinfo;
int error;
pcbinfo = udp_get_inpcbinfo(so->so_proto->pr_protocol);
inp = sotoinpcb(so);
KASSERT(inp != NULL, ("udp6_disconnect: inp == NULL"));
INP_WLOCK(inp);
#ifdef INET
if (inp->inp_vflag & INP_IPV4) {
struct pr_usrreqs *pru;
uint8_t nxt;
nxt = (inp->inp_socket->so_proto->pr_protocol == IPPROTO_UDP) ?
IPPROTO_UDP : IPPROTO_UDPLITE;
INP_WUNLOCK(inp);
pru = inetsw[ip_protox[nxt]].pr_usrreqs;
(void)(*pru->pru_disconnect)(so);
return (0);
}
#endif
if (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr)) {
error = ENOTCONN;
goto out;
}
INP_HASH_WLOCK(pcbinfo);
in6_pcbdisconnect(inp);
inp->in6p_laddr = in6addr_any;
INP_HASH_WUNLOCK(pcbinfo);
SOCK_LOCK(so);
so->so_state &= ~SS_ISCONNECTED; /* XXX */
SOCK_UNLOCK(so);
out:
INP_WUNLOCK(inp);
return (0);
}
示例12: mac_getsockopt_peerlabel
int
mac_getsockopt_peerlabel(struct ucred *cred, struct socket *so,
struct mac *mac)
{
char *elements, *buffer;
struct label *intlabel;
int error;
if (!(mac_labeled & MPC_OBJECT_SOCKET))
return (EINVAL);
error = mac_check_structmac_consistent(mac);
if (error)
return (error);
elements = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK);
error = copyinstr(mac->m_string, elements, mac->m_buflen, NULL);
if (error) {
free(elements, M_MACTEMP);
return (error);
}
buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
intlabel = mac_socket_label_alloc(M_WAITOK);
SOCK_LOCK(so);
mac_socket_copy_label(so->so_peerlabel, intlabel);
SOCK_UNLOCK(so);
error = mac_socketpeer_externalize_label(intlabel, elements, buffer,
mac->m_buflen);
mac_socket_label_free(intlabel);
if (error == 0)
error = copyout(buffer, mac->m_string, strlen(buffer)+1);
free(buffer, M_MACTEMP);
free(elements, M_MACTEMP);
return (error);
}
示例13: udp_disconnect
static int
udp_disconnect(struct socket *so)
{
struct inpcb *inp;
struct inpcbinfo *pcbinfo;
pcbinfo = get_inpcbinfo(so->so_proto->pr_protocol);
inp = sotoinpcb(so);
KASSERT(inp != NULL, ("udp_disconnect: inp == NULL"));
INP_WLOCK(inp);
if (inp->inp_faddr.s_addr == INADDR_ANY) {
INP_WUNLOCK(inp);
return (ENOTCONN);
}
INP_HASH_WLOCK(pcbinfo);
in_pcbdisconnect(inp);
inp->inp_laddr.s_addr = INADDR_ANY;
INP_HASH_WUNLOCK(pcbinfo);
SOCK_LOCK(so);
so->so_state &= ~SS_ISCONNECTED; /* XXX */
SOCK_UNLOCK(so);
INP_WUNLOCK(inp);
return (0);
}
示例14: icl_accept_thread
/*
* XXX: Doing accept in a separate thread in each socket might not be the best way
* to do stuff, but it's pretty clean and debuggable - and you probably won't
* have hundreds of listening sockets anyway.
*/
static void
icl_accept_thread(void *arg)
{
struct icl_listen_sock *ils;
struct socket *head, *so;
struct sockaddr *sa;
int error;
ils = arg;
head = ils->ils_socket;
ils->ils_running = true;
for (;;) {
ACCEPT_LOCK();
while (TAILQ_EMPTY(&head->so_comp) && head->so_error == 0 && ils->ils_disconnecting == false) {
if (head->so_rcv.sb_state & SBS_CANTRCVMORE) {
head->so_error = ECONNABORTED;
break;
}
error = msleep(&head->so_timeo, &accept_mtx, PSOCK | PCATCH,
"accept", 0);
if (error) {
ACCEPT_UNLOCK();
ICL_WARN("msleep failed with error %d", error);
continue;
}
if (ils->ils_disconnecting) {
ACCEPT_UNLOCK();
ICL_DEBUG("terminating");
ils->ils_running = false;
kthread_exit();
return;
}
}
if (head->so_error) {
error = head->so_error;
head->so_error = 0;
ACCEPT_UNLOCK();
ICL_WARN("socket error %d", error);
continue;
}
so = TAILQ_FIRST(&head->so_comp);
KASSERT(so != NULL, ("NULL so"));
KASSERT(!(so->so_qstate & SQ_INCOMP), ("accept1: so SQ_INCOMP"));
KASSERT(so->so_qstate & SQ_COMP, ("accept1: so not SQ_COMP"));
/*
* Before changing the flags on the socket, we have to bump the
* reference count. Otherwise, if the protocol calls sofree(),
* the socket will be released due to a zero refcount.
*/
SOCK_LOCK(so); /* soref() and so_state update */
soref(so); /* file descriptor reference */
TAILQ_REMOVE(&head->so_comp, so, so_list);
head->so_qlen--;
so->so_state |= (head->so_state & SS_NBIO);
so->so_qstate &= ~SQ_COMP;
so->so_head = NULL;
SOCK_UNLOCK(so);
ACCEPT_UNLOCK();
sa = NULL;
error = soaccept(so, &sa);
if (error != 0) {
ICL_WARN("soaccept error %d", error);
if (sa != NULL)
free(sa, M_SONAME);
soclose(so);
continue;
}
(ils->ils_listen->il_accept)(so, sa, ils->ils_id);
}
}
示例15: ng_ksocket_finish_accept
/*
* Handle the first completed incoming connection, assumed to be already
* on the socket's so_comp queue.
*/
static void
ng_ksocket_finish_accept(priv_p priv)
{
struct socket *const head = priv->so;
struct socket *so;
struct sockaddr *sa = NULL;
struct ng_mesg *resp;
struct ng_ksocket_accept *resp_data;
node_p node;
priv_p priv2;
int len;
int error;
ACCEPT_LOCK();
so = TAILQ_FIRST(&head->so_comp);
if (so == NULL) { /* Should never happen */
ACCEPT_UNLOCK();
return;
}
TAILQ_REMOVE(&head->so_comp, so, so_list);
head->so_qlen--;
so->so_qstate &= ~SQ_COMP;
so->so_head = NULL;
SOCK_LOCK(so);
soref(so);
sosetstate(so, SS_NBIO);
SOCK_UNLOCK(so);
ACCEPT_UNLOCK();
/* XXX KNOTE(&head->so_rcv.sb_sel.si_note, 0); */
soaccept(so, &sa);
len = OFFSETOF(struct ng_ksocket_accept, addr);
if (sa != NULL)
len += sa->sa_len;
NG_MKMESSAGE(resp, NGM_KSOCKET_COOKIE, NGM_KSOCKET_ACCEPT, len,
M_WAITOK | M_NULLOK);
if (resp == NULL) {
soclose(so);
goto out;
}
resp->header.flags |= NGF_RESP;
resp->header.token = priv->response_token;
/* Clone a ksocket node to wrap the new socket */
error = ng_make_node_common(&ng_ksocket_typestruct, &node);
if (error) {
kfree(resp, M_NETGRAPH);
soclose(so);
goto out;
}
if (ng_ksocket_constructor(node) != 0) {
NG_NODE_UNREF(node);
kfree(resp, M_NETGRAPH);
soclose(so);
goto out;
}
priv2 = NG_NODE_PRIVATE(node);
priv2->so = so;
priv2->flags |= KSF_CLONED | KSF_EMBRYONIC;
/*
* Insert the cloned node into a list of embryonic children
* on the parent node. When a hook is created on the cloned
* node it will be removed from this list. When the parent
* is destroyed it will destroy any embryonic children it has.
*/
LIST_INSERT_HEAD(&priv->embryos, priv2, siblings);
so->so_upcallarg = (caddr_t)node;
so->so_upcall = ng_ksocket_incoming;
SOCKBUF_LOCK(&so->so_rcv);
so->so_rcv.sb_flags |= SB_UPCALL;
SOCKBUF_UNLOCK(&so->so_rcv);
SOCKBUF_LOCK(&so->so_snd);
so->so_snd.sb_flags |= SB_UPCALL;
SOCKBUF_UNLOCK(&so->so_snd);
/* Fill in the response data and send it or return it to the caller */
resp_data = (struct ng_ksocket_accept *)resp->data;
resp_data->nodeid = NG_NODE_ID(node);
if (sa != NULL)
bcopy(sa, &resp_data->addr, sa->sa_len);
NG_SEND_MSG_ID(error, node, resp, priv->response_addr, 0);
out:
if (sa != NULL)
kfree(sa, M_SONAME);
}