terminal session: return number of bytes written

To better support non-blocking terminal components, let the
'Terminal::Session::write()' function return the number of bytes
actually written.

Fixes #2240
This commit is contained in:
Christian Prochaska
2017-01-17 15:45:54 +01:00
committed by Norman Feske
parent 9f7a4feab4
commit dbb641d44a
11 changed files with 65 additions and 31 deletions

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (C) 2011-2016 Genode Labs GmbH
* Copyright (C) 2011-2017 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
@ -433,14 +433,22 @@ namespace Terminal {
return num_bytes;
}
void _write(Genode::size_t num_bytes)
Genode::size_t _write(Genode::size_t num_bytes)
{
/* sanitize argument */
num_bytes = Genode::min(num_bytes, _io_buffer.size());
/* write data to socket, assuming that it won't block */
if (::write(sd(), _io_buffer.local_addr<char>(), num_bytes) < 0)
ssize_t written_bytes = ::write(sd(),
_io_buffer.local_addr<char>(),
num_bytes);
if (written_bytes < 0) {
Genode::error("write error, dropping data");
return 0;
}
return written_bytes;
}
Genode::Dataspace_capability _dataspace()