clang format, based on cpprest

This commit is contained in:
Benjamin Sergeant
2019-05-30 08:46:50 -07:00
parent 5bad02ccae
commit c6dfb14953
47 changed files with 426 additions and 414 deletions

View File

@ -6,14 +6,13 @@
#pragma once
#include <functional>
#include <atomic>
#include <functional>
namespace ix
{
using CancellationRequest = std::function<bool()>;
CancellationRequest makeCancellationRequestWithTimeout(int seconds,
std::atomic<bool>& requestInitCancellation);
}
CancellationRequest makeCancellationRequestWithTimeout(
int seconds, std::atomic<bool>& requestInitCancellation);
} // namespace ix

View File

@ -6,14 +6,15 @@
#pragma once
#include <stdint.h>
#include <string>
#include <atomic>
#include <memory>
#include <stdint.h>
#include <string>
namespace ix
{
class ConnectionState {
class ConnectionState
{
public:
ConnectionState();
virtual ~ConnectionState() = default;
@ -32,6 +33,4 @@ namespace ix
static std::atomic<uint64_t> _globalId;
};
}
} // namespace ix

View File

@ -11,22 +11,20 @@
#pragma once
#include "IXCancellationRequest.h"
#include <string>
#include <thread>
#include <atomic>
#include <condition_variable>
#include <set>
#include <string>
#include <thread>
struct addrinfo;
namespace ix
{
class DNSLookup {
class DNSLookup
{
public:
DNSLookup(const std::string& hostname,
int port,
int64_t wait = DNSLookup::kDefaultWait);
DNSLookup(const std::string& hostname, int port, int64_t wait = DNSLookup::kDefaultWait);
~DNSLookup();
struct addrinfo* resolve(std::string& errMsg,
@ -78,4 +76,4 @@ namespace ix
const static int64_t kDefaultWait;
};
}
} // namespace ix

View File

@ -6,39 +6,38 @@
#pragma once
#include <algorithm>
#include <functional>
#include <mutex>
#include <atomic>
#include <tuple>
#include <memory>
#include <map>
#include "IXSocket.h"
#include "IXWebSocketHttpHeaders.h"
#include <algorithm>
#include <atomic>
#include <functional>
#include <map>
#include <memory>
#include <mutex>
#include <tuple>
namespace ix
{
enum class HttpErrorCode : int
{
Ok = 0,
CannotConnect = 1,
Timeout = 2,
Gzip = 3,
UrlMalformed = 4,
CannotCreateSocket = 5,
SendError = 6,
ReadError = 7,
CannotReadStatusLine = 8,
MissingStatus = 9,
HeaderParsingError = 10,
MissingLocation = 11,
TooManyRedirects = 12,
ChunkReadError = 13,
CannotReadBody = 14
Ok = 0,
CannotConnect = 1,
Timeout = 2,
Gzip = 3,
UrlMalformed = 4,
CannotCreateSocket = 5,
SendError = 6,
ReadError = 7,
CannotReadStatusLine = 8,
MissingStatus = 9,
HeaderParsingError = 10,
MissingLocation = 11,
TooManyRedirects = 12,
ChunkReadError = 13,
CannotReadBody = 14
};
using HttpResponse = std::tuple<int, // status
using HttpResponse = std::tuple<int, // status
HttpErrorCode, // error code
WebSocketHttpHeaders,
std::string, // payload
@ -64,15 +63,14 @@ namespace ix
OnProgressCallback onProgressCallback;
};
class HttpClient {
class HttpClient
{
public:
HttpClient();
~HttpClient();
HttpResponse get(const std::string& url,
const HttpRequestArgs& args);
HttpResponse head(const std::string& url,
const HttpRequestArgs& args);
HttpResponse get(const std::string& url, const HttpRequestArgs& args);
HttpResponse head(const std::string& url, const HttpRequestArgs& args);
HttpResponse post(const std::string& url,
const HttpParameters& httpParameters,
@ -94,9 +92,7 @@ namespace ix
void log(const std::string& msg, const HttpRequestArgs& args);
bool gzipInflate(
const std::string& in,
std::string& out);
bool gzipInflate(const std::string& in, std::string& out);
std::shared_ptr<Socket> _socket;
@ -104,4 +100,4 @@ namespace ix
const static std::string kGet;
const static std::string kHead;
};
}
} // namespace ix

View File

@ -7,25 +7,25 @@
#pragma once
#ifdef _WIN32
# include <WS2tcpip.h>
# include <WinSock2.h>
# include <basetsd.h>
# include <io.h>
# include <ws2def.h>
#include <WS2tcpip.h>
#include <WinSock2.h>
#include <basetsd.h>
#include <io.h>
#include <ws2def.h>
#else
# include <arpa/inet.h>
# include <errno.h>
# include <netdb.h>
# include <netinet/tcp.h>
# include <sys/select.h>
# include <sys/socket.h>
# include <sys/stat.h>
# include <sys/time.h>
# include <unistd.h>
#include <arpa/inet.h>
#include <errno.h>
#include <netdb.h>
#include <netinet/tcp.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <unistd.h>
#endif
namespace ix
{
bool initNetSystem();
bool uninitNetSystem();
}
} // namespace ix

