mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-31 08:25:38 +00:00
server/tcp_terminal: wrap RPC functions in 'with_libc'
This commit is contained in:
parent
f9b3c6d2cf
commit
cd21074201
@ -441,39 +441,46 @@ class Terminal::Session_component : public Genode::Rpc_object<Session, Session_c
|
|||||||
|
|
||||||
bool avail()
|
bool avail()
|
||||||
{
|
{
|
||||||
return !read_buffer_empty();
|
bool ret = false;
|
||||||
|
Libc::with_libc([&] () { ret = !read_buffer_empty(); });
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Genode::size_t _read(Genode::size_t dst_len)
|
Genode::size_t _read(Genode::size_t dst_len)
|
||||||
{
|
{
|
||||||
Genode::size_t num_bytes =
|
Genode::size_t num_bytes = 0;
|
||||||
read_buffer(_io_buffer.local_addr<char>(),
|
Libc::with_libc([&] () {
|
||||||
Genode::min(_io_buffer.size(), dst_len));
|
num_bytes = read_buffer(_io_buffer.local_addr<char>(),
|
||||||
|
Genode::min(_io_buffer.size(), dst_len));
|
||||||
/*
|
|
||||||
* If read buffer was in use, look if more data is buffered in
|
|
||||||
* the TCP/IP stack.
|
|
||||||
*/
|
|
||||||
if (num_bytes)
|
|
||||||
open_socket_pool()->update_sockets_to_watch();
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If read buffer was in use, look if more data is buffered in
|
||||||
|
* the TCP/IP stack.
|
||||||
|
*/
|
||||||
|
if (num_bytes)
|
||||||
|
open_socket_pool()->update_sockets_to_watch();
|
||||||
|
});
|
||||||
return num_bytes;
|
return num_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
Genode::size_t _write(Genode::size_t num_bytes)
|
Genode::size_t _write(Genode::size_t num_bytes)
|
||||||
{
|
{
|
||||||
/* sanitize argument */
|
ssize_t written_bytes = 0;
|
||||||
num_bytes = Genode::min(num_bytes, _io_buffer.size());
|
|
||||||
|
|
||||||
/* write data to socket, assuming that it won't block */
|
Libc::with_libc([&] () {
|
||||||
ssize_t written_bytes = ::write(sd(),
|
/* sanitize argument */
|
||||||
_io_buffer.local_addr<char>(),
|
num_bytes = Genode::min(num_bytes, _io_buffer.size());
|
||||||
num_bytes);
|
|
||||||
|
|
||||||
if (written_bytes < 0) {
|
/* write data to socket, assuming that it won't block */
|
||||||
Genode::error("write error, dropping data");
|
written_bytes = ::write(sd(),
|
||||||
return 0;
|
_io_buffer.local_addr<char>(),
|
||||||
}
|
num_bytes);
|
||||||
|
|
||||||
|
if (written_bytes < 0) {
|
||||||
|
Genode::error("write error, dropping data");
|
||||||
|
written_bytes = 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return written_bytes;
|
return written_bytes;
|
||||||
}
|
}
|
||||||
@ -522,8 +529,12 @@ class Terminal::Root_component : public Genode::Root_component<Session_component
|
|||||||
|
|
||||||
unsigned tcp_port = 0;
|
unsigned tcp_port = 0;
|
||||||
policy.attribute("port").value(&tcp_port);
|
policy.attribute("port").value(&tcp_port);
|
||||||
return new (md_alloc())
|
Session_component *session = nullptr;
|
||||||
Session_component(_env, io_buffer_size, tcp_port);
|
Libc::with_libc([&] () {
|
||||||
|
session = new (md_alloc())
|
||||||
|
Session_component(_env, io_buffer_size, tcp_port);
|
||||||
|
});
|
||||||
|
return session;
|
||||||
}
|
}
|
||||||
catch (Xml_node::Nonexistent_attribute) {
|
catch (Xml_node::Nonexistent_attribute) {
|
||||||
error("Missing \"port\" attribute in policy definition");
|
error("Missing \"port\" attribute in policy definition");
|
||||||
@ -566,13 +577,13 @@ struct Main
|
|||||||
Main(Genode::Env &env) : _env(env)
|
Main(Genode::Env &env) : _env(env)
|
||||||
{
|
{
|
||||||
Genode::log("--- TCP terminal started ---");
|
Genode::log("--- TCP terminal started ---");
|
||||||
|
Libc::with_libc([&] () {
|
||||||
/* start thread blocking in select */
|
/* start thread blocking in select */
|
||||||
open_socket_pool(&_env);
|
open_socket_pool(&_env);
|
||||||
|
});
|
||||||
|
|
||||||
/* announce service at our parent */
|
/* announce service at our parent */
|
||||||
_env.parent().announce(env.ep().manage(_root));
|
_env.parent().announce(env.ep().manage(_root));
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user