本文整理汇总了C++中SSL_pending函数的典型用法代码示例。如果您正苦于以下问题:C++ SSL_pending函数的具体用法?C++ SSL_pending怎么用?C++ SSL_pending使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SSL_pending函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sslRead
/*
Return the number of bytes read. Return -1 on errors and EOF. Distinguish EOF via mprIsSocketEof.
If non-blocking, may return zero if no data or still handshaking.
*/
PUBLIC ssize sslRead(Webs *wp, void *buf, ssize len)
{
WebsSocket *sp;
char ebuf[ME_GOAHEAD_LIMIT_STRING];
ulong serror;
int rc, error, retries, i;
if (wp->ssl == 0 || len <= 0) {
return -1;
}
/*
Limit retries on WANT_READ. If non-blocking and no data, then this can spin forever.
*/
sp = socketPtr(wp->sid);
retries = 5;
for (i = 0; i < retries; i++) {
rc = SSL_read(wp->ssl, buf, (int) len);
if (rc < 0) {
error = SSL_get_error(wp->ssl, rc);
if (error == SSL_ERROR_WANT_READ || error == SSL_ERROR_WANT_CONNECT || error == SSL_ERROR_WANT_ACCEPT) {
continue;
}
serror = ERR_get_error();
ERR_error_string_n(serror, ebuf, sizeof(ebuf) - 1);
trace(5, "SSL_read %s", ebuf);
}
break;
}
if (rc <= 0) {
error = SSL_get_error(wp->ssl, rc);
if (error == SSL_ERROR_WANT_READ) {
rc = 0;
} else if (error == SSL_ERROR_WANT_WRITE) {
rc = 0;
} else if (error == SSL_ERROR_ZERO_RETURN) {
sp->flags |= SOCKET_EOF;
rc = -1;
} else if (error == SSL_ERROR_SYSCALL) {
sp->flags |= SOCKET_EOF;
rc = -1;
} else if (error != SSL_ERROR_ZERO_RETURN) {
serror = ERR_get_error();
ERR_error_string_n(serror, ebuf, sizeof(ebuf) - 1);
trace(4, "OpenSSL: connection with protocol error: %s", ebuf);
rc = -1;
sp->flags |= SOCKET_EOF;
}
} else if (SSL_pending(wp->ssl) > 0) {
socketHiddenData(sp, SSL_pending(wp->ssl), SOCKET_READABLE);
}
return rc;
}
示例2: sycSSL_pending
int sycSSL_pending(SSL *ssl) {
int result;
Debug1("SSL_pending(%p)", ssl);
result = SSL_pending(ssl);
Debug1("SSL_pending() -> %d", result);
return result;
}
示例3: sock_check
static gboolean sock_check(GSource *source)
{
SockInfo *sock = ((SockSource *)source)->sock;
struct timeval timeout = {0, 0};
fd_set fds;
GIOCondition condition = sock->condition;
#if USE_SSL
if (sock->ssl) {
if (condition & G_IO_IN) {
if (SSL_pending(sock->ssl) > 0)
return TRUE;
if (SSL_want_write(sock->ssl))
condition |= G_IO_OUT;
}
if (condition & G_IO_OUT) {
if (SSL_want_read(sock->ssl))
condition |= G_IO_IN;
}
}
#endif
FD_ZERO(&fds);
FD_SET(sock->sock, &fds);
select(sock->sock + 1,
(condition & G_IO_IN) ? &fds : NULL,
(condition & G_IO_OUT) ? &fds : NULL,
NULL, &timeout);
return FD_ISSET(sock->sock, &fds) != 0;
}
示例4: ssl_peek
gint ssl_peek(SSL *ssl, gchar *buf, gint len)
{
gint err, ret;
if (SSL_pending(ssl) == 0) {
if (fd_check_io(SSL_get_rfd(ssl), G_IO_IN) < 0)
return -1;
}
ret = SSL_peek(ssl, buf, len);
switch ((err = SSL_get_error(ssl, ret))) {
case SSL_ERROR_NONE:
return ret;
case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE:
errno = EAGAIN;
return -1;
case SSL_ERROR_ZERO_RETURN:
return 0;
default:
g_warning("SSL_peek() returned error %d, ret = %d\n", err, ret);
if (ret == 0)
return 0;
return -1;
}
}
示例5: lws_ssl_capable_read
LWS_VISIBLE int
lws_ssl_capable_read(struct libwebsocket_context *context,
struct libwebsocket *wsi, unsigned char *buf, int len)
{
int n;
if (!wsi->ssl)
return lws_ssl_capable_read_no_ssl(context, wsi, buf, len);
wsi->buffered_reads_pending = 0;
n = SSL_read(wsi->ssl, buf, len);
if (n >= 0) {
/*
* if it was our buffer that limited what we read,
* check if SSL has additional data pending inside SSL buffers.
*
* Because these won't signal at the network layer with POLLIN
* and if we don't realize, this data will sit there forever
*/
if (n == len && wsi->ssl && SSL_pending(wsi->ssl)) {
context->ssl_flag_buffered_reads = 1;
wsi->buffered_reads_pending = 1;
}
return n;
}
n = SSL_get_error(wsi->ssl, n);
if (n == SSL_ERROR_WANT_READ || n == SSL_ERROR_WANT_WRITE)
return LWS_SSL_CAPABLE_MORE_SERVICE;
return LWS_SSL_CAPABLE_ERROR;
}
示例6: if
int ssl::read(std::vector<unsigned char>& buf) {
int bytes_read;
if((bytes_read = SSL_read(_ssl.get(), buf.data(), (int)buf.size())) < 0) {
return -1;
}
else if(!bytes_read) {
_eof = true;
}
// Make sure all bytes are read
int pending = SSL_pending(_ssl.get());
// Update number of bytes in buf
buf.resize(bytes_read + pending);
if(pending) {
if((bytes_read = SSL_read(_ssl.get(), &buf.data()[bytes_read], (int)buf.size() - bytes_read)) < 0) {
return -1;
}
else if(!bytes_read) {
_eof = true;
}
}
return 0;
}
示例7: hr_ssl_read
ssize_t hr_ssl_read(struct corerouter_peer *main_peer) {
struct corerouter_session *cs = main_peer->session;
struct http_session *hr = (struct http_session *) cs;
hr_ssl_clear_errors();
// try to always leave 4k available
if (uwsgi_buffer_ensure(main_peer->in, uwsgi.page_size)) return -1;
int ret = SSL_read(hr->ssl, main_peer->in->buf + main_peer->in->pos, main_peer->in->len - main_peer->in->pos);
if (ret > 0) {
// fix the buffer
main_peer->in->pos += ret;
// check for pending data
int ret2 = SSL_pending(hr->ssl);
if (ret2 > 0) {
if (uwsgi_buffer_fix(main_peer->in, main_peer->in->len + ret2 )) {
uwsgi_cr_log(main_peer, "cannot fix the buffer to %d\n", main_peer->in->len + ret2);
return -1;
}
if (SSL_read(hr->ssl, main_peer->in->buf + main_peer->in->pos, ret2) != ret2) {
uwsgi_cr_log(main_peer, "SSL_read() on %d bytes of pending data failed\n", ret2);
return -1;
}
// fix the buffer
main_peer->in->pos += ret2;
}
#ifdef UWSGI_SPDY
if (hr->spdy) {
//uwsgi_log("RUNNING THE SPDY PARSER FOR %d bytes\n", main_peer->in->pos);
return spdy_parse(main_peer);
}
#endif
return http_parse(main_peer);
}
int err = SSL_get_error(hr->ssl, ret);
if (err == SSL_ERROR_ZERO_RETURN || err == 0) return 0;
if (err == SSL_ERROR_WANT_READ) {
cr_reset_hooks_and_read(main_peer, hr_ssl_read);
return 1;
}
else if (err == SSL_ERROR_WANT_WRITE) {
cr_write_to_main(main_peer, hr_ssl_read);
return 1;
}
else if (err == SSL_ERROR_SYSCALL) {
if (errno != 0)
uwsgi_cr_error(main_peer, "hr_ssl_read()");
}
else if (err == SSL_ERROR_SSL && uwsgi.ssl_verbose) {
ERR_print_errors_fp(stderr);
}
return -1;
}
示例8: decode_ssl_input
int decode_ssl_input(h2o_socket_t *sock)
{
assert(sock->ssl != NULL);
assert(sock->ssl->handshake.cb == NULL);
while (sock->ssl->input.encrypted->size != 0 || SSL_pending(sock->ssl->ssl)) {
int rlen;
h2o_iovec_t buf = h2o_buffer_reserve(&sock->input, 4096);
if (buf.base == NULL)
return errno;
{ /* call SSL_read (while detecting SSL renegotiation and reporting it as error) */
int did_write_in_read = 0;
sock->ssl->did_write_in_read = &did_write_in_read;
rlen = SSL_read(sock->ssl->ssl, buf.base, (int)buf.len);
sock->ssl->did_write_in_read = NULL;
if (did_write_in_read)
return EIO;
}
if (rlen == -1) {
if (SSL_get_error(sock->ssl->ssl, rlen) != SSL_ERROR_WANT_READ) {
return EIO;
}
break;
} else if (rlen == 0) {
break;
} else {
sock->input->size += rlen;
}
}
return 0;
}
示例9: http_ssl_read
static ssize_t
http_ssl_read(void *cookie, char *buf, size_t len)
{
int nr, err;
http_ssl_cookie_t *hsc = (http_ssl_cookie_t *)cookie;
size_t total = 0;
do {
nr = SSL_read(hsc->ssl, buf + total, len - total);
if (nr > 0) {
total += (size_t)nr;
} else {
err = SSL_get_error(hsc->ssl, nr);
switch (err) {
case SSL_ERROR_ZERO_RETURN:
goto read_out;
break;
case SSL_ERROR_WANT_WRITE:
case SSL_ERROR_WANT_READ:
break;
default:
if (debug_mode)
ERR_print_errors_fp(stderr);
if (total == 0)
total = (ssize_t)-1;
goto read_out;
}
}
} while ((total < len) && SSL_pending(hsc->ssl));
read_out:
return (ssize_t)total;
}
示例10: waitForData
bool SSLSocket::waitForData() {
if (m_data->m_ssl_active && SSL_pending(m_data->m_handle)) {
return true;
}
return Socket::waitForData();
}
示例11: ssl_read_socket
static ssize_t
ssl_read_socket(SSL* ssl, char *buf, size_t len)
{
int nr, err;
size_t total = 0;
do {
nr = SSL_read(ssl, buf + total, len - total);
if (nr > 0) {
total += (size_t)nr;
} else {
err = SSL_get_error(ssl, nr);
switch (err) {
case SSL_ERROR_ZERO_RETURN:
goto read_out;
break;
case SSL_ERROR_WANT_WRITE:
case SSL_ERROR_WANT_READ:
break;
case SSL_ERROR_SYSCALL:
if (ERR_get_error() == 0)
goto read_out;
default:
if (total == 0)
total = (ssize_t)-1;
logit(LOG_ERR, "SSL_read %s! (err: %d)", "FAILED", err);
goto read_out;
}
}
} while ((total < len) && SSL_pending(ssl));
read_out:
return (ssize_t)total;
}
示例12: roadmap_ssl_read
int roadmap_ssl_read (void *context, void *buffer, int buffer_size)
{
int read;
RoadMapSslIO ssl_io_ctx = (RoadMapSslIO) context;
int received = 0;
int err;
do
{
read = SSL_read( ssl_io_ctx->ssl, buffer, buffer_size );
buffer_size -= read;
buffer += read;
if ( ( err = SSL_get_error( ssl_io_ctx->ssl, read ) ) == SSL_ERROR_NONE )
{
received += read;
}
else
{
roadmap_log ( ROADMAP_ERROR, "Error (%d) in SSL_read: %s !!", err, ERR_error_string( err, NULL ) );
received = 0;
break;
}
} while ( SSL_pending( ssl_io_ctx->ssl ) && ( buffer_size > 0 ) );
return received;
}
示例13: Curl_cyassl_data_pending
bool Curl_cyassl_data_pending(const struct connectdata* conn, int connindex)
{
if(conn->ssl[connindex].handle) /* SSL is in use */
return (0 != SSL_pending(conn->ssl[connindex].handle)) ? TRUE : FALSE;
else
return FALSE;
}
示例14: mssl_read
static ssize_t mssl_read(void *cookie, char *buf, size_t len)
{
_dprintf("%s()\n", __FUNCTION__);
mssl_cookie_t *kuki = cookie;
int total = 0;
int n, err;
do {
n = SSL_read(kuki->ssl, &(buf[total]), len - total);
_dprintf("SSL_read(max=%d) returned %d\n", len - total, n);
err = SSL_get_error(kuki->ssl, n);
switch (err) {
case SSL_ERROR_NONE:
total += n;
break;
case SSL_ERROR_ZERO_RETURN:
total += n;
goto OUT;
case SSL_ERROR_WANT_WRITE:
case SSL_ERROR_WANT_READ:
break;
default:
_dprintf("%s(): SSL error %d\n", __FUNCTION__, err);
mssl_print_err(kuki->ssl);
if (total == 0) total = -1;
goto OUT;
}
} while ((len - total > 0) && SSL_pending(kuki->ssl));
OUT:
_dprintf("%s() returns %d\n", __FUNCTION__, total);
return total;
}
示例15: read
int SSLSocket::read(void *buffer, unsigned long size) {
ssl_internal_stack *stack;
stack = (ssl_internal_stack *)idata;
if(SSL_pending(stack->ssl) == 0) {
((char *)buffer)[0] = 0;
return 0;
}
int ret;
if((ret = SSL_read(stack->ssl, buffer, size)) <= 0) {
switch(SSL_get_error(stack->ssl, ret)) {
case SSL_ERROR_ZERO_RETURN:
throw SSLConnectionClosed();
break;
case SSL_ERROR_WANT_WRITE:
case SSL_ERROR_WANT_READ:
throw SSLConnectionIsBusy();
break;
case SSL_ERROR_WANT_CONNECT:
case SSL_ERROR_WANT_ACCEPT:
throw NotConnected();
break;
case SSL_ERROR_WANT_X509_LOOKUP:
throw CertificateLookupPending();
break;
case SSL_ERROR_SYSCALL:
case SSL_ERROR_SSL:
throw SSLGeneric();
break;
}
}
return ret;
}