View File

@ -11,7 +11,8 @@
namespace ix
{
class SelectInterrupt {
class SelectInterrupt
{
public:
SelectInterrupt();
virtual ~SelectInterrupt();
@ -23,6 +24,4 @@ namespace ix
virtual uint64_t read();
virtual int getFd() const;
};
}
} // namespace ix

View File

@ -7,13 +7,13 @@
#pragma once
#include "IXSelectInterrupt.h"
#include <stdint.h>
#include <string>
namespace ix
{
class SelectInterruptEventFd final : public SelectInterrupt {
class SelectInterruptEventFd final : public SelectInterrupt
{
public:
SelectInterruptEventFd();
virtual ~SelectInterruptEventFd();
@ -28,5 +28,4 @@ namespace ix
private:
int _eventfd;
};
}
} // namespace ix

View File

@ -12,4 +12,4 @@ namespace ix
{
class SelectInterrupt;
std::shared_ptr<SelectInterrupt> createSelectInterrupt();
}
} // namespace ix

View File

@ -7,14 +7,14 @@
#pragma once
#include "IXSelectInterrupt.h"
#include <mutex>
#include <stdint.h>
#include <string>
#include <mutex>
namespace ix
{
class SelectInterruptPipe final : public SelectInterrupt {
class SelectInterruptPipe final : public SelectInterrupt
{
public:
SelectInterruptPipe();
virtual ~SelectInterruptPipe();
@ -37,5 +37,4 @@ namespace ix
static const int kPipeReadIndex;
static const int kPipeWriteIndex;
};
}
} // namespace ix

View File

@ -10,4 +10,3 @@ namespace ix
{
void setThreadName(const std::string& name);
}

View File

@ -6,12 +6,12 @@
#pragma once
#include <string>
#include <functional>
#include <mutex>
#include <atomic>
#include <vector>
#include <functional>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
#ifdef _WIN32
#include <BaseTsd.h>
@ -24,11 +24,11 @@ typedef SSIZE_T ssize_t;
#undef EINVAL
// map to WSA error codes
#define EWOULDBLOCK WSAEWOULDBLOCK
#define EAGAIN WSATRY_AGAIN
#define EINPROGRESS WSAEINPROGRESS
#define EBADF WSAEBADF
#define EINVAL WSAEINVAL
#define EWOULDBLOCK WSAEWOULDBLOCK
#define EAGAIN WSATRY_AGAIN
#define EINPROGRESS WSAEINPROGRESS
#define EBADF WSAEBADF
#define EINVAL WSAEINVAL
#endif
@ -41,15 +41,16 @@ namespace ix
enum class PollResultType
{
ReadyForRead = 0,
ReadyForWrite = 1,
Timeout = 2,
Error = 3,
SendRequest = 4,
CloseRequest = 5
ReadyForRead = 0,
ReadyForWrite = 1,
Timeout = 2,
Error = 3,
SendRequest = 4,
CloseRequest = 5
};
class Socket {
class Socket
{
public:
Socket(int fd = -1);
virtual ~Socket();
@ -75,17 +76,13 @@ namespace ix
// Blocking and cancellable versions, working with socket that can be set
// to non blocking mode. Used during HTTP upgrade.
bool readByte(void* buffer,
const CancellationRequest& isCancellationRequested);
bool writeBytes(const std::string& str,
const CancellationRequest& isCancellationRequested);
bool readByte(void* buffer, const CancellationRequest& isCancellationRequested);
bool writeBytes(const std::string& str, const CancellationRequest& isCancellationRequested);
std::pair<bool, std::string> readLine(
const CancellationRequest& isCancellationRequested);
std::pair<bool, std::string> readBytes(
size_t length,
const OnProgressCallback& onProgressCallback,
const CancellationRequest& isCancellationRequested);
std::pair<bool, std::string> readLine(const CancellationRequest& isCancellationRequested);
std::pair<bool, std::string> readBytes(size_t length,
const OnProgressCallback& onProgressCallback,
const CancellationRequest& isCancellationRequested);
static int getErrno();
static bool isWaitNeeded();
@ -111,4 +108,4 @@ namespace ix
std::shared_ptr<SelectInterrupt> _selectInterrupt;
};
}
} // namespace ix

