.Core: docs

git-svn-id: svn://ultimatepp.org/upp/trunk@4800 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2012-04-17 13:37:08 +00:00
parent f2af1cff97
commit b20a84f409
7 changed files with 804 additions and 446 deletions

View file

@ -268,8 +268,8 @@ bool HttpRequest::Do()
case CHUNK_BODY:
if(ReadingBody())
break;
c1 = Get();
c2 = Get();
c1 = TcpSocket::Get();
c2 = TcpSocket::Get();
if(c1 != '\r' || c2 != '\n')
HttpError("missing ending CRLF in chunked transfer");
StartPhase(CHUNK_HEADER);
@ -446,7 +446,7 @@ bool HttpRequest::SendingData()
{
for(;;) {
int n = min(2048, data.GetLength() - count);
n = Put(~data + count, n);
n = TcpSocket::Put(~data + count, n);
if(n == 0)
break;
count += n;
@ -457,7 +457,7 @@ bool HttpRequest::SendingData()
bool HttpRequest::ReadingHeader()
{
for(;;) {
int c = Get();
int c = TcpSocket::Get();
if(c < 0)
return !IsEof();
else
@ -477,7 +477,7 @@ bool HttpRequest::ReadingHeader()
void HttpRequest::ReadingChunkHeader()
{
for(;;) {
int c = Get();
int c = TcpSocket::Get();
if(c < 0)
break;
else
@ -559,12 +559,12 @@ void HttpRequest::StartBody()
}
}
void HttpRequest::ContentOut(const void *ptr, dword size)
void HttpRequest::ContentOut(const void *ptr, int size)
{
body.Cat((const char *)ptr, size);
}
void HttpRequest::Out(const void *ptr, dword size)
void HttpRequest::Out(const void *ptr, int size)
{
LLOG("HTTP Out " << size);
if(z.IsError())
@ -585,7 +585,7 @@ bool HttpRequest::ReadingBody()
int n = chunk;
if(count >= 0)
n = min(n, count);
String s = Get(n);
String s = TcpSocket::Get(n);
if(s.GetCount() == 0)
return !IsEof() && count;
#ifndef ENDZIP

View file

@ -1,420 +1,427 @@
String WwwFormat(Time tm);
String UrlEncode(const char *s, const char *end);
String UrlEncode(const char *s, int len);
String UrlEncode(const String& s);
String UrlDecode(const char *s, const char *end);
String UrlDecode(const char *s, int len);
String UrlDecode(const String& s);
String Base64Encode(const char *s, const char *end);
String Base64Encode(const char *s, int len);
String Base64Encode(const String& data);
String Base64Decode(const char *s, const char *end);
String Base64Decode(const char *s, int len);
String Base64Decode(const String& data);
class IpAddrInfo {
enum { COUNT = 32 };
struct Entry {
const char *host;
const char *port;
int status;
addrinfo *addr;
};
static Entry pool[COUNT];
enum {
EMPTY = 0, WORKING, CANCELED, RESOLVED, FAILED
};
String host, port;
Entry *entry;
Entry exe[1];
static void EnterPool();
static void LeavePool();
static auxthread_t auxthread__ Thread(void *ptr);
void Start();
public:
void Start(const String& host, int port);
bool InProgress();
bool Execute(const String& host, int port);
addrinfo *GetResult();
void Clear();
IpAddrInfo();
~IpAddrInfo() { Clear(); }
};
enum { WAIT_READ = 1, WAIT_WRITE = 2, WAIT_EXCEPTION = 4, WAIT_ALL = 7 };
struct SSLInfo {
String cipher;
bool cert_avail;
bool cert_verified; // Peer verification not yet working - this is always false
String cert_subject;
String cert_issuer;
Date cert_notbefore;
Date cert_notafter;
int cert_version;
String cert_serial;
};
class TcpSocket {
enum { BUFFERSIZE = 512 };
enum { NONE, CONNECT, ACCEPT, SSL_CONNECTED };
SOCKET socket;
int mode;
char buffer[BUFFERSIZE];
char *ptr;
char *end;
bool is_eof;
bool is_error;
bool is_abort;
bool ipv6;
int timeout;
int waitstep;
int done;
int errorcode;
String errordesc;
struct SSL {
virtual bool Start() = 0;
virtual bool Wait(dword flags, int end_time) = 0;
virtual int Send(const void *buffer, int maxlen) = 0;
virtual int Recv(void *buffer, int maxlen) = 0;
virtual void Close() = 0;
virtual dword Handshake() = 0;
virtual ~SSL() {}
};
One<SSL> ssl;
One<SSLInfo> sslinfo;
String cert, pkey;
bool asn1;
struct SSLImp;
friend struct SSLImp;
static SSL *(*CreateSSL)(TcpSocket& socket);
static SSL *CreateSSLImp(TcpSocket& socket);
friend void InitCreateSSL();
friend class IpAddrInfo;
int GetEndTime() const;
bool RawWait(dword flags, int end_time);
bool Wait(dword events, int end_time);
SOCKET AcceptRaw(dword *ipaddr, int timeout_msec);
bool Open(int family, int type, int protocol);
int RawRecv(void *buffer, int maxlen);
int Recv(void *buffer, int maxlen);
int RawSend(const void *buffer, int maxlen);
int Send(const void *buffer, int maxlen);
bool RawConnect(addrinfo *info);
void RawClose();
void ReadBuffer(int end_time);
int Get_();
int Peek_();
int Peek_(int end_time);
int Peek(int end_time) { return ptr < end ? *ptr : Peek_(end_time); }
void Reset();
void SetSockError(const char *context, int code, const char *errdesc);
void SetSockError(const char *context, const char *errdesc);
void SetSockError(const char *context);
static int GetErrorCode();
static bool WouldBlock();
static void Init();
public:
Callback WhenWait;
static String GetHostName();
int GetDone() const { return done; }
bool IsOpen() const { return socket != INVALID_SOCKET; }
bool IsEof() const { return is_eof && ptr == end; }
bool IsError() const { return is_error; }
void ClearError() { is_error = false; errorcode = 0; errordesc.Clear(); }
int GetError() const { return errorcode; }
String GetErrorDesc() const { return errordesc; }
void Abort() { is_abort = true; }
bool IsAbort() const { return is_abort; }
void ClearAbort() { is_abort = false; }
SOCKET GetSOCKET() const { return socket; }
String GetPeerAddr() const;
void Attach(SOCKET socket);
bool Connect(const char *host, int port);
bool Connect(IpAddrInfo& info);
bool Listen(int port, int listen_count, bool ipv6 = false, bool reuse = true);
bool Accept(TcpSocket& listen_socket);
void Close();
void Shutdown();
void NoDelay();
void Linger(int msecs);
void NoLinger() { Linger(Null); }
bool Wait(dword events);
bool WaitRead() { return Wait(WAIT_READ); }
bool WaitWrite() { return Wait(WAIT_WRITE); }
int Peek() { return ptr < end ? *ptr : Peek_(); }
int Term() { return Peek(); }
int Get() { return ptr < end ? *ptr++ : Get_(); }
int Get(void *buffer, int len);
String Get(int len);
int Put(const char *s, int len);
int Put(const String& s) { return Put(s.Begin(), s.GetLength()); }
bool GetAll(void *buffer, int len);
String GetAll(int len);
String GetLine(int maxlen = 65536);
bool PutAll(const char *s, int len);
bool PutAll(const String& s);
bool StartSSL();
bool IsSSL() const { return ssl; }
bool SSLHandshake();
void SSLCertificate(const String& cert, const String& pkey, bool asn1);
const SSLInfo *GetSSLInfo() const { return ~sslinfo; }
TcpSocket& Timeout(int ms) { timeout = ms; return *this; }
int GetTimeout() const { return timeout; }
TcpSocket& Blocking() { return Timeout(Null); }
TcpSocket();
~TcpSocket() { Close(); }
};
class SocketWaitEvent {
Vector< Tuple2<int, dword> > socket;
fd_set read[1], write[1], exception[1];
public:
void Clear() { socket.Clear(); }
void Add(SOCKET s, dword events = WAIT_ALL) { socket.Add(MakeTuple((int)s, events)); }
void Add(TcpSocket& s, dword events = WAIT_ALL) { Add(s.GetSOCKET(), events); }
int Wait(int timeout);
dword Get(int i) const;
dword operator[](int i) const { return Get(i); }
SocketWaitEvent();
};
struct HttpHeader {
String first_line;
VectorMap<String, String> fields;
String operator[](const char *id) { return fields.Get(id, Null); }
bool Response(String& protocol, int& code, String& reason);
bool Request(String& method, String& uri, String& version);
void Clear();
bool Parse(const String& hdrs);
};
class HttpRequest : public TcpSocket {
int phase;
String data;
int count;
HttpHeader header;
String error;
String body;
enum {
DEFAULT_HTTP_PORT = 80,
DEFAULT_HTTPS_PORT = 443
};
enum {
METHOD_GET,
METHOD_POST,
METHOD_HEAD,
METHOD_PUT,
};
int max_header_size;
int max_content_size;
int max_redirects;
int max_retries;
int timeout;
String host;
int port;
String proxy_host;
int proxy_port;
String proxy_username;
String proxy_password;
String ssl_proxy_host;
int ssl_proxy_port;
String ssl_proxy_username;
String ssl_proxy_password;
String path;
bool ssl;
int method;
String accept;
String agent;
bool force_digest;
bool is_post;
bool std_headers;
bool hasurlvar;
String contenttype;
String username;
String password;
String digest;
String request_headers;
String postdata;
String protocol;
int status_code;
String reason_phrase;
int start_time;
int retry_count;
int redirect_count;
int chunk;
IpAddrInfo addrinfo;
int bodylen;
bool gzip;
Zlib z;
void Init();
void StartPhase(int s);
void Start();
void Dns();
void StartConnect();
void ProcessSSLProxyResponse();
void AfterConnect();
void StartRequest();
bool SendingData();
bool ReadingHeader();
void StartBody();
bool ReadingBody();
void ReadingChunkHeader();
void Finish();
void CopyCookies();
void HttpError(const char *s);
void ContentOut(const void *ptr, dword size);
void Out(const void *ptr, dword size);
String CalculateDigest(const String& authenticate) const;
public:
Callback2<const void *, dword> WhenContent;
HttpRequest& MaxHeaderSize(int m) { max_header_size = m; return *this; }
HttpRequest& MaxContentSize(int m) { max_content_size = m; return *this; }
HttpRequest& MaxRedirect(int n) { max_redirects = n; return *this; }
HttpRequest& MaxRetries(int n) { max_retries = n; return *this; }
HttpRequest& RequestTimeout(int ms) { timeout = ms; return *this; }
HttpRequest& ChunkSize(int n) { chunk = n; return *this; }
HttpRequest& Method(int m) { method = m; return *this; }
HttpRequest& GET() { return Method(METHOD_GET); }
HttpRequest& POST() { return Method(METHOD_POST); }
HttpRequest& HEAD() { return Method(METHOD_HEAD); }
HttpRequest& PUT() { return Method(METHOD_PUT); }
HttpRequest& Host(const String& h) { host = h; return *this; }
HttpRequest& Port(int p) { port = p; return *this; }
HttpRequest& SSL(bool b = true) { ssl = b; return *this; }
HttpRequest& Path(const String& p) { path = p; return *this; }
HttpRequest& User(const String& u, const String& p) { username = u; password = p; return *this; }
HttpRequest& Digest() { force_digest = true; return *this; }
HttpRequest& Digest(const String& d) { digest = d; return *this; }
HttpRequest& Url(const char *url);
HttpRequest& UrlVar(const char *id, const String& data);
HttpRequest& operator()(const char *id, const String& data) { return UrlVar(id, data); }
HttpRequest& PostData(const String& pd) { postdata = pd; return *this; }
HttpRequest& PostUData(const String& pd) { return PostData(UrlEncode(pd)); }
HttpRequest& Post(const String& data) { POST(); return PostData(data); }
HttpRequest& Post(const char *id, const String& data);
HttpRequest& Headers(const String& h) { request_headers = h; return *this; }
HttpRequest& ClearHeaders() { return Headers(Null); }
HttpRequest& AddHeaders(const String& h) { request_headers.Cat(h); return *this; }
HttpRequest& Header(const char *id, const String& data);
HttpRequest& Cookie(const String& cookie) { return Header("Cookie", cookie); }
HttpRequest& StdHeaders(bool sh) { std_headers = sh; return *this; }
HttpRequest& NoStdHeaders() { return StdHeaders(false); }
HttpRequest& Accept(const String& a) { accept = a; return *this; }
HttpRequest& UserAgent(const String& a) { agent = a; return *this; }
HttpRequest& ContentType(const String& a) { contenttype = a; return *this; }
HttpRequest& Proxy(const String& host, int port) { proxy_host = host; proxy_port = port; return *this; }
HttpRequest& Proxy(const char *p);
HttpRequest& ProxyAuth(const String& u, const String& p) { proxy_username = u; proxy_password = p; return *this; }
HttpRequest& SSLProxy(const String& host, int port) { ssl_proxy_host = host; ssl_proxy_port = port; return *this; }
HttpRequest& SSLProxy(const char *p);
HttpRequest& SSLProxyAuth(const String& u, const String& p) { ssl_proxy_username = u; ssl_proxy_password = p; return *this; }
bool IsSocketError() const { return TcpSocket::IsError(); }
bool IsHttpError() const { return !IsNull(error) ; }
bool IsError() const { return IsSocketError() || IsHttpError(); }
String GetErrorDesc() const { return IsSocketError() ? TcpSocket::GetErrorDesc() : error; }
void ClearError() { TcpSocket::ClearError(); error.Clear(); }
String GetHeader(const char *s) { return header[s]; }
String operator[](const char *s) { return GetHeader(s); }
String GetRedirectUrl();
int GetContentLength();
int GetStatusCode() const { return status_code; }
String GetReasonPhrase() const { return reason_phrase; }
String GetContent() const { return body; }
String operator~() const { return GetContent(); }
operator String() const { return GetContent(); }
void ClearContent() { body.Clear(); }
enum Phase {
BEGIN, START, DNS,
SSLPROXYREQUEST, SSLPROXYRESPONSE, SSLHANDSHAKE,
REQUEST, HEADER, BODY,
CHUNK_HEADER, CHUNK_BODY, TRAILER,
FINISHED, FAILED
};
bool Do();
int GetPhase() const { return phase; }
String GetPhaseName() const;
bool InProgress() const { return phase != FAILED && phase != FINISHED; }
bool IsFailure() const { return phase == FAILED; }
bool IsSuccess() const { return phase == FINISHED && status_code >= 200 && status_code < 300; }
String Execute();
HttpRequest();
HttpRequest(const char *url);
static void Trace(bool b = true);
};
String WwwFormat(Time tm);
String UrlEncode(const char *s, const char *end);
String UrlEncode(const char *s, int len);
String UrlEncode(const String& s);
String UrlDecode(const char *s, const char *end);
String UrlDecode(const char *s, int len);
String UrlDecode(const String& s);
String Base64Encode(const char *s, const char *end);
String Base64Encode(const char *s, int len);
String Base64Encode(const String& data);
String Base64Decode(const char *s, const char *end);
String Base64Decode(const char *s, int len);
String Base64Decode(const String& data);
class IpAddrInfo {
enum { COUNT = 32 };
struct Entry {
const char *host;
const char *port;
int status;
addrinfo *addr;
};
static Entry pool[COUNT];
enum {
EMPTY = 0, WORKING, CANCELED, RESOLVED, FAILED
};
String host, port;
Entry *entry;
Entry exe[1];
static void EnterPool();
static void LeavePool();
static auxthread_t auxthread__ Thread(void *ptr);
void Start();
public:
void Start(const String& host, int port);
bool InProgress();
bool Execute(const String& host, int port);
addrinfo *GetResult();
void Clear();
IpAddrInfo();
~IpAddrInfo() { Clear(); }
};
enum { WAIT_READ = 1, WAIT_WRITE = 2, WAIT_EXCEPTION = 4, WAIT_ALL = 7 };
struct SSLInfo {
String cipher;
bool cert_avail;
bool cert_verified; // Peer verification not yet working - this is always false
String cert_subject;
String cert_issuer;
Date cert_notbefore;
Date cert_notafter;
int cert_version;
String cert_serial;
};
class TcpSocket {
enum { BUFFERSIZE = 512 };
enum { NONE, CONNECT, ACCEPT, SSL_CONNECTED };
SOCKET socket;
int mode;
char buffer[BUFFERSIZE];
char *ptr;
char *end;
bool is_eof;
bool is_error;
bool is_abort;
bool ipv6;
int timeout;
int waitstep;
int done;
int errorcode;
String errordesc;
struct SSL {
virtual bool Start() = 0;
virtual bool Wait(dword flags, int end_time) = 0;
virtual int Send(const void *buffer, int maxlen) = 0;
virtual int Recv(void *buffer, int maxlen) = 0;
virtual void Close() = 0;
virtual dword Handshake() = 0;
virtual ~SSL() {}
};
One<SSL> ssl;
One<SSLInfo> sslinfo;
String cert, pkey;
bool asn1;
struct SSLImp;
friend struct SSLImp;
static SSL *(*CreateSSL)(TcpSocket& socket);
static SSL *CreateSSLImp(TcpSocket& socket);
friend void InitCreateSSL();
friend class IpAddrInfo;
int GetEndTime() const;
bool RawWait(dword flags, int end_time);
bool Wait(dword events, int end_time);
SOCKET AcceptRaw(dword *ipaddr, int timeout_msec);
bool Open(int family, int type, int protocol);
int RawRecv(void *buffer, int maxlen);
int Recv(void *buffer, int maxlen);
int RawSend(const void *buffer, int maxlen);
int Send(const void *buffer, int maxlen);
bool RawConnect(addrinfo *info);
void RawClose();
void ReadBuffer(int end_time);
int Get_();
int Peek_();
int Peek_(int end_time);
int Peek(int end_time) { return ptr < end ? *ptr : Peek_(end_time); }
void Reset();
void SetSockError(const char *context, int code, const char *errdesc);
void SetSockError(const char *context, const char *errdesc);
void SetSockError(const char *context);
static int GetErrorCode();
static bool WouldBlock();
static void Init();
public:
Callback WhenWait;
static String GetHostName();
int GetDone() const { return done; }
bool IsOpen() const { return socket != INVALID_SOCKET; }
bool IsEof() const { return is_eof && ptr == end; }
bool IsError() const { return is_error; }
void ClearError() { is_error = false; errorcode = 0; errordesc.Clear(); }
int GetError() const { return errorcode; }
String GetErrorDesc() const { return errordesc; }
void Abort() { is_abort = true; }
bool IsAbort() const { return is_abort; }
void ClearAbort() { is_abort = false; }
SOCKET GetSOCKET() const { return socket; }
String GetPeerAddr() const;
void Attach(SOCKET socket);
bool Connect(const char *host, int port);
bool Connect(IpAddrInfo& info);
bool Listen(int port, int listen_count, bool ipv6 = false, bool reuse = true);
bool Accept(TcpSocket& listen_socket);
void Close();
void Shutdown();
void NoDelay();
void Linger(int msecs);
void NoLinger() { Linger(Null); }
bool Wait(dword events);
bool WaitRead() { return Wait(WAIT_READ); }
bool WaitWrite() { return Wait(WAIT_WRITE); }
int Peek() { return ptr < end ? *ptr : Peek_(); }
int Term() { return Peek(); }
int Get() { return ptr < end ? *ptr++ : Get_(); }
int Get(void *buffer, int len);
String Get(int len);
int Put(const char *s, int len);
int Put(const String& s) { return Put(s.Begin(), s.GetLength()); }
bool GetAll(void *buffer, int len);
String GetAll(int len);
String GetLine(int maxlen = 65536);
bool PutAll(const char *s, int len);
bool PutAll(const String& s);
bool StartSSL();
bool IsSSL() const { return ssl; }
bool SSLHandshake();
void SSLCertificate(const String& cert, const String& pkey, bool asn1);
const SSLInfo *GetSSLInfo() const { return ~sslinfo; }
TcpSocket& Timeout(int ms) { timeout = ms; return *this; }
int GetTimeout() const { return timeout; }
TcpSocket& Blocking() { return Timeout(Null); }
TcpSocket();
~TcpSocket() { Close(); }
};
class SocketWaitEvent {
Vector< Tuple2<int, dword> > socket;
fd_set read[1], write[1], exception[1];
public:
void Clear() { socket.Clear(); }
void Add(SOCKET s, dword events = WAIT_ALL) { socket.Add(MakeTuple((int)s, events)); }
void Add(TcpSocket& s, dword events = WAIT_ALL) { Add(s.GetSOCKET(), events); }
int Wait(int timeout);
dword Get(int i) const;
dword operator[](int i) const { return Get(i); }
SocketWaitEvent();
};
struct HttpHeader {
String first_line;
VectorMap<String, String> fields;
String operator[](const char *id) { return fields.Get(id, Null); }
bool Response(String& protocol, int& code, String& reason);
bool Request(String& method, String& uri, String& version);
void Clear();
bool Parse(const String& hdrs);
};
class HttpRequest : public TcpSocket {
int phase;
String data;
int count;
HttpHeader header;
String error;
String body;
enum {
DEFAULT_HTTP_PORT = 80,
DEFAULT_HTTPS_PORT = 443
};
enum {
METHOD_GET,
METHOD_POST,
METHOD_HEAD,
METHOD_PUT,
};
int max_header_size;
int max_content_size;
int max_redirects;
int max_retries;
int timeout;
String host;
int port;
String proxy_host;
int proxy_port;
String proxy_username;
String proxy_password;
String ssl_proxy_host;
int ssl_proxy_port;
String ssl_proxy_username;
String ssl_proxy_password;
String path;
bool ssl;
int method;
String accept;
String agent;
bool force_digest;
bool is_post;
bool std_headers;
bool hasurlvar;
String contenttype;
String username;
String password;
String digest;
String request_headers;
String postdata;
String protocol;
int status_code;
String reason_phrase;
int start_time;
int retry_count;
int redirect_count;
int chunk;
IpAddrInfo addrinfo;
int bodylen;
bool gzip;
Zlib z;
void Init();
void StartPhase(int s);
void Start();
void Dns();
void StartConnect();
void ProcessSSLProxyResponse();
void AfterConnect();
void StartRequest();
bool SendingData();
bool ReadingHeader();
void StartBody();
bool ReadingBody();
void ReadingChunkHeader();
void Finish();
void CopyCookies();
void HttpError(const char *s);
void ContentOut(const void *ptr, int size);
void Out(const void *ptr, int size);
String CalculateDigest(const String& authenticate) const;
// hiding from Socket:
int Get();
int Put();
bool GetAll();
String GetLine();
bool PutAll();
public:
Callback2<const void *, int> WhenContent;
HttpRequest& MaxHeaderSize(int m) { max_header_size = m; return *this; }
HttpRequest& MaxContentSize(int m) { max_content_size = m; return *this; }
HttpRequest& MaxRedirect(int n) { max_redirects = n; return *this; }
HttpRequest& MaxRetries(int n) { max_retries = n; return *this; }
HttpRequest& RequestTimeout(int ms) { timeout = ms; return *this; }
HttpRequest& ChunkSize(int n) { chunk = n; return *this; }
HttpRequest& Method(int m) { method = m; return *this; }
HttpRequest& GET() { return Method(METHOD_GET); }
HttpRequest& POST() { return Method(METHOD_POST); }
HttpRequest& HEAD() { return Method(METHOD_HEAD); }
HttpRequest& PUT() { return Method(METHOD_PUT); }
HttpRequest& Host(const String& h) { host = h; return *this; }
HttpRequest& Port(int p) { port = p; return *this; }
HttpRequest& SSL(bool b = true) { ssl = b; return *this; }
HttpRequest& Path(const String& p) { path = p; return *this; }
HttpRequest& User(const String& u, const String& p) { username = u; password = p; return *this; }
HttpRequest& Digest() { force_digest = true; return *this; }
HttpRequest& Digest(const String& d) { digest = d; return *this; }
HttpRequest& Url(const char *url);
HttpRequest& UrlVar(const char *id, const String& data);
HttpRequest& operator()(const char *id, const String& data) { return UrlVar(id, data); }
HttpRequest& PostData(const String& pd) { postdata = pd; return *this; }
HttpRequest& PostUData(const String& pd) { return PostData(UrlEncode(pd)); }
HttpRequest& Post(const String& data) { POST(); return PostData(data); }
HttpRequest& Post(const char *id, const String& data);
HttpRequest& Headers(const String& h) { request_headers = h; return *this; }
HttpRequest& ClearHeaders() { return Headers(Null); }
HttpRequest& AddHeaders(const String& h) { request_headers.Cat(h); return *this; }
HttpRequest& Header(const char *id, const String& data);
HttpRequest& Cookie(const String& cookie) { return Header("Cookie", cookie); }
HttpRequest& StdHeaders(bool sh) { std_headers = sh; return *this; }
HttpRequest& NoStdHeaders() { return StdHeaders(false); }
HttpRequest& Accept(const String& a) { accept = a; return *this; }
HttpRequest& UserAgent(const String& a) { agent = a; return *this; }
HttpRequest& ContentType(const String& a) { contenttype = a; return *this; }
HttpRequest& Proxy(const String& host, int port) { proxy_host = host; proxy_port = port; return *this; }
HttpRequest& Proxy(const char *p);
HttpRequest& ProxyAuth(const String& u, const String& p) { proxy_username = u; proxy_password = p; return *this; }
HttpRequest& SSLProxy(const String& host, int port) { ssl_proxy_host = host; ssl_proxy_port = port; return *this; }
HttpRequest& SSLProxy(const char *p);
HttpRequest& SSLProxyAuth(const String& u, const String& p) { ssl_proxy_username = u; ssl_proxy_password = p; return *this; }
bool IsSocketError() const { return TcpSocket::IsError(); }
bool IsHttpError() const { return !IsNull(error) ; }
bool IsError() const { return IsSocketError() || IsHttpError(); }
String GetErrorDesc() const { return IsSocketError() ? TcpSocket::GetErrorDesc() : error; }
void ClearError() { TcpSocket::ClearError(); error.Clear(); }
String GetHeader(const char *id) { return header[id]; }
String operator[](const char *id) { return GetHeader(id); }
String GetRedirectUrl();
int GetContentLength();
int GetStatusCode() const { return status_code; }
String GetReasonPhrase() const { return reason_phrase; }
String GetContent() const { return body; }
String operator~() const { return GetContent(); }
operator String() const { return GetContent(); }
void ClearContent() { body.Clear(); }
enum Phase {
BEGIN, START, DNS,
SSLPROXYREQUEST, SSLPROXYRESPONSE, SSLHANDSHAKE,
REQUEST, HEADER, BODY,
CHUNK_HEADER, CHUNK_BODY, TRAILER,
FINISHED, FAILED
};
bool Do();
int GetPhase() const { return phase; }
String GetPhaseName() const;
bool InProgress() const { return phase != FAILED && phase != FINISHED; }
bool IsFailure() const { return phase == FAILED; }
bool IsSuccess() const { return phase == FINISHED && status_code >= 200 && status_code < 300; }
String Execute();
HttpRequest();
HttpRequest(const char *url);
static void Trace(bool b = true);
};

View file

@ -0,0 +1,352 @@
topic "HttpRequest";
[2 $$0,0#00000000000000000000000000000000:Default]
[i448;a25;kKO9;2 $$1,0#37138531426314131252341829483380:class]
[l288;2 $$2,2#27521748481378242620020725143825:desc]
[0 $$3,0#96390100711032703541132217272105:end]
[H6;0 $$4,0#05600065144404261032431302351956:begin]
[i448;a25;kKO9;2 $$5,0#37138531426314131252341829483370:item]
[l288;a4;*@5;1 $$6,6#70004532496200323422659154056402:requirement]
[l288;i1121;b17;O9;~~~.1408;2 $$7,0#10431211400427159095818037425705:param]
[i448;b42;O9;2 $$8,8#61672508125594000341940100500538:tparam]
[b42;2 $$9,9#13035079074754324216151401829390:normal]
[{_}%EN-US
[ {{10000@(113.42.0) [s0; [*@7;4 HttpRequest]]}}&]
[s3;%- &]
[s1;:HttpRequest`:`:class:%- [@(0.0.255)3 class][3 _][*3 HttpRequest][3 _:_][@(0.0.255)3 public][3 _
][*@3;3 TcpSocket]&]
[s2; &]
[s3; &]
[ {{10000F(128)G(128)@1 [s0; [* Public Method List]]}}&]
[s4;%- &]
[s5;:HttpRequest`:`:WhenContent:%- [_^Callback2^ Callback2]<[@(0.0.255) const]_[@(0.0.255) v
oid]_`*, [@(0.0.255) int]>_[* WhenContent]&]
[s2; &]
[s3;%- &]
[s4;%- &]
[s5;:HttpRequest`:`:MaxHeaderSize`(int`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_[* M
axHeaderSize]([@(0.0.255) int]_[*@3 m])&]
[s2; Specifies the maximum size of response header (default is 1000000).&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:MaxContentSize`(int`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_
[* MaxContentSize]([@(0.0.255) int]_[*@3 m])&]
[s2; Specifies the maximum size of response content (default is 10000000).&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:MaxRedirect`(int`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_[* Ma
xRedirect]([@(0.0.255) int]_[*@3 n])&]
[s2; Specifies the maximum number of redirections (code 3xx) (default
is 5).&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:MaxRetries`(int`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_[* Max
Retries]([@(0.0.255) int]_[*@3 n])&]
[s2; Specifies the maximum number of retries on failure (default
is 3).&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:RequestTimeout`(int`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_
[* RequestTimeout]([@(0.0.255) int]_[*@3 ms])&]
[s2; Specifies total allowed time for request in milliseconds (default
is .120000 `- two minutes).&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:ChunkSize`(int`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_[* Chun
kSize]([@(0.0.255) int]_[*@3 n])&]
[s2; Specifies the maximum size of content data block for processing
(default is 4096).&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:Method`(int`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_[* Method](
[@(0.0.255) int]_[*@3 m])&]
[s2; [%-*@3 m] .&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:GET`(`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_[* GET]()&]
[s2; &]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:POST`(`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_[* POST]()&]
[s2; &]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:HEAD`(`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_[* HEAD]()&]
[s2; &]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:PUT`(`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_[* PUT]()&]
[s2; &]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:Host`(const String`&`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_
[* Host]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 h])&]
[s2; [%-*@3 h] .&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:Port`(int`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_[* Port]([@(0.0.255) i
nt]_[*@3 p])&]
[s2; [%-*@3 p] .&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:SSL`(bool`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_[* SSL]([@(0.0.255) b
ool]_[*@3 b]_`=_[@(0.0.255) true])&]
[s2; [%-*@3 b] .&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:Path`(const String`&`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_
[* Path]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 p])&]
[s2; [%-*@3 p] .&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:User`(const String`&`,const String`&`):%- [_^HttpRequest^ HttpReque
st][@(0.0.255) `&]_[* User]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 u],
[@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 p])&]
[s2; [%-*@3 u] [%-*@3 p] .&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:Digest`(`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_[* Digest]()&]
[s2; &]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:Digest`(const String`&`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&
]_[* Digest]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 d])&]
[s2; [%-*@3 d] .&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:Url`(const char`*`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_[* U
rl]([@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 url])&]
[s2; [%-*@3 url] .&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:UrlVar`(const char`*`,const String`&`):%- [_^HttpRequest^ HttpReque
st][@(0.0.255) `&]_[* UrlVar]([@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 id],
[@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 data])&]
[s2; [%-*@3 id] [%-*@3 data] .&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:operator`(`)`(const char`*`,const String`&`):%- [_^HttpRequest^ Htt
pRequest][@(0.0.255) `&]_[* operator()]([@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 id],
[@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 data])&]
[s2; [%-*@3 id] [%-*@3 data] .&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:PostData`(const String`&`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&
]_[* PostData]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 pd])&]
[s2; [%-*@3 pd] .&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:PostUData`(const String`&`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&
]_[* PostUData]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 pd])&]
[s2; [%-*@3 pd] .&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:Post`(const String`&`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_
[* Post]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 data])&]
[s2; [%-*@3 data] .&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:Post`(const char`*`,const String`&`):%- [_^HttpRequest^ HttpRequest
][@(0.0.255) `&]_[* Post]([@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 id],
[@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 data])&]
[s2; [%-*@3 id] [%-*@3 data] .&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:Headers`(const String`&`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&
]_[* Headers]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 h])&]
[s2; [%-*@3 h] .&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:ClearHeaders`(`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_[* Clea
rHeaders]()&]
[s2; &]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:AddHeaders`(const String`&`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&
]_[* AddHeaders]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 h])&]
[s2; [%-*@3 h] .&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:Header`(const char`*`,const String`&`):%- [_^HttpRequest^ HttpReque
st][@(0.0.255) `&]_[* Header]([@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 id],
[@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 data])&]
[s2; [%-*@3 id] [%-*@3 data] .&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:Cookie`(const String`&`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&
]_[* Cookie]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 cookie])&]
[s2; Adds cookie to HTTP request.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:StdHeaders`(bool`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_[* St
dHeaders]([@(0.0.255) bool]_[*@3 sh])&]
[s2; [%-*@3 sh] .&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:NoStdHeaders`(`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_[* NoSt
dHeaders]()&]
[s2; &]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:Accept`(const String`&`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&
]_[* Accept]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 a])&]
[s2; [%-*@3 a] .&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:UserAgent`(const String`&`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&
]_[* UserAgent]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 a])&]
[s2; Specifies `"User`-Agent`" HTTP request field.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:ContentType`(const String`&`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&
]_[* ContentType]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 a])&]
[s2; Specifies `"Content`-Type`" HTTP request field.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:Proxy`(const String`&`,int`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&
]_[* Proxy]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 host],
[@(0.0.255) int]_[*@3 port])&]
[s2; Defines http proxy.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:Proxy`(const char`*`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&]_
[* Proxy]([@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 p])&]
[s2; Defines http proxy, [%-*@3 p] should contain `"hostname:port`".&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:ProxyAuth`(const String`&`,const String`&`):%- [_^HttpRequest^ Http
Request][@(0.0.255) `&]_[* ProxyAuth]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_
[*@3 u], [@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 p])&]
[s2; Defines username and password authentication for SSL proxy.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:SSLProxy`(const String`&`,int`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&
]_[* SSLProxy]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 host],
[@(0.0.255) int]_[*@3 port])&]
[s2; Defines proxy for SSL connection.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:SSLProxy`(const char`*`):%- [_^HttpRequest^ HttpRequest][@(0.0.255) `&
]_[* SSLProxy]([@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 p])&]
[s2; Defines proxy for SSL connection, [%-*@3 p] should contain `"hostname:port`".&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:SSLProxyAuth`(const String`&`,const String`&`):%- [_^HttpRequest^ H
ttpRequest][@(0.0.255) `&]_[* SSLProxyAuth]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&
]_[*@3 u], [@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 p])&]
[s2; Defines username and password authentication for SSL proxy.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:IsSocketError`(`)const:%- [@(0.0.255) bool]_[* IsSocketError]()_[@(0.0.255) c
onst]&]
[s2; Returns true if there was error on socket level.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:IsHttpError`(`)const:%- [@(0.0.255) bool]_[* IsHttpError]()_[@(0.0.255) c
onst]&]
[s2; Returns true if there was error on HTTP protocol level.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:IsError`(`)const:%- [@(0.0.255) bool]_[* IsError]()_[@(0.0.255) const]&]
[s2; Same as IsSocketError() `|`| IsHttpError().&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:GetErrorDesc`(`)const:%- [_^String^ String]_[* GetErrorDesc]()_[@(0.0.255) c
onst]&]
[s2; Returns error description.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:ClearError`(`):%- [@(0.0.255) void]_[* ClearError]()&]
[s2; Clears all errors.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:GetHeader`(const char`*`):%- [_^String^ String]_[* GetHeader]([@(0.0.255) c
onst]_[@(0.0.255) char]_`*[*@3 id])&]
[s5;:HttpRequest`:`:operator`[`]`(const char`*`):%- [_^String^ String]_[* operator`[`]]([@(0.0.255) c
onst]_[@(0.0.255) char]_`*[*@3 id])&]
[s2; Returns response header field. [%-*@3 id] must be lowercase.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:GetRedirectUrl`(`):%- [_^String^ String]_[* GetRedirectUrl]()&]
[s2; Returns processed Location field of HTTP response header.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:GetContentLength`(`):%- [@(0.0.255) int]_[* GetContentLength]()&]
[s2; Returns the content length as specified in HTTP response header
or `-1 if not specified or header not yet loaded.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:GetStatusCode`(`)const:%- [@(0.0.255) int]_[* GetStatusCode]()_[@(0.0.255) c
onst]&]
[s2; If request is finished, returns HTTP status code.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:GetReasonPhrase`(`)const:%- [_^String^ String]_[* GetReasonPhrase]()_
[@(0.0.255) const]&]
[s2; If request is finished, returns HTTP reason phrase.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:GetContent`(`)const:%- [_^String^ String]_[* GetContent]()_[@(0.0.255) c
onst]&]
[s5;:HttpRequest`:`:operator`~`(`)const:%- [_^String^ String]_[* operator`~]()_[@(0.0.255) c
onst]&]
[s5;:HttpRequest`:`:operator String`(`)const:%- [* operator_String]()_[@(0.0.255) const]&]
[s2; Returns current gather content result.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:ClearContent`(`):%- [@(0.0.255) void]_[* ClearContent]()&]
[s2; Clears the content result to reduce memory consumption. Can
be called at any time.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:Do`(`):%- [@(0.0.255) bool]_[* Do]()&]
[s2; Progresses the request. Maximum duration is defined by Socket`::Timeout.
Returns true if processing is not finished.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:GetPhase`(`)const:%- [@(0.0.255) int]_[* GetPhase]()_[@(0.0.255) const]&]
[s2; Returns the current phase of request processing, one of BEGIN,
START, DNS, SSLPROXYREQUEST, SSLPROXYRESPONSE, SSLHANDSHAKE,
REQUEST, HEADER, BODY, CHUNK`_HEADER, CHUNK`_BODY, TRAILER, FINISHED,
FAILED.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:GetPhaseName`(`)const:%- [_^String^ String]_[* GetPhaseName]()_[@(0.0.255) c
onst]&]
[s2; Returns the text description of current request phase.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:InProgress`(`)const:%- [@(0.0.255) bool]_[* InProgress]()_[@(0.0.255) c
onst]&]
[s2; Returns true if request is still in progress.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:IsFailure`(`)const:%- [@(0.0.255) bool]_[* IsFailure]()_[@(0.0.255) con
st]&]
[s2; Request has failed (it can be either due to connection errors
or because the request did not ended with 2xx response code.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:IsSuccess`(`)const:%- [@(0.0.255) bool]_[* IsSuccess]()_[@(0.0.255) con
st]&]
[s2; Request succeeded.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:Execute`(`):%- [_^String^ String]_[* Execute]()&]
[s2; Performs the whole request, returns resulting content on success
or String`::GetVoid() on failer.&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:HttpRequest`(`):%- [* HttpRequest]()&]
[s2; &]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:HttpRequest`(const char`*`):%- [* HttpRequest]([@(0.0.255) const]_[@(0.0.255) c
har]_`*[*@3 url])&]
[s2; [%-*@3 url] .&]
[s3; &]
[s4; &]
[s5;:HttpRequest`:`:Trace`(bool`):%- [@(0.0.255) static] [@(0.0.255) void]_[* Trace]([@(0.0.255) b
ool]_[*@3 b]_`=_[@(0.0.255) true])&]
[s2; [%-*@3 b] .&]
[s3; &]
[s0; ]

View file

@ -13,8 +13,8 @@ topic "SocketWaitEvent";
[ {{10000@(113.42.0) [s0;%% [*@7;4 SocketWaitEvent]]}}&]
[s3; &]
[s1;:SocketWaitEvent`:`:class: [@(0.0.255)3 class][3 _][*3 SocketWaitEvent]&]
[s2;%% Encapsulates select call, allowing waiting on set of sockets
for specified events.&]
[s2;%% Encapsulates POSIX select call, allowing waiting on set of
sockets for specified events.&]
[s3; &]
[ {{10000F(128)G(128)@1 [s0;%% [* Public Method List]]}}&]
[s3; &]
@ -24,21 +24,20 @@ for specified events.&]
[s4; &]
[s5;:SocketWaitEvent`:`:Add`(SOCKET`,dword`): [@(0.0.255) void]_[* Add]([_^SOCKET^ SOCKET]_
[*@3 s], [_^dword^ dword]_[*@3 events]_`=_WAIT`_ALL)&]
[s2;%% Adds socket [%-*@3 s] to the list to be waited on specified
[%-*@3 events].&]
[s2;%% Adds socket [%-*@3 s] to the set to be waited on specified [%-*@3 events].&]
[s3;%% &]
[s4; &]
[s5;:SocketWaitEvent`:`:Add`(TcpSocket`&`,dword`): [@(0.0.255) void]_[* Add]([_^TcpSocket^ T
cpSocket][@(0.0.255) `&]_[*@3 s], [_^dword^ dword]_[*@3 events]_`=_WAIT`_ALL)&]
[s2;%% Adds TcpSocket [%-*@3 s] to the list to be waited on specified
[%-*@3 events]. If [%-*@3 s] is not open, it is not used but its
index is reserved.&]
index is reserved anyway (see Get).&]
[s3;%% &]
[s4; &]
[s5;:SocketWaitEvent`:`:Wait`(int`): [@(0.0.255) int]_[* Wait]([@(0.0.255) int]_[*@3 timeout])
&]
[s2;%% Waits for event for [%-*@3 timeout] ms. If [%-*@3 timeout] is
Null, call is blocking. Returns a number of sockets that signalled
Null, call is blocking. Returns a number of sockets that signaled
an event.&]
[s3;%% &]
[s4; &]

View file

@ -25,9 +25,9 @@ this output partial String to conserve memory.&]
[s3; &]
[s5;:Zlib`:`:WhenOut: [_^Callback2^ Callback2]<[@(0.0.255) const]_[@(0.0.255) void]_`*,
[_^dword^ dword]>_[* WhenOut]&]
[s2;%% Output callback. When there are output data available, they
are passed out using this callback. Default value stores data
into output String inside Zlib.&]
[s2;%% Output callback. Represents `"consumer function`": When there
are output data available, they are passed out using this callback.
Default value stores data into output String inside Zlib.&]
[s3; &]
[s4; &]
[s5;:Zlib`:`:Compress`(`): [@(0.0.255) void]_[* Compress]()&]
@ -38,11 +38,11 @@ into output String inside Zlib.&]
[s2;%% Sets Zlib into decompression mode (`"inflate`" in zlib terminology).&]
[s3; &]
[s4; &]
[s5;:Zlib`:`:Put`(const void`*`,dword`): [@(0.0.255) void]_[* Put]([@(0.0.255) const]_[@(0.0.255) v
oid]_`*[*@3 ptr], [_^dword^ dword]_[*@3 size])&]
[s5;:Zlib`:`:Put`(const void`*`,int`): [@(0.0.255) void]_[* Put]([@(0.0.255) const]_[@(0.0.255) v
oid]_`*[*@3 ptr], [@(0.0.255) int]_[*@3 size])&]
[s5;:Zlib`:`:Put`(const String`&`): [@(0.0.255) void]_[* Put]([@(0.0.255) const]_[_^String^ S
tring][@(0.0.255) `&]_[*@3 s])&]
[s2;%% Puts a bloct of data to be processed (compressed or decompressed
[s2;%% Puts a block of data to be processed (compressed or decompressed
based on mode) by Zlib.&]
[s3;%% &]
[s4; &]

View file

@ -213,21 +213,21 @@ void Zlib::Put0(const char *ptr, int size)
Pump(false);
}
void Zlib::Put(const void *ptr, dword size)
void Zlib::Put(const void *ptr, int size)
{
if(error)
return;
LLOG("ZLIB Put " << size);
const char *p = reinterpret_cast<const char *>(ptr);
while(size) {
int psz = (int) min(size, dword(INT_MAX / 4));
int psz = (int) min(size, INT_MAX / 4);
Put0(p, size);
size -= psz;
p += psz;
}
}
void Zlib::PutOut(const void *ptr, dword size)
void Zlib::PutOut(const void *ptr, int size)
{
LLOG("ZLIB PutOut " << out.GetCount());
out.Cat((const char *)ptr, (int)size);

View file

@ -34,7 +34,7 @@ class Zlib {
String gzip_comment;
String out;
void PutOut(const void *ptr, dword size);
void PutOut(const void *ptr, int size);
void Pump(bool finish);
void Begin();
void Free();
@ -43,11 +43,11 @@ class Zlib {
void Init();
public:
Callback2<const void *, dword> WhenOut;
Callback2<const void *, int> WhenOut;
void Compress();
void Decompress();
void Put(const void *ptr, dword size);
void Put(const void *ptr, int size);
void Put(const String& s) { Put(~s, s.GetCount()); }
void End();
void Clear();