/*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2015-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <folly/portability/Sockets.h>
#include <boost/scoped_array.hpp>
+#include <memory>
enum StateEnum {
STATE_WAITING,
}
StateEnum state;
- size_t bytesWritten;
+ std::atomic<size_t> bytesWritten;
folly::AsyncSocketException exception;
VoidCallback successCallback;
VoidCallback errorCallback;
buffers(),
maxBufferSz(_maxBufferSz) {}
- ~ReadCallback() {
+ ~ReadCallback() override {
for (std::vector<Buffer>::iterator it = buffers.begin();
it != buffers.end();
++it) {
class ReadVerifier {
};
-class TestErrMessageCallback : public folly::AsyncSocket::ErrMessageCallback {
- public:
- TestErrMessageCallback()
- : exception_(folly::AsyncSocketException::UNKNOWN, "none")
- {}
-
- void errMessage(const cmsghdr& cmsg) noexcept override {
- if (cmsg.cmsg_level == SOL_SOCKET &&
- cmsg.cmsg_type == SCM_TIMESTAMPING) {
- gotTimestamp_++;
- checkResetCallback();
- } else if (
- (cmsg.cmsg_level == SOL_IP && cmsg.cmsg_type == IP_RECVERR) ||
- (cmsg.cmsg_level == SOL_IPV6 && cmsg.cmsg_type == IPV6_RECVERR)) {
- gotByteSeq_++;
- checkResetCallback();
- }
- }
-
- void errMessageError(
- const folly::AsyncSocketException& ex) noexcept override {
- exception_ = ex;
- }
-
- void checkResetCallback() noexcept {
- if (socket_ != nullptr && resetAfter_ != -1 &&
- gotTimestamp_ + gotByteSeq_ == resetAfter_) {
- socket_->setErrMessageCB(nullptr);
- }
- }
-
- folly::AsyncSocket* socket_{nullptr};
- folly::AsyncSocketException exception_;
- int gotTimestamp_{0};
- int gotByteSeq_{0};
- int resetAfter_{-1};
-};
-
class TestSendMsgParamsCallback :
public folly::AsyncSocket::SendMsgParamsCallback {
public:
std::shared_ptr<BlockingSocket> accept(int timeout=50) {
int fd = acceptFD(timeout);
- return std::shared_ptr<BlockingSocket>(new BlockingSocket(fd));
+ return std::make_shared<BlockingSocket>(fd);
}
std::shared_ptr<folly::AsyncSocket> acceptAsync(folly::EventBase* evb,