View File

@ -6,12 +6,10 @@
#pragma once
#include "IXSocket.h"
#include "IXCancellationRequest.h"
#include <Security/Security.h>
#include "IXSocket.h"
#include <Security/SecureTransport.h>
#include <Security/Security.h>
#include <mutex>
namespace ix
@ -34,7 +32,7 @@ namespace ix
private:
SSLContextRef _sslContext;
mutable std::mutex _mutex; // AppleSSL routines are not thread-safe
mutable std::mutex _mutex; // AppleSSL routines are not thread-safe
};
}
} // namespace ix

View File

@ -7,14 +7,14 @@
#pragma once
#include "IXCancellationRequest.h"
#include <string>
struct addrinfo;
namespace ix
{
class SocketConnect {
class SocketConnect
{
public:
static int connect(const std::string& hostname,
int port,
@ -24,9 +24,8 @@ namespace ix
static void configure(int sockfd);
private:
static int connectToAddress(const struct addrinfo *address,
static int connectToAddress(const struct addrinfo* address,
std::string& errMsg,
const CancellationRequest& isCancellationRequested);
};
}
} // namespace ix

View File

@ -13,9 +13,7 @@
namespace ix
{
class Socket;
std::shared_ptr<Socket> createSocket(bool tls,
std::string& errorMsg);
std::shared_ptr<Socket> createSocket(bool tls, std::string& errorMsg);
std::shared_ptr<Socket> createSocket(int fd,
std::string& errorMsg);
}
std::shared_ptr<Socket> createSocket(int fd, std::string& errorMsg);
} // namespace ix

View File

@ -6,17 +6,15 @@
#pragma once
#include "IXSocket.h"
#include "IXCancellationRequest.h"
#include "IXSocket.h"
#include <mutex>
#include <openssl/bio.h>
#include <openssl/hmac.h>
#include <openssl/conf.h>
#include <openssl/err.h>
#include <openssl/hmac.h>
#include <openssl/ssl.h>
#include <mutex>
namespace ix
{
class SocketOpenSSL final : public Socket
@ -40,18 +38,16 @@ namespace ix
std::string getSSLError(int ret);
SSL_CTX* openSSLCreateContext(std::string& errMsg);
bool openSSLHandshake(const std::string& hostname, std::string& errMsg);
bool openSSLCheckServerCert(SSL *ssl,
const std::string& hostname,
std::string& errMsg);
bool checkHost(const std::string& host, const char *pattern);
bool openSSLCheckServerCert(SSL* ssl, const std::string& hostname, std::string& errMsg);
bool checkHost(const std::string& host, const char* pattern);
SSL* _ssl_connection;
SSL_CTX* _ssl_context;
const SSL_METHOD* _ssl_method;
mutable std::mutex _mutex; // OpenSSL routines are not thread-safe
mutable std::mutex _mutex; // OpenSSL routines are not thread-safe
static std::once_flag _openSSLInitFlag;
static std::atomic<bool> _openSSLInitializationSuccessful;
};
}
} // namespace ix

View File

@ -16,9 +16,7 @@ namespace ix
SocketSChannel();
~SocketSChannel();
virtual bool connect(const std::string& host,
int port,
std::string& errMsg) final;
virtual bool connect(const std::string& host, int port, std::string& errMsg) final;
virtual void close() final;
// The important override
@ -31,4 +29,4 @@ namespace ix
private:
};
}
} // namespace ix

