From: Mikko Rasa Date: Sat, 14 Jan 2023 22:30:50 +0000 (+0200) Subject: Decorate things which constitute the public API X-Git-Url: http://git.tdb.fi/?p=libs%2Fnet.git;a=commitdiff_plain;h=394c9a732192fce9b3b453dfdb9e92400af2a4f8 Decorate things which constitute the public API --- diff --git a/source/http/client.h b/source/http/client.h index cd53f61..b1f097d 100644 --- a/source/http/client.h +++ b/source/http/client.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -14,7 +15,7 @@ namespace Http { class Request; class Response; -class Client +class MSPNET_API Client { public: sigc::signal signal_response_complete; diff --git a/source/http/formdata.h b/source/http/formdata.h index 3232891..cf78acd 100644 --- a/source/http/formdata.h +++ b/source/http/formdata.h @@ -3,13 +3,14 @@ #include #include +#include namespace Msp { namespace Http { class Request; -class FormData +class MSPNET_API FormData { private: std::map fields; diff --git a/source/http/header.h b/source/http/header.h index 0c6324b..1beb95f 100644 --- a/source/http/header.h +++ b/source/http/header.h @@ -4,13 +4,14 @@ #include #include #include +#include namespace Msp { namespace Http { class Message; -struct Header +struct MSPNET_API Header { enum Style { diff --git a/source/http/message.h b/source/http/message.h index 7984372..be2224d 100644 --- a/source/http/message.h +++ b/source/http/message.h @@ -4,12 +4,13 @@ #include #include #include +#include #include "version.h" namespace Msp { namespace Http { -class Message +class MSPNET_API Message { protected: typedef std::map HeaderMap; diff --git a/source/http/request.h b/source/http/request.h index 979c785..11af993 100644 --- a/source/http/request.h +++ b/source/http/request.h @@ -2,12 +2,13 @@ #define MSP_HTTP_REQUEST_H_ #include +#include #include "message.h" namespace Msp { namespace Http { -class Request: public Message +class MSPNET_API Request: public Message { private: std::string method; diff --git a/source/http/response.h b/source/http/response.h index f7c6812..8644b72 100644 --- a/source/http/response.h +++ b/source/http/response.h @@ -1,13 +1,14 @@ #ifndef MSP_HTTP_RESPONSE_H_ #define MSP_HTTP_RESPONSE_H_ +#include #include "message.h" #include "status.h" namespace Msp { namespace Http { -class Response: public Message +class MSPNET_API Response: public Message { private: Status status; diff --git a/source/http/server.h b/source/http/server.h index dd8b2c6..8665fa3 100644 --- a/source/http/server.h +++ b/source/http/server.h @@ -2,6 +2,7 @@ #define MSP_HTTP_SERVER_H_ #include +#include #include #include @@ -11,7 +12,7 @@ namespace Http { class Request; class Response; -class Server +class MSPNET_API Server { public: sigc::signal signal_request; diff --git a/source/http/status.h b/source/http/status.h index 5e7d54b..5f4656e 100644 --- a/source/http/status.h +++ b/source/http/status.h @@ -2,6 +2,7 @@ #define MSP_HTTPSERVER_STATUS_H_ #include +#include namespace Msp { namespace Http { @@ -20,7 +21,7 @@ enum Status NOT_IMPLEMENTED = 501 }; -extern std::ostream &operator<<(std::ostream &, Status); +MSPNET_API std::ostream &operator<<(std::ostream &, Status); } // namespace Http } // namespace Msp diff --git a/source/http/utils.h b/source/http/utils.h index a25a748..2920d2d 100644 --- a/source/http/utils.h +++ b/source/http/utils.h @@ -3,6 +3,7 @@ #include #include +#include namespace Msp { namespace Http { @@ -25,13 +26,13 @@ struct Url typedef std::map Query; -std::string urlencode(const std::string &, EncodeLevel =SAFE); -std::string urlencode_plus(const std::string &, EncodeLevel =SAFE); -std::string urldecode(const std::string &); -Url parse_url(const std::string &); -std::string build_url(const Url &); -Query parse_query(const std::string &); -std::string build_query(const Query &); +MSPNET_API std::string urlencode(const std::string &, EncodeLevel =SAFE); +MSPNET_API std::string urlencode_plus(const std::string &, EncodeLevel =SAFE); +MSPNET_API std::string urldecode(const std::string &); +MSPNET_API Url parse_url(const std::string &); +MSPNET_API std::string build_url(const Url &); +MSPNET_API Query parse_query(const std::string &); +MSPNET_API std::string build_query(const Query &); } // namespace Http } // namespace Msp diff --git a/source/http/version.h b/source/http/version.h index 19a50b9..665e619 100644 --- a/source/http/version.h +++ b/source/http/version.h @@ -2,14 +2,15 @@ #define MSP_HTTP_MISC_H_ #include +#include namespace Msp { namespace Http { typedef unsigned Version; -Version parse_version(const std::string &); -std::string version_str(Version); +MSPNET_API Version parse_version(const std::string &); +MSPNET_API std::string version_str(Version); } // namespace Http } // namespace Msp diff --git a/source/net/clientsocket.cpp b/source/net/clientsocket.cpp index 7987f4b..51a8dfa 100644 --- a/source/net/clientsocket.cpp +++ b/source/net/clientsocket.cpp @@ -74,6 +74,7 @@ size_t ClientSocket::do_read(char *buf, size_t size) if(!connected) throw bad_socket_state("not connected"); + // XXX This breaks level-triggered semantics on Windows if(size==0) return 0; diff --git a/source/net/clientsocket.h b/source/net/clientsocket.h index c33ed93..80d927a 100644 --- a/source/net/clientsocket.h +++ b/source/net/clientsocket.h @@ -1,6 +1,7 @@ #ifndef MSP_NET_CLIENTSOCKET_H_ #define MSP_NET_CLIENTSOCKET_H_ +#include "mspnet_api.h" #include "socket.h" namespace Msp { @@ -9,7 +10,7 @@ namespace Net { /** ClientSockets are used for sending and receiving data over the network. */ -class ClientSocket: public Socket +class MSPNET_API ClientSocket: public Socket { public: /** Emitted when the socket finishes connecting. */ diff --git a/source/net/communicator.h b/source/net/communicator.h index b98f488..e9f646a 100644 --- a/source/net/communicator.h +++ b/source/net/communicator.h @@ -4,6 +4,7 @@ #include #include #include +#include "mspnet_api.h" #include "protocol.h" namespace Msp { @@ -11,20 +12,20 @@ namespace Net { class StreamSocket; -class sequence_error: public invalid_state +class MSPNET_API sequence_error: public invalid_state { public: sequence_error(const std::string &w): invalid_state(w) { } }; -class incompatible_protocol: public std::runtime_error +class MSPNET_API incompatible_protocol: public std::runtime_error { public: incompatible_protocol(const std::string &w): std::runtime_error(w) { } }; -class Communicator: public NonCopyable +class MSPNET_API Communicator: public NonCopyable { public: sigc::signal signal_handshake_done; diff --git a/source/net/datagramsocket.h b/source/net/datagramsocket.h index e5ded78..a978b9f 100644 --- a/source/net/datagramsocket.h +++ b/source/net/datagramsocket.h @@ -2,11 +2,12 @@ #define MSP_NET_DATAGRAMSOCKET_H_ #include "clientsocket.h" +#include "mspnet_api.h" namespace Msp { namespace Net { -class DatagramSocket: public ClientSocket +class MSPNET_API DatagramSocket: public ClientSocket { public: DatagramSocket(Family, int = 0); diff --git a/source/net/inet.h b/source/net/inet.h index 517b111..fb76d7e 100644 --- a/source/net/inet.h +++ b/source/net/inet.h @@ -1,6 +1,7 @@ #ifndef MSP_NET_INET_H_ #define MSP_NET_INET_H_ +#include "mspnet_api.h" #include "sockaddr.h" namespace Msp { @@ -9,7 +10,7 @@ namespace Net { /** Address class for IPv4 sockets. */ -class InetAddr: public SockAddr +class MSPNET_API InetAddr: public SockAddr { private: unsigned char addr[4] = { }; diff --git a/source/net/inet6.h b/source/net/inet6.h index d4455e5..38cba33 100644 --- a/source/net/inet6.h +++ b/source/net/inet6.h @@ -1,12 +1,13 @@ #ifndef MSP_NET_INET6_H_ #define MSP_NET_INET6_H_ +#include "mspnet_api.h" #include "sockaddr.h" namespace Msp { namespace Net { -class Inet6Addr: public SockAddr +class MSPNET_API Inet6Addr: public SockAddr { private: unsigned char addr[16] = { }; diff --git a/source/net/mspnet_api.h b/source/net/mspnet_api.h new file mode 100644 index 0000000..eccdd41 --- /dev/null +++ b/source/net/mspnet_api.h @@ -0,0 +1,18 @@ +#ifndef MSP_NET_API_H_ +#define MSP_NET_API_H_ + +#if defined(_WIN32) +#if defined(MSPNET_BUILD) +#define MSPNET_API __declspec(dllexport) +#elif defined(MSPNET_IMPORT) +#define MSPNET_API __declspec(dllimport) +#else +#define MSPNET_API +#endif +#elif defined(__GNUC__) +#define MSPNET_API __attribute__((visibility("default"))) +#else +#define MSPNET_API +#endif + +#endif diff --git a/source/net/protocol.h b/source/net/protocol.h index f040a69..8068d32 100644 --- a/source/net/protocol.h +++ b/source/net/protocol.h @@ -7,26 +7,27 @@ #include #include #include +#include "mspnet_api.h" #include "receiver.h" namespace Msp { namespace Net { -class bad_packet: public std::runtime_error +class MSPNET_API bad_packet: public std::runtime_error { public: bad_packet(const std::string &w): std::runtime_error(w) { } }; -class buffer_error: public std::runtime_error +class MSPNET_API buffer_error: public std::runtime_error { public: buffer_error(const std::string &w): std::runtime_error(w) { } }; -class Protocol +class MSPNET_API Protocol { private: template diff --git a/source/net/receiver.h b/source/net/receiver.h index de7209e..9af1bb7 100644 --- a/source/net/receiver.h +++ b/source/net/receiver.h @@ -1,10 +1,12 @@ #ifndef MSP_NET_RECEIVER_H_ #define MSP_NET_RECEIVER_H_ +#include "mspnet_api.h" + namespace Msp { namespace Net { -class ReceiverBase +class MSPNET_API ReceiverBase { protected: ReceiverBase() = default; diff --git a/source/net/resolve.h b/source/net/resolve.h index 212a7f0..3071b77 100644 --- a/source/net/resolve.h +++ b/source/net/resolve.h @@ -9,6 +9,7 @@ #include #include #include +#include "mspnet_api.h" #include "sockaddr.h" namespace Msp { @@ -18,19 +19,19 @@ namespace Net { the loopback address will be used. If host is "*", the wildcard address will be used. If service is empty, a socket address with a null service will be returned. With the IP families, these are not very useful. */ -SockAddr *resolve(const std::string &, const std::string &, Family = UNSPEC); +MSPNET_API SockAddr *resolve(const std::string &, const std::string &, Family = UNSPEC); /** And overload of resolve() that takes host and service as a single string, separated by a colon. If the host part contains colons, such as is the case with a numeric IPv6 address, it must be enclosed in brackets. */ -SockAddr *resolve(const std::string &, Family = UNSPEC); +MSPNET_API SockAddr *resolve(const std::string &, Family = UNSPEC); /** An asynchronous name resolver. Blocking calls are performed in a thread and completion is notified with one of the two signals. */ -class Resolver +class MSPNET_API Resolver { private: struct Task diff --git a/source/net/serversocket.h b/source/net/serversocket.h index 48ab9ba..8c082b3 100644 --- a/source/net/serversocket.h +++ b/source/net/serversocket.h @@ -1,6 +1,7 @@ #ifndef MSP_NET_SERVERSOCKET_H_ #define MSP_NET_SERVERSOCKET_H_ +#include "mspnet_api.h" #include "socket.h" namespace Msp { @@ -12,7 +13,7 @@ class ClientSocket; ServerSockets are used to receive incoming connections. They cannot be used for sending and receiving data. */ -class ServerSocket: public Socket +class MSPNET_API ServerSocket: public Socket { protected: ServerSocket(Family, int, int); diff --git a/source/net/sockaddr.h b/source/net/sockaddr.h index 817de4d..931d4f4 100644 --- a/source/net/sockaddr.h +++ b/source/net/sockaddr.h @@ -2,6 +2,7 @@ #define MSP_NET_SOCKADDR_H_ #include +#include "mspnet_api.h" namespace Msp { namespace Net { @@ -15,7 +16,7 @@ enum Family }; -class SockAddr +class MSPNET_API SockAddr { public: struct SysAddr; diff --git a/source/net/socket.h b/source/net/socket.h index 3e3c2ae..b89c175 100644 --- a/source/net/socket.h +++ b/source/net/socket.h @@ -5,19 +5,20 @@ #include #include #include +#include "mspnet_api.h" #include "sockaddr.h" namespace Msp { namespace Net { -class bad_socket_state: public invalid_state +class MSPNET_API bad_socket_state: public invalid_state { public: bad_socket_state(const std::string &w): invalid_state(w) { } }; -class Socket: public IO::EventObject +class MSPNET_API Socket: public IO::EventObject { protected: enum SocketEvent diff --git a/source/net/streamserversocket.h b/source/net/streamserversocket.h index bd2487d..bbe1c91 100644 --- a/source/net/streamserversocket.h +++ b/source/net/streamserversocket.h @@ -1,13 +1,14 @@ #ifndef MSP_NET_STREAMSERVERSOCKET_H_ #define MSP_NET_STREAMSERVERSOCKET_H_ +#include "mspnet_api.h" #include "serversocket.h" #include "streamsocket.h" namespace Msp { namespace Net { -class StreamServerSocket: public ServerSocket +class MSPNET_API StreamServerSocket: public ServerSocket { private: bool listening = false; diff --git a/source/net/streamsocket.h b/source/net/streamsocket.h index 6f478d2..84b347d 100644 --- a/source/net/streamsocket.h +++ b/source/net/streamsocket.h @@ -2,11 +2,12 @@ #define MSP_NET_STREAMSOCKET_H_ #include "clientsocket.h" +#include "mspnet_api.h" namespace Msp { namespace Net { -class StreamSocket: public ClientSocket +class MSPNET_API StreamSocket: public ClientSocket { friend class StreamServerSocket; diff --git a/source/net/unix.h b/source/net/unix.h index a7431a9..86f1ddd 100644 --- a/source/net/unix.h +++ b/source/net/unix.h @@ -1,12 +1,13 @@ #ifndef MSP_NET_UNIX_H_ #define MSP_NET_UNIX_H_ +#include "mspnet_api.h" #include "sockaddr.h" namespace Msp { namespace Net { -class UnixAddr: public SockAddr +class MSPNET_API UnixAddr: public SockAddr { private: std::string path;