feat(clients): adk+live: close gaps (YAML config import, VertexModel only, MCP tools/call and A2A card live, AP2 v0.2, live features verified, wolfSSL timeout/close status and MSG_NOSIGNAL)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -28,6 +28,27 @@ std::once_flag& init_flag() {
|
||||
return f;
|
||||
}
|
||||
|
||||
// Socket send for wolfSSL: the default callback calls send() without
|
||||
// MSG_NOSIGNAL, so a vanished peer raises SIGPIPE and kills the process.
|
||||
int SendNoSignal(WOLFSSL*, char* buf, int sz, void* ctx) {
|
||||
int fd = *static_cast<int*>(ctx);
|
||||
for (;;) {
|
||||
ssize_t n = ::send(fd, buf, (size_t)sz, MSG_NOSIGNAL);
|
||||
if (n >= 0) return (int)n;
|
||||
switch (errno) {
|
||||
case EINTR: continue;
|
||||
case EAGAIN:
|
||||
#if EWOULDBLOCK != EAGAIN
|
||||
case EWOULDBLOCK:
|
||||
#endif
|
||||
return WOLFSSL_CBIO_ERR_WANT_WRITE;
|
||||
case ECONNRESET: return WOLFSSL_CBIO_ERR_CONN_RST;
|
||||
case EPIPE: return WOLFSSL_CBIO_ERR_CONN_CLOSE;
|
||||
default: return WOLFSSL_CBIO_ERR_GENERAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class WolfTlsSession : public ITlsSession {
|
||||
public:
|
||||
WolfTlsSession() = default;
|
||||
@@ -69,6 +90,7 @@ class WolfTlsSession : public ITlsSession {
|
||||
}
|
||||
if (wolfSSL_set_fd(ssl_.get(), fd) != WOLFSSL_SUCCESS)
|
||||
throw TlsError("wolfSSL_set_fd failed");
|
||||
wolfSSL_SSLSetIOSend(ssl_.get(), SendNoSignal); // keeps the fd context set_fd installed
|
||||
// Blocking handshake is fine: fd is blocking here; timeouts enforced
|
||||
// by connect phase + socket is local-fast. Keep it simple and correct.
|
||||
if (wolfSSL_connect(ssl_.get()) != WOLFSSL_SUCCESS) {
|
||||
@@ -94,30 +116,41 @@ class WolfTlsSession : public ITlsSession {
|
||||
while (sent < size) {
|
||||
int n = wolfSSL_write(ssl_.get(), data + sent, (int)(size - sent));
|
||||
if (n <= 0) {
|
||||
// The fd is blocking with SO_SNDTIMEO: WANT_READ / WANT_WRITE here is
|
||||
// the socket timeout expiring. Retrying would spin without a bound.
|
||||
int err = wolfSSL_get_error(ssl_.get(), n);
|
||||
if (err == WOLFSSL_CBIO_ERR_WANT_READ ||
|
||||
err == WOLFSSL_CBIO_ERR_WANT_WRITE)
|
||||
continue;
|
||||
if (err == WOLFSSL_ERROR_WANT_READ || err == WOLFSSL_ERROR_WANT_WRITE)
|
||||
throw TlsTimeoutError("wolfSSL write timed out");
|
||||
throw TlsError("wolfSSL write failed");
|
||||
}
|
||||
sent += (std::size_t)n;
|
||||
}
|
||||
}
|
||||
|
||||
// Socket read timeout: throws TlsTimeoutError. Closed connection (TLS
|
||||
// close_notify, or a TCP drop without one): returns 0 and
|
||||
// last_read_status() is kClosed. Measured against a TLS 1.3 server: a
|
||||
// timeout is n=-1 with WOLFSSL_ERROR_WANT_READ, a drop is n=0 then
|
||||
// WOLFSSL_ERROR_SYSCALL, a close_notify is n=0 then WOLFSSL_ERROR_ZERO_RETURN.
|
||||
std::size_t recv_some(char* out, std::size_t max_size) override {
|
||||
if (!ssl_) throw TlsError("TLS session not established");
|
||||
int n = wolfSSL_read(ssl_.get(), out, (int)max_size);
|
||||
if (n < 0) {
|
||||
int err = wolfSSL_get_error(ssl_.get(), n);
|
||||
if (err == WOLFSSL_CBIO_ERR_WANT_READ ||
|
||||
err == WOLFSSL_CBIO_ERR_WANT_WRITE)
|
||||
return 0;
|
||||
if (err == WOLFSSL_ERROR_ZERO_RETURN) return 0;
|
||||
throw TlsError("wolfSSL read failed");
|
||||
if (n > 0) {
|
||||
status_ = TlsReadStatus::kData;
|
||||
return (std::size_t)n;
|
||||
}
|
||||
return (std::size_t)n;
|
||||
int err = wolfSSL_get_error(ssl_.get(), n);
|
||||
if (err == WOLFSSL_ERROR_WANT_READ || err == WOLFSSL_ERROR_WANT_WRITE)
|
||||
throw TlsTimeoutError("wolfSSL read timed out");
|
||||
if (n == 0 || err == WOLFSSL_ERROR_ZERO_RETURN || err == WOLFSSL_ERROR_SYSCALL) {
|
||||
status_ = TlsReadStatus::kClosed;
|
||||
return 0;
|
||||
}
|
||||
throw TlsError("wolfSSL read failed");
|
||||
}
|
||||
|
||||
TlsReadStatus last_read_status() const override { return status_; }
|
||||
|
||||
std::string negotiated_protocol() const override { return alpn_; }
|
||||
|
||||
void shutdown() override {
|
||||
@@ -146,6 +179,7 @@ class WolfTlsSession : public ITlsSession {
|
||||
std::unique_ptr<WOLFSSL, SslDeleter> ssl_;
|
||||
int fd_ = -1;
|
||||
std::string alpn_;
|
||||
TlsReadStatus status_ = TlsReadStatus::kUnknown;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user