View File

@ -7,28 +7,28 @@
#pragma once
#include "IXConnectionState.h"
#include <utility> // pair
#include <string>
#include <set>
#include <thread>
#include <list>
#include <mutex>
#include <functional>
#include <memory>
#include <atomic>
#include <condition_variable>
#include <functional>
#include <list>
#include <memory>
#include <mutex>
#include <set>
#include <string>
#include <thread>
#include <utility> // pair
namespace ix
{
class SocketServer {
class SocketServer
{
public:
using ConnectionStateFactory = std::function<std::shared_ptr<ConnectionState>()>;
// Each connection is handled by its own worker thread.
// We use a list as we only care about remove and append operations.
using ConnectionThreads = std::list<std::pair<std::shared_ptr<ConnectionState>,
std::thread>>;
using ConnectionThreads =
std::list<std::pair<std::shared_ptr<ConnectionState>, std::thread>>;
SocketServer(int port = SocketServer::kDefaultPort,
const std::string& host = SocketServer::kDefaultHost,
@ -52,7 +52,6 @@ namespace ix
void wait();
protected:
// Logging
void logError(const std::string& str);
void logInfo(const std::string& str);
@ -93,12 +92,11 @@ namespace ix
// the factory to create ConnectionState objects
ConnectionStateFactory _connectionStateFactory;
virtual void handleConnection(int fd,
std::shared_ptr<ConnectionState> connectionState) = 0;
virtual void handleConnection(int fd, std::shared_ptr<ConnectionState> connectionState) = 0;
virtual size_t getConnectedClientsCount() = 0;
// Returns true if all connection threads are joined
void closeTerminatedThreads();
size_t getConnectionsThreadsCount();
};
}
} // namespace ix

View File

@ -20,4 +20,4 @@ namespace ix
std::string& query,
int& port);
};
}
} // namespace ix

View File

@ -9,39 +9,38 @@
#pragma once
#include "IXProgressCallback.h"
#include "IXWebSocketCloseConstants.h"
#include "IXWebSocketErrorInfo.h"
#include "IXWebSocketHttpHeaders.h"
#include "IXWebSocketPerMessageDeflateOptions.h"
#include "IXWebSocketSendInfo.h"
#include "IXWebSocketTransport.h"
#include <atomic>
#include <mutex>
#include <string>
#include <thread>
#include <mutex>
#include <atomic>
#include "IXWebSocketTransport.h"
#include "IXWebSocketErrorInfo.h"
#include "IXWebSocketSendInfo.h"
#include "IXWebSocketPerMessageDeflateOptions.h"
#include "IXWebSocketHttpHeaders.h"
#include "IXWebSocketCloseConstants.h"
#include "IXProgressCallback.h"
namespace ix
{
// https://developer.mozilla.org/en-US/docs/Web/API/WebSocket#Ready_state_constants
enum class ReadyState
{
Connecting = 0,
Open = 1,
Closing = 2,
Closed = 3
Connecting = 0,
Open = 1,
Closing = 2,
Closed = 3
};
enum class WebSocketMessageType
{
Message = 0,
Open = 1,
Close = 2,
Error = 3,
Ping = 4,
Pong = 5,
Fragment = 6
Message = 0,
Open = 1,
Close = 2,
Error = 3,
Ping = 4,
Pong = 5,
Fragment = 6
};
struct WebSocketOpenInfo
@ -64,9 +63,7 @@ namespace ix
std::string reason;
bool remote;
WebSocketCloseInfo(uint16_t c = 0,
const std::string& r = std::string(),
bool rem = false)
WebSocketCloseInfo(uint16_t c = 0, const std::string& r = std::string(), bool rem = false)
: code(c)
, reason(r)
, remote(rem)
@ -91,7 +88,8 @@ namespace ix
~WebSocket();
void setUrl(const std::string& url);
void setPerMessageDeflateOptions(const WebSocketPerMessageDeflateOptions& perMessageDeflateOptions);
void setPerMessageDeflateOptions(
const WebSocketPerMessageDeflateOptions& perMessageDeflateOptions);
void setHeartBeatPeriod(int heartBeatPeriodSecs);
void setPingInterval(int pingIntervalSecs); // alias of setHeartBeatPeriod
void setPingTimeout(int pingTimeoutSecs);
@ -116,8 +114,7 @@ namespace ix
const OnProgressCallback& onProgressCallback = nullptr);
WebSocketSendInfo ping(const std::string& text);
void close(uint16_t code = 1000,
const std::string& reason = "Normal closure");
void close(uint16_t code = 1000, const std::string& reason = "Normal closure");
void setOnMessageCallback(const OnMessageCallback& callback);
static void setTrafficTrackerCallback(const OnTrafficTrackerCallback& callback);
@ -138,7 +135,6 @@ namespace ix
bool isAutomaticReconnectionEnabled() const;
private:
WebSocketSendInfo sendMessage(const std::string& text,
SendMessageKind sendMessageKind,
const OnProgressCallback& callback = nullptr);
@ -180,4 +176,4 @@ namespace ix
friend class WebSocketServer;
};
}
} // namespace ix

