Esempio n. 1
0
int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)
{
	if (IS_OFP_SOCKET(epfd)) {
		struct ofp_epoll_event ofp_event = { event->events, { .u64 = event->data.u64 } };

		if (ofp_epoll_ctl(epfd, op, fd, &ofp_event) == 0)
			return 0;

		errno = NETWRAP_ERRNO(ofp_errno);
		return -1;
	}
Esempio n. 2
0
int epoll_create(int size)
{
	int epfd = -1;

	if (setup_epoll_wrappers_called) {
		epfd = ofp_epoll_create(size);

		if (epfd == -1)
			errno = NETWRAP_ERRNO(ofp_errno);
		else
			errno = 0;
	} else {
		LIBC_FUNCTION(epoll_create);

		if (libc_epoll_create)
			epfd = libc_epoll_create(size);
		else {
			errno = EACCES;
			epfd = -1;
		}
	}

	return epfd;
}
Esempio n. 3
0
ssize_t sendfile64(int out_fd, int in_fd, off64_t *offset, size_t count)
{
	ssize_t sendfile_value = -1;

	if (IS_OFP_SOCKET(out_fd)) {
		off_t orig = 0;
		size_t data_processed = 0;
		char buff[BUF_SIZE];
		ssize_t data_read;
		ofp_ssize_t ofp_data_sent;
		ofp_ssize_t ofp_data_sent_sum;

		if (offset != NULL) {
			orig = lseek(in_fd, 0, SEEK_CUR);
			if (orig == (off_t)-1)
				return -1;
			if (lseek(in_fd, *offset, SEEK_SET) == -1)
				return -1;
		}

		while (data_processed < count) {
			data_read = (*libc_read)(in_fd, buff, BUF_SIZE);
			if (data_read < 0)
				return -1;
			else if (data_read == 0)   /*EOF*/
				break;

			ofp_data_sent_sum = 0;
			while (ofp_data_sent_sum < data_read) {
				ofp_data_sent = ofp_send(out_fd,
					buff + ofp_data_sent_sum,
					data_read - ofp_data_sent_sum, 0);
				if (ofp_data_sent < 0) {
					if (ofp_errno == OFP_EWOULDBLOCK) {
						usleep(100);
						continue;
					}
					errno = NETWRAP_ERRNO(ofp_errno);
					return -1;
				}
				ofp_data_sent_sum += ofp_data_sent;
			}
			data_processed += data_read;
		}

		sendfile_value = data_processed;

		if (offset != NULL) {
			*offset = lseek(in_fd, 0, SEEK_CUR);
			if (*offset == -1)
				return -1;
			if (lseek(in_fd, orig, SEEK_SET) == -1)
				return -1;
		}
	} else if (libc_sendfile64)
		sendfile_value = (*libc_sendfile64)(out_fd, in_fd,
				offset, count);
	else {
		LIBC_FUNCTION(sendfile64);

		if (libc_sendfile64)
			sendfile_value = (*libc_sendfile64)(out_fd, in_fd,
				offset, count);
		else {
			sendfile_value = -1;
			errno = EACCES;
		}
	}

	/*printf("Sendfile64 called on socket '%d' returned:'%d'\n",
		out_fd, (int)sendfile_value);*/
	return sendfile_value;
}