This commit is contained in:
Baptiste Wicht 2016-09-17 19:24:58 +02:00
parent 19c9d44690
commit 09c6002bc1

View File

@ -8,11 +8,13 @@
#include "tlib/net.hpp" #include "tlib/net.hpp"
#include "tlib/malloc.hpp" #include "tlib/malloc.hpp"
tlib::packet::packet() : fd(0), payload(nullptr), index(0) { tlib::packet::packet()
: fd(0), payload(nullptr), index(0) {
//Nothing else to init //Nothing else to init
} }
tlib::packet::packet(packet&& rhs) : fd(rhs.fd), payload(rhs.payload), index(rhs.index) { tlib::packet::packet(packet&& rhs)
: fd(rhs.fd), payload(rhs.payload), index(rhs.index) {
rhs.payload = nullptr; rhs.payload = nullptr;
} }
@ -125,7 +127,7 @@ std::expected<size_t> tlib::connect(size_t socket_fd, tlib::ip::address server,
int64_t code; int64_t code;
asm volatile("mov rax, 0x3008; mov rbx, %[socket]; mov rcx, %[ip]; mov rdx, %[port]; int 50; mov %[code], rax" asm volatile("mov rax, 0x3008; mov rbx, %[socket]; mov rcx, %[ip]; mov rdx, %[port]; int 50; mov %[code], rax"
: [code] "=m"(code) : [code] "=m"(code)
: [socket] "g" (socket_fd), [ip] "g" (size_t(server.raw_address)), [port] "g" (port) : [socket] "g"(socket_fd), [ip] "g"(size_t(server.raw_address)), [port] "g"(port)
: "rax", "rbx", "rcx", "rdx"); : "rax", "rbx", "rcx", "rdx");
if (code < 0) { if (code < 0) {
@ -139,7 +141,7 @@ std::expected<void> tlib::disconnect(size_t socket_fd) {
int64_t code; int64_t code;
asm volatile("mov rax, 0x3009; mov rbx, %[socket]; int 50; mov %[code], rax" asm volatile("mov rax, 0x3009; mov rbx, %[socket]; int 50; mov %[code], rax"
: [code] "=m"(code) : [code] "=m"(code)
: [socket] "g" (socket_fd) : [socket] "g"(socket_fd)
: "rax", "rbx"); : "rax", "rbx");
if (code < 0) { if (code < 0) {
@ -192,7 +194,7 @@ std::expected<tlib::packet> tlib::wait_for_packet(size_t socket_fd, size_t ms) {
} }
tlib::socket::socket(socket_domain domain, socket_type type, socket_protocol protocol) tlib::socket::socket(socket_domain domain, socket_type type, socket_protocol protocol)
: domain(domain), type(type), protocol(protocol), fd(0), error_code(0) { : domain(domain), type(type), protocol(protocol), fd(0), error_code(0) {
auto open_status = tlib::socket_open(domain, type, protocol); auto open_status = tlib::socket_open(domain, type, protocol);
if (open_status.valid()) { if (open_status.valid()) {
@ -205,7 +207,7 @@ tlib::socket::socket(socket_domain domain, socket_type type, socket_protocol pro
} }
tlib::socket::~socket() { tlib::socket::~socket() {
if(connected()){ if (connected()) {
disconnect(); disconnect();
} }
@ -281,13 +283,13 @@ void tlib::socket::disconnect() {
return; return;
} }
if(!connected()){ if (!connected()) {
return; return;
} }
auto status = tlib::disconnect(fd); auto status = tlib::disconnect(fd);
if(status){ if (status) {
_connected = false; _connected = false;
} else { } else {
error_code = status.error(); error_code = status.error();