View File

@ -26,4 +26,4 @@ namespace ix
static const std::string kProtocolErrorMessage;
static const std::string kNoStatusCodeErrorMessage;
};
}
} // namespace ix

View File

@ -18,4 +18,4 @@ namespace ix
std::string reason;
bool decompressionError = false;
};
}
} // namespace ix

View File

@ -7,15 +7,14 @@
#pragma once
#include "IXCancellationRequest.h"
#include "IXSocket.h"
#include "IXWebSocketHttpHeaders.h"
#include "IXWebSocketPerMessageDeflate.h"
#include "IXWebSocketPerMessageDeflateOptions.h"
#include "IXSocket.h"
#include <string>
#include <atomic>
#include <chrono>
#include <memory>
#include <string>
#include <tuple>
namespace ix
@ -42,7 +41,8 @@ namespace ix
}
};
class WebSocketHandshake {
class WebSocketHandshake
{
public:
WebSocketHandshake(std::atomic<bool>& requestInitCancellation,
std::shared_ptr<Socket> _socket,
@ -56,8 +56,7 @@ namespace ix
int port,
int timeoutSecs);
WebSocketInitResult serverHandshake(int fd,
int timeoutSecs);
WebSocketInitResult serverHandshake(int fd, int timeoutSecs);
private:
std::string genRandomString(const int len);
@ -75,4 +74,4 @@ namespace ix
WebSocketPerMessageDeflateOptions& _perMessageDeflateOptions;
std::atomic<bool>& _enablePerMessageDeflate;
};
}
} // namespace ix

View File

@ -7,10 +7,9 @@
#pragma once
#include "IXCancellationRequest.h"
#include <string>
#include <map>
#include <memory>
#include <string>
namespace ix
{
@ -21,15 +20,14 @@ namespace ix
// Case Insensitive compare_less binary function
struct NocaseCompare
{
bool operator() (const unsigned char& c1, const unsigned char& c2) const;
bool operator()(const unsigned char& c1, const unsigned char& c2) const;
};
bool operator() (const std::string & s1, const std::string & s2) const;
bool operator()(const std::string& s1, const std::string& s2) const;
};
using WebSocketHttpHeaders = std::map<std::string, std::string, CaseInsensitiveLess>;
std::pair<bool, WebSocketHttpHeaders> parseHttpHeaders(
std::shared_ptr<Socket> socket,
const CancellationRequest& isCancellationRequested);
}
std::shared_ptr<Socket> socket, const CancellationRequest& isCancellationRequested);
} // namespace ix

View File

@ -7,9 +7,9 @@
#pragma once
#include "IXWebSocket.h"
#include <thread>
#include <list>
#include <memory>
#include <thread>
namespace ix
{
@ -50,4 +50,4 @@ namespace ix
std::mutex _messagesMutex;
std::list<MessagePtr> _messages;
};
}
} // namespace ix

View File

@ -34,8 +34,8 @@
#pragma once
#include <string>
#include <memory>
#include <string>
namespace ix
{
@ -57,4 +57,4 @@ namespace ix
std::unique_ptr<WebSocketPerMessageDeflateCompressor> _compressor;
std::unique_ptr<WebSocketPerMessageDeflateDecompressor> _decompressor;
};
}
} // namespace ix

View File

@ -7,8 +7,8 @@
#pragma once
#include "zlib.h"
#include <string>
#include <memory>
#include <string>
namespace ix
{
@ -46,5 +46,4 @@ namespace ix
z_stream _inflateState;
};
}
} // namespace ix

View File

@ -42,4 +42,4 @@ namespace ix
int _clientMaxWindowBits;
int _serverMaxWindowBits;
};
}
} // namespace ix

View File

@ -15,8 +15,7 @@ namespace ix
size_t payloadSize;
size_t wireSize;
WebSocketSendInfo(bool s = false, bool c = false,
size_t p = 0, size_t w = 0)
WebSocketSendInfo(bool s = false, bool c = false, size_t p = 0, size_t w = 0)
: success(s)
, compressionError(c)
, payloadSize(p)
@ -25,4 +24,4 @@ namespace ix
;
}
};
}
} // namespace ix

View File

@ -6,24 +6,24 @@
#pragma once
#include <utility> // pair
#include <string>
#include <set>
#include <thread>
#include <mutex>
#include "IXSocketServer.h"
#include "IXWebSocket.h"
#include <condition_variable>
#include <functional>
#include <memory>
#include <condition_variable>
#include "IXWebSocket.h"
#include "IXSocketServer.h"
#include <mutex>
#include <set>
#include <string>
#include <thread>
#include <utility> // pair
namespace ix
{
using OnConnectionCallback = std::function<void(std::shared_ptr<WebSocket>,
std::shared_ptr<ConnectionState>)>;
using OnConnectionCallback =
std::function<void(std::shared_ptr<WebSocket>, std::shared_ptr<ConnectionState>)>;
class WebSocketServer final : public SocketServer {
class WebSocketServer final : public SocketServer
{
public:
WebSocketServer(int port = SocketServer::kDefaultPort,
const std::string& host = SocketServer::kDefaultHost,
@ -59,4 +59,4 @@ namespace ix
std::shared_ptr<ConnectionState> connectionState) final;
virtual size_t getConnectedClientsCount() final;
};
}
} // namespace ix

View File

