| 76 | } |
| 77 | |
| 78 | int silkBioWrite(BIO * bio, const char * buf, int len) |
| 79 | { |
| 80 | auto * socket_impl = static_cast<Poco::Net::SocketImpl *>(BIO_get_data(bio)); |
| 81 | const int fd = socket_impl->sockfd(); |
| 82 | const uint64_t timeout_ns = timeoutNs(socket_impl->getSendTimeout()); |
| 83 | |
| 84 | uint64_t bytes_written = 0; |
| 85 | silk::FiberScheduler::IoFuture future; |
| 86 | iovec iov{const_cast<char *>(buf), static_cast<size_t>(len)}; |
| 87 | silk::FiberScheduler::write(fd, &iov, 1, 0, &bytes_written, &future); |
| 88 | |
| 89 | int r = timeout_ns > 0 |
| 90 | ? silk::FiberFuture::waitWithTimeout(&future, timeout_ns) |
| 91 | : future.wait(); |
| 92 | |
| 93 | if (r == ETIMEDOUT) |
| 94 | { |
| 95 | future.cancel(); |
| 96 | r = future.wait(); |
| 97 | if (r == ECANCELED) |
| 98 | r = ETIMEDOUT; |
| 99 | } |
| 100 | |
| 101 | BIO_clear_retry_flags(bio); |
| 102 | |
| 103 | if (r == 0) |
| 104 | return static_cast<int>(bytes_written); |
| 105 | |
| 106 | errno = r; |
| 107 | if (BIO_sock_non_fatal_error(r) || r == ETIMEDOUT) |
| 108 | BIO_set_retry_write(bio); |
| 109 | return -1; |
| 110 | } |
| 111 | |
| 112 | long silkBioCtrl(BIO * bio, int cmd, [[maybe_unused]] long larg, void * parg) // NOLINT(google-runtime-int) |
| 113 | { |