system/FileDescriptor: add "noexcept"

This commit is contained in:
Max Kellermann 2018-08-20 16:34:47 +02:00
parent 2156fc64f4
commit a65d02d3ae
3 changed files with 20 additions and 19 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2012-2017 Max Kellermann <max.kellermann@gmail.com> * Copyright 2012-2018 Max Kellermann <max.kellermann@gmail.com>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2012-2017 Max Kellermann <max.kellermann@gmail.com> * Copyright 2012-2018 Max Kellermann <max.kellermann@gmail.com>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -59,13 +59,13 @@ protected:
public: public:
FileDescriptor() = default; FileDescriptor() = default;
explicit constexpr FileDescriptor(int _fd):fd(_fd) {} explicit constexpr FileDescriptor(int _fd) noexcept:fd(_fd) {}
constexpr bool operator==(FileDescriptor other) const { constexpr bool operator==(FileDescriptor other) const noexcept {
return fd == other.fd; return fd == other.fd;
} }
constexpr bool IsDefined() const { constexpr bool IsDefined() const noexcept {
return fd >= 0; return fd >= 0;
} }
@ -93,7 +93,7 @@ public:
* Returns the file descriptor. This may only be called if * Returns the file descriptor. This may only be called if
* IsDefined() returns true. * IsDefined() returns true.
*/ */
constexpr int Get() const { constexpr int Get() const noexcept {
return fd; return fd;
} }
@ -109,7 +109,7 @@ public:
fd = -1; fd = -1;
} }
static constexpr FileDescriptor Undefined() { static constexpr FileDescriptor Undefined() noexcept {
return FileDescriptor(-1); return FileDescriptor(-1);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2012-2017 Max Kellermann <max.kellermann@gmail.com> * Copyright 2012-2018 Max Kellermann <max.kellermann@gmail.com>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -39,25 +39,26 @@
*/ */
class UniqueFileDescriptor : protected FileDescriptor { class UniqueFileDescriptor : protected FileDescriptor {
public: public:
UniqueFileDescriptor():FileDescriptor(FileDescriptor::Undefined()) {} UniqueFileDescriptor() noexcept
:FileDescriptor(FileDescriptor::Undefined()) {}
protected: protected:
explicit UniqueFileDescriptor(int _fd):FileDescriptor(_fd) { explicit UniqueFileDescriptor(int _fd) noexcept:FileDescriptor(_fd) {
assert(IsDefined()); assert(IsDefined());
} }
public: public:
explicit UniqueFileDescriptor(FileDescriptor _fd) explicit UniqueFileDescriptor(FileDescriptor _fd) noexcept
:FileDescriptor(_fd) {} :FileDescriptor(_fd) {}
UniqueFileDescriptor(UniqueFileDescriptor &&other) UniqueFileDescriptor(UniqueFileDescriptor &&other) noexcept
:FileDescriptor(other.Steal()) {} :FileDescriptor(other.Steal()) {}
~UniqueFileDescriptor() { ~UniqueFileDescriptor() noexcept {
Close(); Close();
} }
UniqueFileDescriptor &operator=(UniqueFileDescriptor &&other) { UniqueFileDescriptor &operator=(UniqueFileDescriptor &&other) noexcept {
std::swap(fd, other.fd); std::swap(fd, other.fd);
return *this; return *this;
} }
@ -65,7 +66,7 @@ public:
/** /**
* Convert this object to its #FileDescriptor base type. * Convert this object to its #FileDescriptor base type.
*/ */
const FileDescriptor &ToFileDescriptor() const { const FileDescriptor &ToFileDescriptor() const noexcept {
return *this; return *this;
} }
@ -77,7 +78,7 @@ public:
using FileDescriptor::Steal; using FileDescriptor::Steal;
protected: protected:
void Set(int _fd) { void Set(int _fd) noexcept {
assert(!IsDefined()); assert(!IsDefined());
assert(_fd >= 0); assert(_fd >= 0);
@ -91,7 +92,7 @@ public:
#ifndef _WIN32 #ifndef _WIN32
using FileDescriptor::OpenNonBlocking; using FileDescriptor::OpenNonBlocking;
static bool CreatePipe(UniqueFileDescriptor &r, UniqueFileDescriptor &w) { static bool CreatePipe(UniqueFileDescriptor &r, UniqueFileDescriptor &w) noexcept {
return FileDescriptor::CreatePipe(r, w); return FileDescriptor::CreatePipe(r, w);
} }
@ -100,7 +101,7 @@ public:
using FileDescriptor::Duplicate; using FileDescriptor::Duplicate;
using FileDescriptor::CheckDuplicate; using FileDescriptor::CheckDuplicate;
static bool CreatePipe(FileDescriptor &r, FileDescriptor &w); static bool CreatePipe(FileDescriptor &r, FileDescriptor &w) noexcept;
#endif #endif
using FileDescriptor::EnableCloseOnExec; using FileDescriptor::EnableCloseOnExec;
@ -118,7 +119,7 @@ public:
using FileDescriptor::CreateInotify; using FileDescriptor::CreateInotify;
#endif #endif
bool Close() { bool Close() noexcept {
return IsDefined() && FileDescriptor::Close(); return IsDefined() && FileDescriptor::Close();
} }