static int hasTimedOut(int milliseconds) { static struct timeval start = { 0, 0 }; if (milliseconds) return millisecondsSince(&start) >= milliseconds; gettimeofday(&start, NULL); return 1; }
virtual void handshakeError(TAsyncSSLSocket* sock, const TTransportException& ex) noexcept { auto elapsedTime = millisecondsSince(acceptTime_); VLOG(3) << "SSL handshake error after " << elapsedTime.count() << " ms; " << sock->getRawBytesReceived() << " bytes received & " << sock->getRawBytesWritten() << " bytes sent: " << ex.what(); acceptor_->updateSSLStats(sock, elapsedTime, sslError_); acceptor_->sslConnectionError(); delete this; }
// TAsyncSSLSocket::HandshakeCallback API virtual void handshakeSuccess(TAsyncSSLSocket* sock) noexcept { const unsigned char* nextProto = nullptr; unsigned nextProtoLength = 0; sock->getSelectedNextProtocol(&nextProto, &nextProtoLength); if (VLOG_IS_ON(3)) { if (nextProto) { VLOG(3) << "Client selected next protocol " << string((const char*)nextProto, nextProtoLength); } else { VLOG(3) << "Client did not select a next protocol"; } } // fill in SSL-related fields from TransportInfo // the other fields like RTT are filled in the Acceptor TransportInfo tinfo; tinfo.ssl = true; tinfo.acceptTime = acceptTime_; tinfo.sslSetupTime = millisecondsSince(acceptTime_); tinfo.sslSetupBytesRead = sock->getRawBytesReceived(); tinfo.sslSetupBytesWritten = sock->getRawBytesWritten(); tinfo.sslServerName = sock->getSSLServerName(); tinfo.sslCipher = sock->getNegotiatedCipherName(); tinfo.sslVersion = sock->getSSLVersion(); tinfo.sslCertSize = sock->getSSLCertSize(); tinfo.sslResume = SSLUtil::getResumeState(sock); sock->getSSLClientCiphers(tinfo.sslClientCiphers); sock->getSSLServerCiphers(tinfo.sslServerCiphers); tinfo.sslClientComprMethods = sock->getSSLClientComprMethods(); tinfo.sslClientExts = sock->getSSLClientExts(); tinfo.sslNextProtocol.assign( reinterpret_cast<const char*>(nextProto), nextProtoLength); acceptor_->updateSSLStats(sock, tinfo.sslSetupTime, SSLErrorEnum::NO_ERROR); acceptor_->downstreamConnectionManager_->removeConnection(this); acceptor_->sslConnectionReady(std::move(socket_), clientAddr_, nextProto ? string((const char*)nextProto, nextProtoLength) : empty_string, tinfo); delete this; }
void HTTPConnector::connectSuccess() noexcept { if (!cb_) { return; } folly::SocketAddress localAddress; folly::SocketAddress peerAddress; socket_->getLocalAddress(&localAddress); socket_->getPeerAddress(&peerAddress); std::unique_ptr<HTTPCodec> codec; transportInfo_.acceptTime = getCurrentTime(); if (transportInfo_.ssl) { AsyncSSLSocket* sslSocket = dynamic_cast<AsyncSSLSocket*>(socket_.get()); const char* npnProto; unsigned npnProtoLen; sslSocket->getSelectedNextProtocol( reinterpret_cast<const unsigned char**>(&npnProto), &npnProtoLen); transportInfo_.sslNextProtocol = std::make_shared<std::string>(npnProto, npnProtoLen); transportInfo_.sslSetupTime = millisecondsSince(connectStart_); transportInfo_.sslCipher = sslSocket->getNegotiatedCipherName() ? std::make_shared<std::string>(sslSocket->getNegotiatedCipherName()) : nullptr; transportInfo_.sslVersion = sslSocket->getSSLVersion(); transportInfo_.sslResume = wangle::SSLUtil::getResumeState(sslSocket); codec = makeCodec(*transportInfo_.sslNextProtocol, forceHTTP1xCodecTo1_1_); } else { codec = makeCodec(plaintextProtocol_, forceHTTP1xCodecTo1_1_); } HTTPUpstreamSession* session = new HTTPUpstreamSession( timeoutSet_, std::move(socket_), localAddress, peerAddress, std::move(codec), transportInfo_, nullptr); cb_->connectSuccess(session); }
void HTTPConnector::connectSuccess() noexcept { if (!cb_) { return; } folly::SocketAddress localAddress; folly::SocketAddress peerAddress; socket_->getLocalAddress(&localAddress); socket_->getPeerAddress(&peerAddress); std::unique_ptr<HTTPCodec> codec; transportInfo_.acceptTime = getCurrentTime(); if (transportInfo_.secure) { AsyncSSLSocket* sslSocket = socket_->getUnderlyingTransport<AsyncSSLSocket>(); if (sslSocket) { transportInfo_.sslNextProtocol = std::make_shared<std::string>(socket_->getApplicationProtocol()); transportInfo_.sslSetupTime = millisecondsSince(connectStart_); transportInfo_.sslCipher = sslSocket->getNegotiatedCipherName() ? std::make_shared<std::string>(sslSocket->getNegotiatedCipherName()) : nullptr; transportInfo_.sslVersion = sslSocket->getSSLVersion(); transportInfo_.sslResume = wangle::SSLUtil::getResumeState(sslSocket); } codec = makeCodec(socket_->getApplicationProtocol(), forceHTTP1xCodecTo1_1_); } else { codec = makeCodec(plaintextProtocol_, forceHTTP1xCodecTo1_1_); } HTTPUpstreamSession* session = new HTTPUpstreamSession( timeout_, std::move(socket_), localAddress, peerAddress, std::move(codec), transportInfo_, nullptr); cb_->connectSuccess(session); }
static int awaitCursorMotion (RoutingData *routing, int direction) { int oldx = (routing->oldx = routing->curx); int oldy = (routing->oldy = routing->cury); long timeout = routing->timeSum / routing->timeCount; int moved = 0; TimeValue start; getCurrentTime(&start); while (1) { long time; approximateDelay(ROUTING_INTERVAL); time = millisecondsSince(&start) + 1; { int row = routing->cury + routing->verticalDelta; int bestRow = row; int bestLength = 0; do { ScreenCharacter buffer[routing->screenColumns]; if (!readScreenRow(routing, buffer, row)) break; { int before = routing->curx; int after = before; while (buffer[before].text == routing->rowBuffer[before].text) if (--before < 0) break; while (buffer[after].text == routing->rowBuffer[after].text) if (++after >= routing->screenColumns) break; { int length = after - before - 1; if (length > bestLength) { bestRow = row; if ((bestLength = length) == routing->screenColumns) break; } } } row -= direction; } while ((row >= 0) && (row < routing->screenRows)); routing->verticalDelta = bestRow - routing->cury; } oldy = routing->cury; oldx = routing->curx; if (!getCurrentPosition(routing)) return 0; if ((routing->cury != oldy) || (routing->curx != oldx)) { logRouting("moved: [%d,%d] -> [%d,%d]", oldx, oldy, routing->curx, routing->cury); if (!moved) { moved = 1; timeout = time * 2; routing->timeSum += time * 8; routing->timeCount += 1; } } else if (time > timeout) { if (!moved) { logRouting("timed out"); } break; } } return 1; }
std::chrono::milliseconds HTTPConnector::timeElapsed() { if (timePointInitialized(connectStart_)) { return millisecondsSince(connectStart_); } return std::chrono::milliseconds(0); }
static int brl_readCommand (BrailleDisplay *brl, KeyTableCommandContext context) { unsigned char byte; const InputMode *mode; const InputBinding *binding; { int result = serialReadData(serialDevice, &byte, 1, 0, 0); if (result == 0) { if (inputMode->temporary) if (millisecondsSince(&inputTime) > 3000) resetInputMode(); return EOF; } if (result == -1) { logSystemError("read"); return BRL_CMD_RESTARTBRL; } } mode = inputMode; if (mode->temporary) resetInputMode(); switch (byte) { case KEY_F1: binding = &mode->keyF1; break; case KEY_F2: binding = &mode->keyF2; break; case KEY_LEFT: binding = &mode->keyLeft; break; case KEY_RIGHT: binding = &mode->keyRight; break; case KEY_UP: binding = &mode->keyUp; break; case KEY_DOWN: binding = &mode->keyDown; break; case KEY_CENTER: binding = &mode->keyCenter; break; default: logMessage(LOG_WARNING, "unhandled key: %s -> %02X", mode->name, byte); beep(brl); return EOF; } switch (binding->type) { case IBT_unbound: logMessage(LOG_WARNING, "unbound key: %s -> %02X", mode->name, byte); beep(brl); break; case IBT_command: return binding->value.command; case IBT_block: return binding->value.block + cursorOffset; case IBT_function: return binding->value.function(brl); case IBT_submode: { setInputMode(binding->value.submode); break; } default: logMessage(LOG_WARNING, "unhandled input binding type: %02X", binding->type); break; } return BRL_CMD_NOOP; }