mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-13 22:47:15 -04:00
Prepare socket support
This commit is contained in:
parent
18b2a2bdc7
commit
1683dc3b37
48
kernel/include/net/socket.hpp
Normal file
48
kernel/include/net/socket.hpp
Normal file
@ -0,0 +1,48 @@
|
||||
//=======================================================================
|
||||
// Copyright Baptiste Wicht 2013-2016.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//=======================================================================
|
||||
|
||||
#ifndef NET_SOCKET_H
|
||||
#define NET_SOCKET_H
|
||||
|
||||
#include <types.hpp>
|
||||
|
||||
namespace network {
|
||||
|
||||
enum class socket_domain {
|
||||
AF_INET
|
||||
};
|
||||
|
||||
enum class socket_type {
|
||||
RAW
|
||||
};
|
||||
|
||||
enum class socket_protocol {
|
||||
ICMP
|
||||
};
|
||||
|
||||
struct socket {
|
||||
size_t id;
|
||||
socket_domain domain;
|
||||
socket_type type;
|
||||
socket_protocol protocol;
|
||||
|
||||
//socket(){}
|
||||
//socket(size_t id, socket_domain domain, socket_type type, socket_protocol protocol)
|
||||
//: id(id), domain(domain), type(type), protocol(protocol) {}
|
||||
|
||||
void invalidate(){
|
||||
id = 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
bool is_valid() const {
|
||||
return id == 0xFFFFFFFF;
|
||||
}
|
||||
};
|
||||
|
||||
} // end of network namespace
|
||||
|
||||
#endif
|
@ -16,6 +16,8 @@
|
||||
|
||||
#include "vfs/path.hpp"
|
||||
|
||||
#include "net/socket.hpp"
|
||||
|
||||
namespace scheduler {
|
||||
|
||||
constexpr const size_t MAX_PRIORITY = 4;
|
||||
@ -90,6 +92,7 @@ struct process_control_t {
|
||||
size_t rounds;
|
||||
size_t sleep_timeout;
|
||||
std::vector<path> handles;
|
||||
std::vector<network::socket> sockets;
|
||||
path working_directory;
|
||||
};
|
||||
|
||||
|
@ -55,6 +55,11 @@ const path& get_handle(size_t fd);
|
||||
bool has_handle(size_t fd);
|
||||
void release_handle(size_t fd);
|
||||
|
||||
size_t register_new_socket(network::socket_domain domain, network::socket_type type, network::socket_protocol protocol);
|
||||
const network::socket& get_socket(size_t fd);
|
||||
bool has_socket(size_t fd);
|
||||
void release_socket(size_t fd);
|
||||
|
||||
const path& get_working_directory();
|
||||
void set_working_directory(const path& directory);
|
||||
|
||||
|
@ -918,6 +918,26 @@ const path& scheduler::get_handle(size_t fd){
|
||||
return pcb[current_pid].handles[fd];
|
||||
}
|
||||
|
||||
size_t scheduler::register_new_socket(network::socket_domain domain, network::socket_type type, network::socket_protocol protocol){
|
||||
auto id = pcb[current_pid].sockets.size();
|
||||
|
||||
pcb[current_pid].sockets.emplace_back(id, domain, type, protocol);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
void scheduler::release_socket(size_t fd){
|
||||
pcb[current_pid].sockets[fd].invalidate();
|
||||
}
|
||||
|
||||
bool scheduler::has_socket(size_t fd){
|
||||
return fd < pcb[current_pid].sockets.size() && pcb[current_pid].sockets[fd].is_valid();
|
||||
}
|
||||
|
||||
const network::socket& scheduler::get_socket(size_t fd){
|
||||
return pcb[current_pid].sockets[fd];
|
||||
}
|
||||
|
||||
const path& scheduler::get_working_directory(){
|
||||
return pcb[current_pid].working_directory;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user