本文整理汇总了C++中Protocol::Send方法的典型用法代码示例。如果您正苦于以下问题:C++ Protocol::Send方法的具体用法?C++ Protocol::Send怎么用?C++ Protocol::Send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Protocol
的用法示例。
在下文中一共展示了Protocol::Send方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InOut
static void InOut(
HANDLE hC0C,
SOCKET hSock,
Protocol &protocol,
BOOL ignoreDSR,
SOCKET hSockListen = INVALID_SOCKET)
{
printf("InOut() START\n");
protocol.Clean();
BOOL stop = FALSE;
enum {
EVENT_READ,
EVENT_SENT,
EVENT_RECEIVED,
EVENT_WRITTEN,
EVENT_STAT,
EVENT_CLOSE,
EVENT_ACCEPT,
EVENT_NUM
};
HANDLE hEvents[EVENT_NUM];
OVERLAPPED overlaps[EVENT_NUM];
if (!PrepareEvents(EVENT_NUM, hEvents, overlaps))
stop = TRUE;
if (!SetCommMask(hC0C, EV_DSR)) {
TraceLastError("InOut(): SetCommMask()");
stop = TRUE;
}
WSAEventSelect(hSock, hEvents[EVENT_CLOSE], FD_CLOSE);
if (hSockListen != INVALID_SOCKET)
WSAEventSelect(hSockListen, hEvents[EVENT_ACCEPT], FD_ACCEPT);
DWORD not_used;
BYTE cbufRead[64];
BOOL waitingRead = FALSE;
BYTE cbufSend[64];
int cbufSendSize = 0;
int cbufSendDone = 0;
BOOL waitingSend = FALSE;
BYTE cbufRecv[64];
BOOL waitingRecv = FALSE;
BYTE cbufWrite[64];
int cbufWriteSize = 0;
int cbufWriteDone = 0;
BOOL waitingWrite = FALSE;
BOOL waitingStat = FALSE;
int DSR = -1;
while (!stop) {
if (!waitingSend) {
if (!cbufSendSize) {
cbufSendSize = protocol.Read(cbufSend, sizeof(cbufSend));
if (cbufSendSize < 0)
break;
}
DWORD num = cbufSendSize - cbufSendDone;
if (num) {
if (!WriteFile((HANDLE)hSock, cbufSend + cbufSendDone, num, ¬_used, &overlaps[EVENT_SENT])) {
if (::GetLastError() != ERROR_IO_PENDING) {
TraceLastError("InOut(): WriteFile(hSock)");
break;
}
}
waitingSend = TRUE;
}
}
if (!waitingRead && !protocol.isSendFull()) {
if (!ReadFile(hC0C, cbufRead, sizeof(cbufRead), ¬_used, &overlaps[EVENT_READ])) {
if (::GetLastError() != ERROR_IO_PENDING) {
TraceLastError("InOut(): ReadFile(hC0C)");
break;
}
}
waitingRead = TRUE;
}
if (!waitingWrite) {
if (!cbufWriteSize) {
cbufWriteSize = protocol.Recv(cbufWrite, sizeof(cbufWrite));
if (cbufWriteSize < 0)
break;
}
DWORD num = cbufWriteSize - cbufWriteDone;
//.........这里部分代码省略.........