Example #1
0
static void
pip_read(Xfilepipe *p)
{
	int n;

//	fprintf(stderr, "pip_read %p %d %d %d\n", p, spfd_can_read(p->lspfd), spfd_can_write(p->lspfd), spfd_has_error(p->lspfd));
	if (spfd_has_error(p->lspfd)) {
		pip_read_eof(p);
		pip_read_buf(p);
		return;
	}

	if (p->direction != Read)
		return;

	if (p->buflen < p->bufsize) {
		n = spfd_read(p->lspfd, p->buf + p->buflen, p->bufsize - p->buflen);
		if (n > 0) {
//			fprintf(stderr, "pip_read %p read %d bytes\n", p, n);
			p->buflen += n;
		}
	}

	pip_read_buf(p);
}
Example #2
0
int
spcfd_has_error(Spcfd *spcfd)
{
	if (spcfd->spfd)
		return spfd_has_error(spcfd->spfd);

	return spcfd->flags & Error;
}
Example #3
0
static void
pip_notify(Spfd *spfd, void *aux)
{
	Xfilepipe *p;

	p = aux;
//	fprintf(stderr, "pip_notify %p %d %d %d\n", spfd, spfd_can_read(spfd), spfd_can_write(spfd), spfd_has_error(spfd));
	if (p->buflen>0 || (p->direction==Read && spfd_can_read(spfd)))
		pip_read(p);

	if (spfd_can_write(spfd))
		pip_write(p);

	if (spfd_has_error(spfd)) {
		pip_read_eof(p);
		pip_disconnect(p);
	}
}
Example #4
0
static void
spc_notify(Spfd *spfd, void *aux)
{
	int ecode;
	char *ename;
	Spcfsys *fs;

	fs = aux;
	fs->in_notify++;
	sp_rerror(&ename, &ecode);
	if (ename)
		ename = strdup(ename);

	sp_werror(NULL, 0);
	if (spfd_can_read(spfd))
		spc_fd_read(fs);

	if (fs->destroyed) {
		free(fs);
		return;
	}

	if (!fs->spfd)
		goto error;

	if (spfd_can_write(spfd))
		spc_fd_write(fs);

	if (spfd_has_error(spfd))
		spc_disconnect_fsys(fs);

error:
	sp_rerror(&ename, &ecode);
	if (ecode) {
		if (spc_chatty)
			fprintf(stderr, "Error: %s: %d\n", ename, ecode);
		sp_werror(NULL, 0);
	}
	fs->in_notify--;
}
Example #5
0
static void
sp_ethconn_notify(Spfd *spfd, void *aux)
{
	int n = 0;
	Spconn *conn = aux;

//	int cr = spfd_can_read(spfd);
//	int cw = spfd_can_write(spfd);
//	if (conn->srv->debuglevel > 0)
//		fprintf(stderr, "sp_ethconn_notify: fd readable %d writable %d\n", cr, cw);

//	if (spfd_can_write(spfd))
//		spfd_write(spfd, 0, 0);	// reset polling flags

	if (spfd_can_read(spfd))
		n = sp_ethconn_read(conn);

	if (n || spfd_has_error(spfd))
	{
		if (conn->srv->debuglevel > 0)
			fprintf(stderr, "sp_ethconn_notify: error, shutdown conn\n");
		sp_conn_shutdown(conn);
	}
}