/* * add a message to the sending queue. * iLen = required size of the memory block to hold the message */ int SendQueue::addTo(TWindowData *dat, const int iLen, int dwFlags) { int iLength = 0, i; int iFound = NR_SENDJOBS; if (m_currentIndex >= NR_SENDJOBS) { _DebugPopup(dat->hContact, _T("Send queue full")); return 0; } /* * find a free entry in the send queue... */ for (i = 0; i < NR_SENDJOBS; i++) { if (m_jobs[i].hOwner != 0 || m_jobs[i].iStatus != 0) { // this entry is used, check if it's orphaned and can be removed... if (m_jobs[i].hwndOwner && IsWindow(m_jobs[i].hwndOwner)) // window exists, do not reuse it continue; if (time(NULL) - m_jobs[i].dwTime < 120) // non-acked entry, but not old enough, don't re-use it continue; clearJob(i); iFound = i; goto entry_found; } iFound = i; break; } entry_found: if (iFound == NR_SENDJOBS) { _DebugPopup(dat->hContact, _T("Send queue full")); return 0; } iLength = iLen; if (iLength > 0) { if (m_jobs[iFound].sendBuffer == NULL) { if (iLength < HISTORY_INITIAL_ALLOCSIZE) iLength = HISTORY_INITIAL_ALLOCSIZE; m_jobs[iFound].sendBuffer = (char *)malloc(iLength); m_jobs[iFound].dwLen = iLength; } else { if (iLength > m_jobs[iFound].dwLen) { m_jobs[iFound].sendBuffer = (char *)realloc(m_jobs[iFound].sendBuffer, iLength); m_jobs[iFound].dwLen = iLength; } } CopyMemory(m_jobs[iFound].sendBuffer, dat->sendBuffer, iLen); } m_jobs[iFound].dwFlags = dwFlags; m_jobs[iFound].dwTime = time(NULL); HWND hwndDlg = dat->hwnd; dat->cache->saveHistory(0, 0); ::SetDlgItemText(hwndDlg, IDC_MESSAGE, _T("")); ::SetFocus(GetDlgItem(hwndDlg, IDC_MESSAGE)); UpdateSaveAndSendButton(dat); sendQueued(dat, iFound); return 0; }
void PacketQueue::add(const void* data, int len) { switch (getProtocolOpcode(data)) { case OP_Combined: readCombined(data, len); break; case OP_Packet: case OP_Fragment: { uint16_t seq = getSequence(data); if (seq == m_nextSeq) { m_connection.sendToLocal(data, len); sendQueued(seq + 1); } else { enqueue(data, len, seq); } break; } case OP_SessionDisconnect: m_connection.endSession(); // Fallthrough default: // Forward anything that didn't need special handling m_connection.sendToLocal(data, len); break; } }
int SendQueue::addTo(TWindowData *dat, size_t iLen, int dwFlags) { int i; int iFound = NR_SENDJOBS; if (m_currentIndex >= NR_SENDJOBS) { _DebugPopup(dat->hContact, _T("Send queue full")); return 0; } // find a mir_free entry in the send queue... for (i = 0; i < NR_SENDJOBS; i++) { if (m_jobs[i].hContact != 0 || m_jobs[i].iStatus != 0) { // this entry is used, check if it's orphaned and can be removed... if (m_jobs[i].hOwnerWnd && IsWindow(m_jobs[i].hOwnerWnd)) // window exists, do not reuse it continue; if (time(NULL) - m_jobs[i].dwTime < 120) // non-acked entry, but not old enough, don't re-use it continue; clearJob(i); iFound = i; goto entry_found; } iFound = i; break; } entry_found: if (iFound == NR_SENDJOBS) { _DebugPopup(dat->hContact, _T("Send queue full")); return 0; } SendJob &job = m_jobs[iFound]; job.szSendBuffer = (char*)mir_alloc(iLen); memcpy(job.szSendBuffer, dat->sendBuffer, iLen); job.dwFlags = dwFlags; job.dwTime = time(NULL); HWND hwndDlg = dat->hwnd; dat->cache->saveHistory(0, 0); ::SetDlgItemText(hwndDlg, IDC_MESSAGE, _T("")); ::SetFocus(GetDlgItem(hwndDlg, IDC_MESSAGE)); UpdateSaveAndSendButton(dat); sendQueued(dat, iFound); return 0; }
uint32_t HTTPClientChannel::sendRequest( RpcOptions& rpcOptions, std::unique_ptr<RequestCallback> cb, std::unique_ptr<apache::thrift::ContextStack> ctx, unique_ptr<IOBuf> buf, std::shared_ptr<THeader> header) { // cb is not allowed to be null. DCHECK(cb); DestructorGuard dg(this); cb->context_ = RequestContext::saveContext(); std::chrono::milliseconds timeout(timeout_); if (rpcOptions.getTimeout() > std::chrono::milliseconds(0)) { timeout = rpcOptions.getTimeout(); } auto twcb = new HTTPTransactionTwowayCallback(std::move(cb), std::move(ctx), isSecurityActive(), protocolId_, timer_.get(), std::chrono::milliseconds(timeout_)); if (!httpSession_) { TTransportException ex(TTransportException::NOT_OPEN, "HTTPSession is not open"); twcb->messageSendError( folly::make_exception_wrapper<TTransportException>(std::move(ex))); delete twcb; return -1; } auto txn = httpSession_->newTransaction(twcb); if (!txn) { TTransportException ex(TTransportException::NOT_OPEN, "Too many active requests on connection"); // Might be able to create another transaction soon ex.setOptions(TTransportException::CHANNEL_IS_VALID); twcb->messageSendError( folly::make_exception_wrapper<TTransportException>(std::move(ex))); delete twcb; return -1; } auto streamId = txn->getID(); setRequestHeaderOptions(header.get()); addRpcOptionHeaders(header.get(), rpcOptions); auto msg = buildHTTPMessage(header.get()); txn->sendHeaders(msg); txn->sendBody(std::move(buf)); txn->sendEOM(); twcb->sendQueued(); return (uint32_t)streamId; }