Пример #1
0
int
xp_file_copy_finish(Xpcopy *c)
{
	Xpfile *f;

	for(f = c->files; f != NULL; f = f->next) {
		if (f->spcfd) {
			spcfd_remove(f->spcfd);
			f->spcfd = NULL;
		}

		if (f->fid) {
			spc_close(f->fid);
			f->fid = NULL;
		}

		if (f->path) {
			free(f->buf);
			f->buf = NULL;
		}
	}

	free(c);
	return 0;
}
Пример #2
0
static void
spcfd_write_cb(void *cba, Spfcall *rc)
{
	int ecode;
	char *ename;
	Spcfd *spcfd;

	spcfd = cba;

	spcfd_check_error(spcfd, rc);
	sp_rerror(&ename, &ecode);
	if (ecode) {
		spcfd->flags |= Error;
		goto do_notify;
	}

	spcfd->offset += rc->count;
	if (rc->count < spcfd->wpos)
		memmove(spcfd->wbuf, spcfd->wbuf + rc->count, spcfd->wpos - rc->count);

	spcfd->wpos -= rc->count;

do_notify:
	free(spcfd->wtc);
	spcfd->wtc = NULL;
	free(rc);
	if (spcfd->flags & Remove)
		spcfd_remove(spcfd);
	else
		(*spcfd->notify)(spcfd, spcfd->aux);

	sp_werror(NULL, 0);
}
Пример #3
0
static void
spcfd_read_cb(void *cba, Spfcall *rc)
{
	int n, ecode;
	char *ename;
	Spcfd *spcfd;

	spcfd = cba;
	spcfd_check_error(spcfd, rc);
	sp_rerror(&ename, &ecode);
	if (ecode) {
		spcfd->flags |= Error;
		goto do_notify;
	}

	n = spcfd->rpos;
	if (rc->count) {
		memmove(spcfd->rbuf + spcfd->rpos, rc->data, rc->count);
		spcfd->rpos += rc->count;
		spcfd->offset += rc->count;
	} else
		spcfd->flags |= Reof;

do_notify:
	free(spcfd->rtc);
	spcfd->rtc = NULL;
	free(rc);

	if (spcfd->flags & Remove)
		spcfd_remove(spcfd);
	else
		(*spcfd->notify)(spcfd, spcfd->aux);

	sp_werror(NULL, 0);
}
Пример #4
0
void
xp_file_destroy(Xpfile *f)
{
	if (!f)
		return;

	if (f->spcfd)
		spcfd_remove(f->spcfd);
	if (f->fid)
		spc_close(f->fid);
	if (f->fd >= 0)
		close(f->fd);

	free(f->buf);
	free(f->name);
	free(f->path);
	free(f);
}
Пример #5
0
static void
xp_file_notify(Spcfd *spcfd, void *a)
{
	int n, ecode;
	char *ename;
	Xpcopy *c;
	Xpfile *f;

	c = a;
	f = c->cfile;

error:
	if (sp_haserror()) {
		sp_rerror(&ename, &ecode);
		if (c->finish)
			(*c->finish)(c, c->finishaux);

//		spcfd_remove(spcfd);
		return;
	}

	if (!spcfd_can_write(spcfd))
		return;

	if (f->pos >= f->buflen) {
		if (!f->path) 
			goto next_file;

		if (f->fd < 0) {
			f->fd = open(f->path, O_RDONLY);
			if (f->fd < 0) {
				sp_uerror(errno);
				goto error;
			}

			f->bufsize = Bufsize;
			f->buf = malloc(f->bufsize);
			if (!f->buf) {
				sp_werror(Enomem, ENOMEM);
				goto error;
			}
		}

		n = read(f->fd, f->buf, f->bufsize);
		if (n < 0) {
			sp_uerror(errno);
			goto error;
		}

		if (n == 0) {
			close(f->fd);
			f->fd = -1;
			free(f->buf);
			f->buf = NULL;
			f->buflen = 0;
			f->bufsize = 0;
			f->pos = 0;
			goto next_file;
		}

		f->buflen = n;
		f->pos = 0;
	}

	n = spcfd_write(spcfd, f->buf + f->pos, f->buflen - f->pos);
	if (n <= 0)
		goto error;

	f->pos += n;
	return;

next_file:
	spcfd_remove(f->spcfd);
	f->spcfd = NULL;
	c->cfile = f->next;
	xp_file_copy(c);
}
Пример #6
0
static void
disconnect()
{
	spcfd_remove(ispcfd);
	spcfd_stop_loop();
}