int CStreamBuffer::read( int sd, int flag )
{
	if( m_capacity == m_used ){
		//TODO expand
	}

	int res = 0;
	WRAP_SYSCALL( res, recv( sd, static_cast<void *>(m_buffer+m_used), m_capacity-m_used, flag ) );
	if( res == 0 ){
		printf( "EOF. sd:%d\n", sd );
		return -1;
	}

	if( res < 0 ){
		if( errno == EAGAIN ||
			errno == EWOULDBLOCK ){
			perror( "not ready yet" );
			return 0;
		}
		else{
			perror("recv()");
			return -1;
		}
	}
	m_used += res;
	return 0;
}
int CStreamBuffer::write( int sd, int flag )
{
	int res = 0;
	char* p = m_buffer + m_offset;
	size_t len = m_used - m_offset;
	while( len > 0 ){
		WRAP_SYSCALL( res, send( sd, p, len, flag ) );
		if( res < 0 ){
			if( errno == EAGAIN ||
				errno == EWOULDBLOCK ){
				perror( "not ready yet" );
				return ERR_SEND_FAILED;
			}
			else{
				perror( "couldn't send" );
				return -1;
			}
		}
		len -= res;
		p += res;
		m_offset += res;
	}
	compact( m_offset );
	return 0;
}
Exemple #3
0
void DiskFile::link(File* target) {
  DiskFile* diskTarget = dynamic_cast<DiskFile*>(target);
  if (diskTarget == NULL) {
    throw new std::invalid_argument("Cannot link disk file to non-disk file: " + path);
  }

  WRAP_SYSCALL(link, diskTarget->path.c_str(), path.c_str());
}
Exemple #4
0
void DiskFile::unlink() {
  WRAP_SYSCALL(unlink, path.c_str());
}
Exemple #5
0
void ByteStream::stat(struct stat* stats) {
  WRAP_SYSCALL(fstat, handle, stats);
}
Exemple #6
0
size_t ByteStream::write(const void* buffer, size_t size) {
  return WRAP_SYSCALL(write, handle, buffer, size);
}
Exemple #7
0
size_t ByteStream::read(void* buffer, size_t size) {
  return WRAP_SYSCALL(read, handle, buffer, size);
}
Exemple #8
0
ByteStream::ByteStream(const std::string& path, int flags, int mode)
    : handle(path, WRAP_SYSCALL(open, path.c_str(), flags, mode)) {}