@ -10,22 +10,21 @@
// Adapted from https://github.com/dhbaird/easywsclient
//
#include <string>
#include <vector>
#include <functional>
#include <memory>
#include <mutex>
#include <atomic>
#include <list>
#include "IXWebSocketSendInfo.h"
#include "IXWebSocketPerMessageDeflate.h"
#include "IXWebSocketPerMessageDeflateOptions.h"
#include "IXWebSocketHttpHeaders.h"
#include "IXCancellationRequest.h"
#include "IXWebSocketHandshake.h"
#include "IXProgressCallback.h"
#include "IXWebSocketCloseConstants.h"
#include "IXWebSocketHandshake.h"
#include "IXWebSocketHttpHeaders.h"
#include "IXWebSocketPerMessageDeflate.h"
#include "IXWebSocketPerMessageDeflateOptions.h"
#include "IXWebSocketSendInfo.h"
#include <atomic>
#include <functional>
#include <list>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
namespace ix
{
@ -63,14 +62,9 @@ namespace ix
AbnormalClose
};
using OnMessageCallback = std::function<void(const std::string&,
size_t,
bool,
MessageKind)>;
using OnCloseCallback = std::function<void(uint16_t,
const std::string&,
size_t,
bool)>;
using OnMessageCallback =
std::function<void(const std::string&, size_t, bool, MessageKind)>;
using OnCloseCallback = std::function<void(uint16_t, const std::string&, size_t, bool)>;
WebSocketTransport();
~WebSocketTransport();
@ -82,7 +76,7 @@ namespace ix
WebSocketInitResult connectToUrl(const std::string& url, // Client
int timeoutSecs);
WebSocketInitResult connectToSocket(int fd, // Server
WebSocketInitResult connectToSocket(int fd, // Server
int timeoutSecs);
PollResult poll();
@ -103,25 +97,26 @@ namespace ix
ReadyState getReadyState() const;
void setReadyState(ReadyState readyState);
void setOnCloseCallback(const OnCloseCallback& onCloseCallback);
void dispatch(PollResult pollResult,
const OnMessageCallback& onMessageCallback);
void dispatch(PollResult pollResult, const OnMessageCallback& onMessageCallback);
size_t bufferedAmount() const;
private:
std::string _url;
struct wsheader_type {
struct wsheader_type
{
unsigned header_size;
bool fin;
bool rsv1;
bool mask;
enum opcode_type {
enum opcode_type
{
CONTINUATION = 0x0,
TEXT_FRAME = 0x1,
TEXT_FRAME = 0x1,
BINARY_FRAME = 0x2,
CLOSE = 8,
PING = 9,
PONG = 0xa,
CLOSE = 8,
PING = 9,
PONG = 0xa,
} opcode;
int N0;
uint64_t N;
@ -176,7 +171,7 @@ namespace ix
std::atomic<bool> _requestInitCancellation;
mutable std::mutex _closingTimePointMutex;
std::chrono::time_point<std::chrono::steady_clock>_closingTimePoint;
std::chrono::time_point<std::chrono::steady_clock> _closingTimePoint;
static const int kClosingMaximumWaitingDelayInMs;
// enable auto response to ping
@ -211,7 +206,8 @@ namespace ix
// No PONG data was received through the socket for longer than ping timeout delay
bool pingTimeoutExceeded();
// after calling close(), if no CLOSE frame answer is received back from the remote, we should close the connexion
// after calling close(), if no CLOSE frame answer is received back from the remote, we
// should close the connexion
bool closingDelayExceeded();
void initTimePointsAndGCDAfterConnect();
@ -252,4 +248,4 @@ namespace ix
std::string getMergedChunks() const;
};
}
} // namespace ix

View File

@ -31,48 +31,54 @@
namespace LUrlParser
{
enum LUrlParserError
{
LUrlParserError_Ok = 0,
LUrlParserError_Uninitialized = 1,
LUrlParserError_NoUrlCharacter = 2,
LUrlParserError_InvalidSchemeName = 3,
LUrlParserError_NoDoubleSlash = 4,
LUrlParserError_NoAtSign = 5,
LUrlParserError_UnexpectedEndOfLine = 6,
LUrlParserError_NoSlash = 7,
};
enum LUrlParserError
{
LUrlParserError_Ok = 0,
LUrlParserError_Uninitialized = 1,
LUrlParserError_NoUrlCharacter = 2,
LUrlParserError_InvalidSchemeName = 3,
LUrlParserError_NoDoubleSlash = 4,
LUrlParserError_NoAtSign = 5,
LUrlParserError_UnexpectedEndOfLine = 6,
LUrlParserError_NoSlash = 7,
};
class clParseURL
{
public:
LUrlParserError m_ErrorCode;
std::string m_Scheme;
std::string m_Host;
std::string m_Port;
std::string m_Path;
std::string m_Query;
std::string m_Fragment;
std::string m_UserName;
std::string m_Password;
class clParseURL
{
public:
LUrlParserError m_ErrorCode;
std::string m_Scheme;
std::string m_Host;
std::string m_Port;
std::string m_Path;
std::string m_Query;
std::string m_Fragment;
std::string m_UserName;
std::string m_Password;
clParseURL()
: m_ErrorCode( LUrlParserError_Uninitialized )
{}
clParseURL()
: m_ErrorCode(LUrlParserError_Uninitialized)
{
}
/// return 'true' if the parsing was successful
bool IsValid() const { return m_ErrorCode == LUrlParserError_Ok; }
/// return 'true' if the parsing was successful
bool IsValid() const
{
return m_ErrorCode == LUrlParserError_Ok;
}
/// helper to convert the port number to int, return 'true' if the port is valid (within the 0..65535 range)
bool GetPort( int* OutPort ) const;
/// helper to convert the port number to int, return 'true' if the port is valid (within the
/// 0..65535 range)
bool GetPort(int* OutPort) const;
/// parse the URL
static clParseURL ParseURL( const std::string& URL );
/// parse the URL
static clParseURL ParseURL(const std::string& URL);
private:
explicit clParseURL( LUrlParserError ErrorCode )
: m_ErrorCode( ErrorCode )
{}
};
private:
explicit clParseURL(LUrlParserError ErrorCode)
: m_ErrorCode(ErrorCode)
{
}
};
} // namespace LUrlParser