📄 cksocket.h
字号:
// CkSocket.h: interface for the CkSocket class.
//
//////////////////////////////////////////////////////////////////////
#ifndef _CKSOCKET_H
#define _CKSOCKET_H
#pragma once
class CkByteData;
#include "CkString.h"
#include "CkObject.h"
class CkCert;
class CkSocketProgress;
#pragma warning( disable : 4068 )
#pragma unmanaged
/*
IMPORTANT: Objects returned by methods as non-const pointers must be deleted
by the calling application.
*/
// CLASS: CkSocket
class CkSocket : public CkObject
{
public:
CkSocket();
virtual ~CkSocket();
bool SendBytes(const char *byteData, unsigned long numBytes);
// BEGIN PUBLIC INTERFACE
bool get_Utf8(void) const;
void put_Utf8(bool b);
CkSocketProgress *get_EventCallbackObject(void) const { return m_callback; }
void put_EventCallbackObject(CkSocketProgress *progress) { m_callback = progress; }
CkCert *GetSslServerCert(void);
CkCert *GetMyCert(void);
bool UnlockComponent(const char *code);
bool IsUnlocked(void) const;
// Error log retrieval and saving (these methods are common to all Chilkat VC++ classes.)
bool SaveLastError(const char *filename);
void LastErrorXml(CkString &str);
void LastErrorHtml(CkString &str);
void LastErrorText(CkString &str);
void get_Version(CkString &str);
long get_ObjectId(void);
bool AsyncDnsStart(const char *hostname, int maxWaitMs);
bool get_AsyncDnsFinished(void); // True if finished, false if in progress.
void get_AsyncDnsResult(CkString &str);
void AsyncDnsAbort(void); // Abort the async DNS operation.
void get_AsyncDnsLog(CkString &str);
bool get_AsyncDnsSuccess(void); // True if successful, false if aborted or failed.
bool AsyncConnectStart(const char *hostname, int port, bool ssl, int maxWaitMs);
bool get_AsyncConnectFinished(void); // True if finished, false if in progress.
void AsyncConnectAbort(void); // Abort the async connect operation.
void get_AsyncConnectLog(CkString &str);
bool get_AsyncConnectSuccess(void); // True if successful, false if aborted or failed.
void SleepMs(int millisec) const;
void get_MyIpAddress(CkString &str);
bool BindAndListen(int port, int backlog);
// Synchronous connect and accept.
bool Connect(const char *hostname, int port, bool ssl, int maxWaitMs);
CkSocket *AcceptNextConnection(int maxWaitMs);
void Close(int maxWaitMs);
bool get_Ssl(void);
void put_Ssl(bool newVal);
bool InitSslServer(CkCert &cert);
// 0 = success
// 1-299 = underlying reasons
// Normal sockets:
// 1 = empty hostname
// 2 = DNS lookup failed
// 3 = DNS timeout
// 4 = Aborted by application.
// 5 = Internal failure.
// 6 = Connect Timed Out
// 7 = Connect Rejected (or failed for some other reason)
// SSL:
// 100 = Internal schannel error
// 101 = Failed to create credentials
// 102 = Failed to send initial message to proxy.
// 103 = Handshake failed.
// 104 = Failed to obtain remote certificate.
long get_ConnectFailReason(void);
long get_HeartbeatMs(void);
void put_HeartbeatMs(long millisec);
long get_MaxSendIdleMs(void);
void put_MaxSendIdleMs(long millisec);
long get_MaxReadIdleMs(void);
void put_MaxReadIdleMs(long millisec);
void get_StringCharset(CkString &str);
void put_StringCharset(const char *str);
long get_DebugDnsDelayMs(void);
void put_DebugDnsDelayMs(long millisec);
long get_DebugConnectDelayMs(void);
void put_DebugConnectDelayMs(long millisec);
bool get_IsConnected(void);
long get_RemotePort(void);
void get_RemoteIpAddress(CkString &str);
bool AsyncAcceptStart(int maxWaitMs);
bool get_AsyncAcceptFinished(void);
void AsyncAcceptAbort(void);
void get_AsyncAcceptLog(CkString &str);
bool get_AsyncAcceptSuccess(void);
CkSocket *AsyncAcceptSocket(void);
bool AsyncSendBytes(const unsigned char *byteData, unsigned long numBytes);
bool AsyncSendString(const char *str);
bool get_AsyncSendFinished(void); // True if finished, false if in progress.
void AsyncSendAbort(void); // Abort the async send operation.
void get_AsyncSendLog(CkString &str);
bool get_AsyncSendSuccess(void); // True if successful, false if aborted or failed.
bool AsyncReceiveBytes(void);
bool AsyncReceiveBytesN(unsigned long numBytes);
bool AsyncReceiveString(void);
bool AsyncReceiveToCRLF(void);
bool AsyncReceiveUntilMatch(const char *matchStr);
bool get_AsyncReceiveFinished(void); // True if finished, false if in progress.
void AsyncReceiveAbort(void); // Abort the async receive operation.
void get_AsyncReceiveLog(CkString &str);
bool get_AsyncReceiveSuccess(void); // True if successful, false if aborted or failed.
void get_AsyncReceivedString(CkString &str);
void get_AsyncReceivedBytes(CkByteData &byteData);
const char *asyncReceivedString(void);
const char *asyncReceiveLog(void);
const char *asyncSendLog(void);
void BuildHttpGetRequest(const char *url, CkString &str);
long get_SendPacketSize(void);
void put_SendPacketSize(long sizeInBytes);
long get_ReceivePacketSize(void);
void put_ReceivePacketSize(long sizeInBytes);
bool SendString(const char *str);
bool SendBytes(const unsigned char *byteData, unsigned long numBytes);
bool ReceiveString(CkString &strOut);
bool ReceiveUntilMatch(const char *matchStr, CkString &strOut);
bool ReceiveBytes(CkByteData &byteData);
bool ReceiveBytesN(unsigned long numBytes, CkByteData &byteData);
const char *stringCharset(void);
const char *remoteIpAddress(void);
const char *asyncAcceptLog(void);
const char *buildHttpGetRequest(const char *url);
const char *receiveString(void);
const char *receiveUntilMatch(const char *matchStr);
CkString m_resultString;
const char *lastErrorText(void);
const char *lastErrorXml(void);
const char *lastErrorHtml(void);
const char *asyncDnsResult(void);
const char *asyncDnsLog(void);
const char *asyncConnectLog(void);
const char *myIpAddress(void);
const char *version(void);
// END PUBLIC INTERFACE
// For internal use only.
private:
CkSocketProgress *m_callback;
void *m_implCb;
void *m_impl;
bool m_utf8; // If true, all input "const char *" parameters are utf-8, otherwise they are ANSI strings.
// Don't allow assignment or copying these objects.
CkSocket(const CkSocket &) { }
CkSocket &operator=(const CkSocket &) { return *this; }
CkSocket(void *impl);
public:
void *getImpl(void) const { return m_impl; }
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -