-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SERVER-24080 Implement transport layer primitives
- Loading branch information
1 parent
a3fcc35
commit 6e4141c
Showing
7 changed files
with
229 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* Copyright (C) 2016 MongoDB Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* As a special exception, the copyright holders give permission to link the | ||
* code of portions of this program with the OpenSSL library under certain | ||
* conditions as described in each individual source file and distribute | ||
* linked combinations including the program with the OpenSSL library. You | ||
* must comply with the GNU Affero General Public License in all respects for | ||
* all of the code used other than as permitted herein. If you modify file(s) | ||
* with this exception, you may extend this exception to your version of the | ||
* file(s), but you are not obligated to do so. If you do not wish to do so, | ||
* delete this exception statement from your version. If you delete this | ||
* exception statement from all source files in the program, then also delete | ||
* it in the license file. | ||
*/ | ||
|
||
#include "mongo/platform/basic.h" | ||
|
||
#include "mongo/transport/session.h" | ||
|
||
#include "mongo/platform/atomic_word.h" | ||
#include "mongo/transport/transport_layer.h" | ||
|
||
namespace mongo { | ||
namespace transport { | ||
|
||
namespace { | ||
|
||
AtomicUInt64 sessionIdCounter(0); | ||
|
||
} // namespace | ||
|
||
Session::Session(HostAndPort remote, HostAndPort local, TransportLayer* tl) | ||
: _id(sessionIdCounter.addAndFetch(1)), _remote(remote), _local(local), _tl(tl) {} | ||
|
||
Session::~Session() { | ||
if (_tl != nullptr) { | ||
invariant(_tl); | ||
_tl->end(*this); | ||
} | ||
} | ||
|
||
Session::Session(Session&& other) | ||
: _id(other._id), | ||
_remote(std::move(other._remote)), | ||
_local(std::move(other._local)), | ||
_tl(other._tl) { | ||
// We do not want to call tl->end() on moved-from Sessions. | ||
other._tl = nullptr; | ||
} | ||
|
||
Session& Session::operator=(Session&& other) { | ||
_id = other._id; | ||
_remote = std::move(other._remote); | ||
_local = std::move(other._local); | ||
_tl = other._tl; | ||
_tl = nullptr; | ||
|
||
return *this; | ||
} | ||
|
||
Session::SessionId Session::id() const { | ||
return _id; | ||
} | ||
|
||
const HostAndPort& Session::remote() const { | ||
return _remote; | ||
} | ||
|
||
const HostAndPort& Session::local() const { | ||
return _local; | ||
} | ||
|
||
} // namespace transport | ||
} // namespace mongo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* Copyright (C) 2016 MongoDB Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* As a special exception, the copyright holders give permission to link the | ||
* code of portions of this program with the OpenSSL library under certain | ||
* conditions as described in each individual source file and distribute | ||
* linked combinations including the program with the OpenSSL library. You | ||
* must comply with the GNU Affero General Public License in all respects for | ||
* all of the code used other than as permitted herein. If you modify file(s) | ||
* with this exception, you may extend this exception to your version of the | ||
* file(s), but you are not obligated to do so. If you do not wish to do so, | ||
* delete this exception statement from your version. If you delete this | ||
* exception statement from all source files in the program, then also delete | ||
* it in the license file. | ||
*/ | ||
|
||
#include "mongo/platform/basic.h" | ||
|
||
#include "mongo/transport/ticket.h" | ||
#include "mongo/transport/ticket_impl.h" | ||
|
||
namespace mongo { | ||
namespace transport { | ||
|
||
const Date_t Ticket::kNoExpirationDate{Date_t::max()}; | ||
|
||
Ticket::Ticket(std::unique_ptr<TicketImpl> ticket) : _ticket(std::move(ticket)) {} | ||
|
||
Ticket::~Ticket() = default; | ||
|
||
Ticket::Ticket(Ticket&&) = default; | ||
Ticket& Ticket::operator=(Ticket&&) = default; | ||
|
||
Session::SessionId Ticket::sessionId() const { | ||
return _ticket->sessionId(); | ||
} | ||
|
||
Date_t Ticket::expiration() const { | ||
return _ticket->expiration(); | ||
} | ||
|
||
// TODO should this actually be const? | ||
TicketImpl* Ticket::impl() const { | ||
return _ticket.get(); | ||
} | ||
|
||
} // namespace transport | ||
} // namespace mongo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright (C) 2016 MongoDB Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* As a special exception, the copyright holders give permission to link the | ||
* code of portions of this program with the OpenSSL library under certain | ||
* conditions as described in each individual source file and distribute | ||
* linked combinations including the program with the OpenSSL library. You | ||
* must comply with the GNU Affero General Public License in all respects for | ||
* all of the code used other than as permitted herein. If you modify file(s) | ||
* with this exception, you may extend this exception to your version of the | ||
* file(s), but you are not obligated to do so. If you do not wish to do so, | ||
* delete this exception statement from your version. If you delete this | ||
* exception statement from all source files in the program, then also delete | ||
* it in the license file. | ||
*/ | ||
|
||
#include "mongo/platform/basic.h" | ||
|
||
#include "mongo/transport/transport_layer.h" | ||
|
||
namespace mongo { | ||
namespace transport { | ||
|
||
TransportLayer::TransportLayer() = default; | ||
TransportLayer::~TransportLayer() = default; | ||
|
||
TicketImpl* TransportLayer::getTicketImpl(const Ticket& ticket) { | ||
return ticket.impl(); | ||
} | ||
|
||
} // namespace transport | ||
} // namespace mongo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters