コード例 #1
0
int
ncp_sock_send(struct socket *so, struct mbuf *top, struct ncp_rq *rqp)
{
	struct thread *td = curthread; /* XXX */
	struct sockaddr *to = NULL;
	struct ncp_conn *conn = rqp->conn;
	struct mbuf *m;
	int error, flags=0;
	int sendwait;

	for(;;) {
		m = m_copym(top, 0, M_COPYALL, MB_WAIT);
/*		NCPDDEBUG(m);*/
		error = so_pru_sosend(so, to, NULL, m, NULL, flags, td);
		if (error == 0 || error == EINTR || error == ENETDOWN)
			break;
		if (rqp->rexmit == 0) break;
		rqp->rexmit--;
		tsleep(&sendwait, 0, "ncprsn", conn->li.timeout * hz);
		error = ncp_chkintr(conn, td);
		if (error == EINTR) break;
	}
	if (error) {
		log(LOG_INFO, "ncp_send: error %d for server %s", error, conn->li.server);
	}
	return error;
}
コード例 #2
0
static void
ncp_watchdog(struct ncp_conn *conn) {
	char *buf;
	int error, len, flags;
	struct socket *so;
	struct sockaddr *sa;
	struct sockbuf sio;

	sa = NULL;
	while (conn->wdg_so) { /* not a loop */
		so = conn->wdg_so;
		sbinit(&sio, 1000000);
		flags = MSG_DONTWAIT;
		error = so_pru_soreceive(so, (struct sockaddr**)&sa,
					 NULL, &sio, NULL, &flags);
		if (error)
			break;
		len = sio.sb_cc;
		NCPSDEBUG("got watch dog %d\n",len);
		if (len != 2) {
			m_freem(sio.sb_mb);
			break;
		}
		buf = mtod(sio.sb_mb, char *);
		if (buf[1] != '?') {
			m_freem(sio.sb_mb);
			break;
		}
		buf[1] = 'Y';
		error = so_pru_sosend(so, sa, NULL, sio.sb_mb, NULL, 0, curthread);
		NCPSDEBUG("send watch dog %d\n",error);
		break;
	}
	if (sa)
		kfree(sa, M_SONAME);
	return;
}
コード例 #3
0
/*
 * MPSAFE
 */
int
soo_write(struct file *fp, struct uio *uio, struct ucred *cred, int fflags)
{
	struct socket *so;
	int error;
	int msgflags;

	so = (struct socket *)fp->f_data;

	if (fflags & O_FBLOCKING)
		msgflags = 0;
	else if (fflags & O_FNONBLOCKING)
		msgflags = MSG_FNONBLOCKING;
	else if (fp->f_flag & FNONBLOCK)
		msgflags = MSG_FNONBLOCKING;
	else
		msgflags = 0;

	error = so_pru_sosend(so, NULL, uio, NULL, NULL, msgflags, uio->uio_td);
	if (error == EPIPE && !(fflags & MSG_NOSIGNAL) &&
	    !(so->so_options & SO_NOSIGPIPE))
		lwpsignal(uio->uio_td->td_proc, uio->uio_td->td_lwp, SIGPIPE);
	return (error);
}