Remove all TRANTOR_EXPORT defines from core.

This commit is contained in:
Relintai 2022-02-10 09:52:56 +01:00
parent 482599541d
commit b8e0579a2a
7 changed files with 209 additions and 220 deletions

View File

@ -15,7 +15,6 @@
#pragma once #pragma once
#include "core/containers/task_queue.h" #include "core/containers/task_queue.h"
#include <trantor/exports.h>
#include <list> #include <list>
#include <memory> #include <memory>
#include <vector> #include <vector>
@ -29,7 +28,7 @@ namespace trantor
* can be called a threads pool. * can be called a threads pool.
* *
*/ */
class TRANTOR_EXPORT ConcurrentTaskQueue : public TaskQueue class ConcurrentTaskQueue : public TaskQueue
{ {
public: public:
/** /**

View File

@ -16,7 +16,6 @@
#include "task_queue.h" #include "task_queue.h"
#include "core/loops/event_loop_thread.h" #include "core/loops/event_loop_thread.h"
#include <trantor/exports.h>
#include <string> #include <string>
#include <queue> #include <queue>
#include <mutex> #include <mutex>
@ -28,7 +27,7 @@ namespace trantor
* by one. * by one.
* *
*/ */
class TRANTOR_EXPORT SerialTaskQueue : public TaskQueue class SerialTaskQueue : public TaskQueue
{ {
public: public:
/** /**

View File

@ -16,7 +16,6 @@
#include "core/loops/event_loop.h" #include "core/loops/event_loop.h"
#include "core/log/logger.h" #include "core/log/logger.h"
#include <trantor/exports.h>
#include <map> #include <map>
#include <mutex> #include <mutex>
#include <deque> #include <deque>
@ -42,7 +41,7 @@ using BucketQueue = std::deque<EntryBucket>;
* accuracy. This is usually used internally. * accuracy. This is usually used internally.
* *
*/ */
class TRANTOR_EXPORT TimingWheel class TimingWheel
{ {
public: public:
class CallbackEntry class CallbackEntry

View File

@ -6,7 +6,7 @@
// Author: Tao An // Author: Tao An
#pragma once #pragma once
#include <trantor/exports.h>
#include <memory> #include <memory>
#include "core/loops/event_loop.h" #include "core/loops/event_loop.h"
#include "core/net/inet_address.h" #include "core/net/inet_address.h"
@ -18,7 +18,7 @@ namespace trantor
* @note Although the c-ares library is not essential, it is recommended to * @note Although the c-ares library is not essential, it is recommended to
* install it for higher performance * install it for higher performance
*/ */
class TRANTOR_EXPORT Resolver class Resolver
{ {
public: public:
using Callback = std::function<void(const trantor::InetAddress&)>; using Callback = std::function<void(const trantor::InetAddress&)>;

View File

@ -17,14 +17,15 @@
// Author: Tao An // Author: Tao An
#pragma once #pragma once
#include "core/loops/event_loop.h" #include "core/loops/event_loop.h"
#include "core/net/inet_address.h" #include "core/net/inet_address.h"
#include "tcp_connection.h" #include "tcp_connection.h"
#include <trantor/exports.h>
#include <functional> #include <functional>
#include <thread> #include <thread>
#include <atomic> #include <atomic>
#include <signal.h> #include <signal.h>
namespace trantor namespace trantor
{ {
class Connector; class Connector;
@ -34,7 +35,7 @@ class SSLContext;
* @brief This class represents a TCP client. * @brief This class represents a TCP client.
* *
*/ */
class TRANTOR_EXPORT TcpClient : NonCopyable class TcpClient : NonCopyable
{ {
public: public:
/** /**

View File

@ -13,249 +13,241 @@
*/ */
#pragma once #pragma once
#include <trantor/exports.h>
#include "core/containers/msg_buffer.h"
#include "core/loops/callbacks.h"
#include "core/loops/event_loop.h" #include "core/loops/event_loop.h"
#include "core/net/inet_address.h" #include "core/net/inet_address.h"
#include <trantor/utils/NonCopyable.h> #include <trantor/utils/NonCopyable.h>
#include "core/containers/msg_buffer.h"
#include "core/loops/callbacks.h"
#include <memory>
#include <functional> #include <functional>
#include <memory>
#include <string> #include <string>
namespace trantor namespace trantor {
{
class SSLContext; class SSLContext;
TRANTOR_EXPORT std::shared_ptr<SSLContext> newSSLServerContext( std::shared_ptr<SSLContext> newSSLServerContext(
const std::string &certPath, const std::string &certPath,
const std::string &keyPath, const std::string &keyPath,
bool useOldTLS = false, bool useOldTLS = false,
const std::vector<std::pair<std::string, std::string>> &sslConfCmds = {}); const std::vector<std::pair<std::string, std::string> > &sslConfCmds = {});
/** /**
* @brief This class represents a TCP connection. * @brief This class represents a TCP connection.
* *
*/ */
class TRANTOR_EXPORT TcpConnection class TcpConnection {
{ public:
public: TcpConnection() = default;
TcpConnection() = default; virtual ~TcpConnection(){};
virtual ~TcpConnection(){};
/** /**
* @brief Send some data to the peer. * @brief Send some data to the peer.
* *
* @param msg * @param msg
* @param len * @param len
*/ */
virtual void send(const char *msg, size_t len) = 0; virtual void send(const char *msg, size_t len) = 0;
virtual void send(const void *msg, size_t len) = 0; virtual void send(const void *msg, size_t len) = 0;
virtual void send(const std::string &msg) = 0; virtual void send(const std::string &msg) = 0;
virtual void send(std::string &&msg) = 0; virtual void send(std::string &&msg) = 0;
virtual void send(const MsgBuffer &buffer) = 0; virtual void send(const MsgBuffer &buffer) = 0;
virtual void send(MsgBuffer &&buffer) = 0; virtual void send(MsgBuffer &&buffer) = 0;
virtual void send(const std::shared_ptr<std::string> &msgPtr) = 0; virtual void send(const std::shared_ptr<std::string> &msgPtr) = 0;
virtual void send(const std::shared_ptr<MsgBuffer> &msgPtr) = 0; virtual void send(const std::shared_ptr<MsgBuffer> &msgPtr) = 0;
/** /**
* @brief Send a file to the peer. * @brief Send a file to the peer.
* *
* @param fileName * @param fileName
* @param offset * @param offset
* @param length * @param length
*/ */
virtual void sendFile(const char *fileName, virtual void sendFile(const char *fileName,
size_t offset = 0, size_t offset = 0,
size_t length = 0) = 0; size_t length = 0) = 0;
/** /**
* @brief Get the local address of the connection. * @brief Get the local address of the connection.
* *
* @return const InetAddress& * @return const InetAddress&
*/ */
virtual const InetAddress &localAddr() const = 0; virtual const InetAddress &localAddr() const = 0;
/** /**
* @brief Get the remote address of the connection. * @brief Get the remote address of the connection.
* *
* @return const InetAddress& * @return const InetAddress&
*/ */
virtual const InetAddress &peerAddr() const = 0; virtual const InetAddress &peerAddr() const = 0;
/** /**
* @brief Return true if the connection is established. * @brief Return true if the connection is established.
* *
* @return true * @return true
* @return false * @return false
*/ */
virtual bool connected() const = 0; virtual bool connected() const = 0;
/** /**
* @brief Return false if the connection is established. * @brief Return false if the connection is established.
* *
* @return true * @return true
* @return false * @return false
*/ */
virtual bool disconnected() const = 0; virtual bool disconnected() const = 0;
/** /**
* @brief Get the buffer in which the received data stored. * @brief Get the buffer in which the received data stored.
* *
* @return MsgBuffer* * @return MsgBuffer*
*/ */
virtual MsgBuffer *getRecvBuffer() = 0; virtual MsgBuffer *getRecvBuffer() = 0;
/** /**
* @brief Set the high water mark callback * @brief Set the high water mark callback
* *
* @param cb The callback is called when the data in sending buffer is * @param cb The callback is called when the data in sending buffer is
* larger than the water mark. * larger than the water mark.
* @param markLen The water mark in bytes. * @param markLen The water mark in bytes.
*/ */
virtual void setHighWaterMarkCallback(const HighWaterMarkCallback &cb, virtual void setHighWaterMarkCallback(const HighWaterMarkCallback &cb,
size_t markLen) = 0; size_t markLen) = 0;
/** /**
* @brief Set the TCP_NODELAY option to the socket. * @brief Set the TCP_NODELAY option to the socket.
* *
* @param on * @param on
*/ */
virtual void setTcpNoDelay(bool on) = 0; virtual void setTcpNoDelay(bool on) = 0;
/** /**
* @brief Shutdown the connection. * @brief Shutdown the connection.
* @note This method only closes the writing direction. * @note This method only closes the writing direction.
*/ */
virtual void shutdown() = 0; virtual void shutdown() = 0;
/** /**
* @brief Close the connection forcefully. * @brief Close the connection forcefully.
* *
*/ */
virtual void forceClose() = 0; virtual void forceClose() = 0;
/** /**
* @brief Get the event loop in which the connection I/O is handled. * @brief Get the event loop in which the connection I/O is handled.
* *
* @return EventLoop* * @return EventLoop*
*/ */
virtual EventLoop *getLoop() = 0; virtual EventLoop *getLoop() = 0;
/** /**
* @brief Set the custom data on the connection. * @brief Set the custom data on the connection.
* *
* @param context * @param context
*/ */
void setContext(const std::shared_ptr<void> &context) void setContext(const std::shared_ptr<void> &context) {
{ contextPtr_ = context;
contextPtr_ = context; }
} void setContext(std::shared_ptr<void> &&context) {
void setContext(std::shared_ptr<void> &&context) contextPtr_ = std::move(context);
{ }
contextPtr_ = std::move(context);
}
/** /**
* @brief Get the custom data from the connection. * @brief Get the custom data from the connection.
* *
* @tparam T * @tparam T
* @return std::shared_ptr<T> * @return std::shared_ptr<T>
*/ */
template <typename T> template <typename T>
std::shared_ptr<T> getContext() const std::shared_ptr<T> getContext() const {
{ return std::static_pointer_cast<T>(contextPtr_);
return std::static_pointer_cast<T>(contextPtr_); }
}
/** /**
* @brief Return true if the custom data is set by user. * @brief Return true if the custom data is set by user.
* *
* @return true * @return true
* @return false * @return false
*/ */
bool hasContext() const bool hasContext() const {
{ return (bool)contextPtr_;
return (bool)contextPtr_; }
}
/** /**
* @brief Clear the custom data. * @brief Clear the custom data.
* *
*/ */
void clearContext() void clearContext() {
{ contextPtr_.reset();
contextPtr_.reset(); }
}
/** /**
* @brief Call this method to avoid being kicked off by TcpServer, refer to * @brief Call this method to avoid being kicked off by TcpServer, refer to
* the kickoffIdleConnections method in the TcpServer class. * the kickoffIdleConnections method in the TcpServer class.
* *
*/ */
virtual void keepAlive() = 0; virtual void keepAlive() = 0;
/** /**
* @brief Return true if the keepAlive() method is called. * @brief Return true if the keepAlive() method is called.
* *
* @return true * @return true
* @return false * @return false
*/ */
virtual bool isKeepAlive() = 0; virtual bool isKeepAlive() = 0;
/** /**
* @brief Return the number of bytes sent * @brief Return the number of bytes sent
* *
* @return size_t * @return size_t
*/ */
virtual size_t bytesSent() const = 0; virtual size_t bytesSent() const = 0;
/** /**
* @brief Return the number of bytes received. * @brief Return the number of bytes received.
* *
* @return size_t * @return size_t
*/ */
virtual size_t bytesReceived() const = 0; virtual size_t bytesReceived() const = 0;
/** /**
* @brief Check whether the connection is SSL encrypted. * @brief Check whether the connection is SSL encrypted.
* *
* @return true * @return true
* @return false * @return false
*/ */
virtual bool isSSLConnection() const = 0; virtual bool isSSLConnection() const = 0;
/** /**
* @brief Start the SSL encryption on the connection (as a client). * @brief Start the SSL encryption on the connection (as a client).
* *
* @param callback The callback is called when the SSL connection is * @param callback The callback is called when the SSL connection is
* established. * established.
* @param hostname The server hostname for SNI. If it is empty, the SNI is * @param hostname The server hostname for SNI. If it is empty, the SNI is
* not used. * not used.
* @param sslConfCmds The commands used to call the SSL_CONF_cmd function in * @param sslConfCmds The commands used to call the SSL_CONF_cmd function in
* OpenSSL. * OpenSSL.
*/ */
virtual void startClientEncryption( virtual void startClientEncryption(
std::function<void()> callback, std::function<void()> callback,
bool useOldTLS = false, bool useOldTLS = false,
bool validateCert = true, bool validateCert = true,
std::string hostname = "", std::string hostname = "",
const std::vector<std::pair<std::string, std::string>> &sslConfCmds = const std::vector<std::pair<std::string, std::string> > &sslConfCmds = {}) = 0;
{}) = 0;
/** /**
* @brief Start the SSL encryption on the connection (as a server). * @brief Start the SSL encryption on the connection (as a server).
* *
* @param ctx The SSL context. * @param ctx The SSL context.
* @param callback The callback is called when the SSL connection is * @param callback The callback is called when the SSL connection is
* established. * established.
*/ */
virtual void startServerEncryption(const std::shared_ptr<SSLContext> &ctx, virtual void startServerEncryption(const std::shared_ptr<SSLContext> &ctx,
std::function<void()> callback) = 0; std::function<void()> callback) = 0;
protected: protected:
bool validateCert_ = false; bool validateCert_ = false;
private: private:
std::shared_ptr<void> contextPtr_; std::shared_ptr<void> contextPtr_;
}; };
} // namespace trantor } // namespace trantor

View File

@ -20,7 +20,6 @@
#include "core/net/inet_address.h" #include "core/net/inet_address.h"
#include "core/net/tcp_connection.h" #include "core/net/tcp_connection.h"
#include "core/loops/timing_wheel.h" #include "core/loops/timing_wheel.h"
#include <trantor/exports.h>
#include <string> #include <string>
#include <memory> #include <memory>
#include <set> #include <set>
@ -33,7 +32,7 @@ class SSLContext;
* @brief This class represents a TCP server. * @brief This class represents a TCP server.
* *
*/ */
class TRANTOR_EXPORT TcpServer : NonCopyable class TcpServer : NonCopyable
{ {
public: public:
/** /**