本文整理匯總了C++中BIO_set_nbio函數的典型用法代碼示例。如果您正苦於以下問題:C++ BIO_set_nbio函數的具體用法?C++ BIO_set_nbio怎麽用?C++ BIO_set_nbio使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了BIO_set_nbio函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: gw_malloc
/*
* XXX bad assumption here that conn_wrap_fd for SSL can only happens
* for the server side!!!! FIXME !!!!
*/
Connection *conn_wrap_fd(int fd, int ssl)
{
Connection *conn;
if (socket_set_blocking(fd, 0) < 0)
return NULL;
conn = gw_malloc(sizeof(*conn));
conn->inlock = mutex_create();
conn->outlock = mutex_create();
conn->claimed = 0;
conn->outbuf = octstr_create("");
conn->outbufpos = 0;
conn->inbuf = octstr_create("");
conn->inbufpos = 0;
conn->fd = fd;
conn->connected = yes;
conn->read_eof = 0;
conn->io_error = 0;
conn->output_buffering = DEFAULT_OUTPUT_BUFFERING;
conn->registered = NULL;
conn->callback = NULL;
conn->callback_data = NULL;
conn->callback_data_destroyer = NULL;
conn->listening_pollin = 0;
conn->listening_pollout = 0;
#ifdef HAVE_LIBSSL
/*
* do all the SSL magic for this connection
*/
if (ssl) {
conn->ssl = SSL_new(global_server_ssl_context);
conn->peer_certificate = NULL;
/* SSL_set_fd can fail, so check it */
if (SSL_set_fd(conn->ssl, conn->fd) == 0) {
/* SSL_set_fd failed, log error and return NULL */
error(errno, "SSL: OpenSSL: %.256s", ERR_error_string(ERR_get_error(), NULL));
conn_destroy(conn);
return NULL;
}
/* SSL_set_verify(conn->ssl, 0, NULL); */
/* set read/write BIO layer to non-blocking mode */
BIO_set_nbio(SSL_get_rbio(conn->ssl), 1);
BIO_set_nbio(SSL_get_wbio(conn->ssl), 1);
/* set accept state , SSL-Handshake will be handled transparent while SSL_[read|write] */
SSL_set_accept_state(conn->ssl);
} else {
conn->ssl = NULL;
conn->peer_certificate = NULL;
}
#endif /* HAVE_LIBSSL */
return conn;
}
示例2: zc_socket_ssl_handshake
int
zc_socket_ssl_handshake(zcSocket *s)
{
int ret;
int err;
int sockstate, nonblocking;
/* just in case the blocking state of the socket has been changed */
nonblocking = !s->blocked; //(self->Socket->sock_timeout >= 0.0);
BIO_set_nbio(SSL_get_rbio(s->ssl), nonblocking);
BIO_set_nbio(SSL_get_wbio(s->ssl), nonblocking);
/* Actually negotiate SSL connection */
/* XXX If SSL_do_handshake() returns 0, it's also a failure. */
sockstate = 0;
do {
ret = SSL_do_handshake(s->ssl);
err = SSL_get_error(s->ssl, ret);
if (err == SSL_ERROR_WANT_READ) {
sockstate = zc_socket_select(s, 0); //check_socket_and_wait_for_timeout(s->fd, 0);
} else if (err == SSL_ERROR_WANT_WRITE) {
sockstate = zc_socket_select(s, 1); //check_socket_and_wait_for_timeout(s->fd, 1);
} else {
sockstate = ZC_SSL_SOCKET_OPERATION_OK;
}
if (sockstate == ZC_SSL_SOCKET_HAS_TIMED_OUT) {
//PyErr_SetString(PySSLErrorObject, ERRSTR("The handshake operation timed out"));
ZCWARN("The handshake operation timed out");
return ZC_ERR;
} else if (sockstate == ZC_SSL_SOCKET_HAS_BEEN_CLOSED) {
//PyErr_SetString(PySSLErrorObject, ERRSTR("Underlying socket has been closed."));
ZCWARN("Underlying socket has been closed.");
return ZC_ERR;
} else if (sockstate == ZC_SSL_SOCKET_TOO_LARGE_FOR_SELECT) {
//PyErr_SetString(PySSLErrorObject, ERRSTR("Underlying socket too large for select()."));
ZCWARN("Underlying socket too large for select().");
return ZC_ERR;
} else if (sockstate == ZC_SSL_SOCKET_IS_NONBLOCKING) {
break;
}
} while (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE);
if (ret < 1) {
ZCWARN("handshak error:%d", ret);
return ZC_ERR;
}
//return PySSL_SetError(self, ret, __FILE__, __LINE__);
if (s->peer_cert)
X509_free (s->peer_cert);
if ((s->peer_cert = SSL_get_peer_certificate(s->ssl))) {
X509_NAME_oneline(X509_get_subject_name(s->peer_cert), s->server, X509_NAME_MAXLEN);
X509_NAME_oneline(X509_get_issuer_name(s->peer_cert), s->issuer, X509_NAME_MAXLEN);
}
return ZC_OK;
}
示例3: zc_socket_ssl_send
int
zc_socket_ssl_send(zcSocket *s, char *buf, int blen)
{
//char *data;
int len;
//int count;
int sockstate;
int err;
int nonblocking;
/* just in case the blocking state of the socket has been changed */
nonblocking = !s->blocked; //(self->Socket->sock_timeout >= 0.0);
BIO_set_nbio(SSL_get_rbio(s->ssl), nonblocking);
BIO_set_nbio(SSL_get_wbio(s->ssl), nonblocking);
//sockstate = check_socket_and_wait_for_timeout(self->Socket, 1);
sockstate = zc_socket_select(s, 1);
if (sockstate == ZC_SSL_SOCKET_HAS_TIMED_OUT) {
ZCWARN("The write operation timed out");
return ZC_ERR;
} else if (sockstate == ZC_SSL_SOCKET_HAS_BEEN_CLOSED) {
ZCWARN("Underlying socket has been closed.");
return ZC_ERR;
} else if (sockstate == ZC_SSL_SOCKET_TOO_LARGE_FOR_SELECT) {
ZCWARN("Underlying socket too large for select().");
return ZC_ERR;
}
do {
err = 0;
len = SSL_write(s->ssl, buf, blen);
err = SSL_get_error(s->ssl, len);
if (err == SSL_ERROR_WANT_READ) {
sockstate = zc_socket_select(s, 0);
} else if (err == SSL_ERROR_WANT_WRITE) {
sockstate = zc_socket_select(s, 1);
} else {
sockstate = ZC_SSL_SOCKET_OPERATION_OK;
}
if (sockstate == ZC_SSL_SOCKET_HAS_TIMED_OUT) {
ZCWARN("The write operation timed out");
return ZC_ERR;
} else if (sockstate == ZC_SSL_SOCKET_HAS_BEEN_CLOSED) {
ZCWARN("Underlying socket has been closed.");
return ZC_ERR;
} else if (sockstate == ZC_SSL_SOCKET_IS_NONBLOCKING) {
break;
}
} while (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE);
if (len > 0)
//return PyInt_FromLong(len);
return len;
else
//return PySSL_SetError(self, len, __FILE__, __LINE__);
return len;
}
示例4: lws_tls_server_new_nonblocking
int
lws_tls_server_new_nonblocking(struct lws *wsi, lws_sockfd_type accept_fd)
{
#if !defined(USE_WOLFSSL)
BIO *bio;
#endif
errno = 0;
wsi->tls.ssl = SSL_new(wsi->vhost->tls.ssl_ctx);
if (wsi->tls.ssl == NULL) {
lwsl_err("SSL_new failed: %d (errno %d)\n",
lws_ssl_get_error(wsi, 0), errno);
lws_tls_err_describe();
return 1;
}
SSL_set_ex_data(wsi->tls.ssl, openssl_websocket_private_data_index, wsi);
SSL_set_fd(wsi->tls.ssl, (int)(long long)accept_fd);
#ifdef USE_WOLFSSL
#ifdef USE_OLD_CYASSL
CyaSSL_set_using_nonblock(wsi->tls.ssl, 1);
#else
wolfSSL_set_using_nonblock(wsi->tls.ssl, 1);
#endif
#else
SSL_set_mode(wsi->tls.ssl, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER |
SSL_MODE_RELEASE_BUFFERS);
bio = SSL_get_rbio(wsi->tls.ssl);
if (bio)
BIO_set_nbio(bio, 1); /* nonblocking */
else
lwsl_notice("NULL rbio\n");
bio = SSL_get_wbio(wsi->tls.ssl);
if (bio)
BIO_set_nbio(bio, 1); /* nonblocking */
else
lwsl_notice("NULL rbio\n");
#endif
#if defined (LWS_HAVE_SSL_SET_INFO_CALLBACK)
if (wsi->vhost->tls.ssl_info_event_mask)
SSL_set_info_callback(wsi->tls.ssl, lws_ssl_info_callback);
#endif
return 0;
}
示例5: set_nonblocking
void set_nonblocking(BIO *bio)
{
if(BIO_method_type(bio) == BIO_TYPE_CONNECT)
{
BIO_set_nbio(bio, 1);
}
if(BIO_method_type(bio) == BIO_TYPE_ACCEPT)
{
BIO_set_nbio_accept(bio, 1);
}
#ifdef DTLS_IMPLEMENTED
if(BIO_method_type(bio) == BIO_TYPE_DGRAM)
{
int fd = BIO_get_fd(bio, NULL);
#ifdef WIN32
unsigned long nonzero = 1;
SocketResetErrorStatus();
ioctlsocket(fd, FIONBIO, &nonzero);
#else
fcntl(fd, F_SETFL, FASYNC | O_NONBLOCK);
#endif
}
#endif
}
示例6: LUA_FUNCTION
static LUA_FUNCTION(openssl_bio_nbio)
{
BIO* bio = CHECK_OBJECT(1, BIO, "openssl.bio");
int nbio = lua_toboolean(L, 2);
int ret = BIO_set_nbio(bio, nbio);
return openssl_pushresult(L, ret);
}
示例7: engine_alloc
ms_conn* engine_alloc(VALUE klass, VALUE* obj) {
ms_conn* conn;
*obj = Data_Make_Struct(klass, ms_conn, 0, engine_free, conn);
conn->read = BIO_new(BIO_s_mem());
BIO_set_nbio(conn->read, 1);
conn->write = BIO_new(BIO_s_mem());
BIO_set_nbio(conn->write, 1);
conn->ssl = 0;
conn->ctx = 0;
return conn;
}
示例8: resolv_and_connect_wout_SSL
static enum pbpal_resolv_n_connect_result resolv_and_connect_wout_SSL(pubnub_t *pb)
{
PUBNUB_LOG_TRACE("resolv_and_connect_wout_SSL\n");
if (NULL == pb->pal.socket) {
char const*origin = PUBNUB_ORIGIN_SETTABLE ? pb->origin : PUBNUB_ORIGIN;
PUBNUB_LOG_TRACE("pb=%p: Don't have BIO\n", pb);
pb->pal.socket = BIO_new_connect((char*)origin);
}
if (NULL == pb->pal.socket) {
return pbpal_resolv_resource_failure;
}
BIO_set_conn_port(pb->pal.socket, "http");
BIO_set_nbio(pb->pal.socket, !pb->options.use_blocking_io);
WATCH_ENUM(pb->options.use_blocking_io);
if (BIO_do_connect(pb->pal.socket) <= 0) {
if (BIO_should_retry(pb->pal.socket)) {
return pbpal_connect_wouldblock;
}
ERR_print_errors_cb(print_to_pubnub_log, NULL);
PUBNUB_LOG_ERROR("BIO_do_connect failed\n");
return pbpal_connect_failed;
}
PUBNUB_LOG_TRACE("pb=%p: BIO connected\n", pb);
{
int fd = BIO_get_fd(pb->pal.socket, NULL);
socket_set_rcv_timeout(fd, pb->transaction_timeout_ms);
}
return pbpal_connect_success;
}
示例9: handshake
static int
handshake (struct stream_data *data)
{
int ret;
int finished;
SSL_library_init();
SSL_load_error_strings();
data->ssl_ctx = SSL_CTX_new(TLSv1_method());
if(!data->ssl_ctx) return IKS_NOMEM;
data->ssl = SSL_new(data->ssl_ctx);
if(!data->ssl) return IKS_NOMEM;
if( SSL_set_fd(data->ssl, (int)(intptr_t)data->sock) != 1 ) return IKS_NOMEM;
/* Set both the read and write BIO's to non-blocking mode */
BIO_set_nbio(SSL_get_rbio(data->ssl), 1);
BIO_set_nbio(SSL_get_wbio(data->ssl), 1);
finished = 0;
do
{
ret = SSL_connect(data->ssl);
if( ret != 1 )
{
if( wait_for_data(data, ret, 1) != IKS_OK )
{
finished = 1;
SSL_free(data->ssl);
}
}
} while( ret != 1 && finished != 1 );
if( ret == 1 )
{
data->flags &= (~SF_TRY_SECURE);
data->flags |= SF_SECURE;
iks_send_header (data->prs, data->server);
}
return ret == 1 ? IKS_OK : IKS_NET_TLSFAIL;
}
示例10: conn_init_client_ssl
static int conn_init_client_ssl(Connection *ret, Octstr *certkeyfile)
{
ret->ssl = SSL_new(global_ssl_context);
/*
* The current thread's error queue must be empty before
* the TLS/SSL I/O operation is attempted, or SSL_get_error()
* will not work reliably.
*/
ERR_clear_error();
if (certkeyfile != NULL) {
SSL_use_certificate_file(ret->ssl, octstr_get_cstr(certkeyfile),
SSL_FILETYPE_PEM);
SSL_use_PrivateKey_file(ret->ssl, octstr_get_cstr(certkeyfile),
SSL_FILETYPE_PEM);
if (SSL_check_private_key(ret->ssl) != 1) {
error(0, "conn_open_ssl: private key isn't consistent with the "
"certificate from file %s (or failed reading the file)",
octstr_get_cstr(certkeyfile));
return -1;
}
}
/* SSL_set_fd can fail, so check it */
if (SSL_set_fd(ret->ssl, ret->fd) == 0) {
/* SSL_set_fd failed, log error */
error(errno, "SSL: OpenSSL: %.256s", ERR_error_string(ERR_get_error(), NULL));
return -1;
}
/*
* make sure the socket is non-blocking while we do SSL_connect
*/
if (socket_set_blocking(ret->fd, 0) < 0) {
return -1;
}
BIO_set_nbio(SSL_get_rbio(ret->ssl), 1);
BIO_set_nbio(SSL_get_wbio(ret->ssl), 1);
SSL_set_connect_state(ret->ssl);
return 0;
}
示例11: ssl_setup_socket
/** Associate an SSL object with a socket and return it.
* \param sock socket descriptor to associate with an SSL object.
* \return pointer to SSL object.
*/
SSL *
ssl_setup_socket(int sock)
{
SSL *ssl;
BIO *bio;
ssl = SSL_new(ctx);
bio = BIO_new_socket(sock, BIO_NOCLOSE);
BIO_set_nbio(bio, 1);
SSL_set_bio(ssl, bio, bio);
return ssl;
}
示例12: ssl_setup_socket
/** Associate an SSL object with a socket and return it.
* \param sock socket descriptor to associate with an SSL object.
* \return pointer to SSL object.
*/
SSL *
ssl_setup_socket(int sock)
{
SSL *ssl;
BIO *bio;
ssl = ssl_alloc_struct();
bio = BIO_new_socket(sock, BIO_NOCLOSE);
BIO_set_nbio(bio, 1);
SSL_set_bio(ssl, bio, bio);
return ssl;
}
示例13: _ios
Connection::Connection(Context& ctx, std::ios& ios, OpenMode omode)
: _ios(&ios)
, _connected(false)
, _in(0)
, _out(0)
, _ssl(0)
{
// Create the SSL objects
_in = BIO_new( BIO_s_mem() );
_out = BIO_new( BIO_s_mem() );
_ssl = SSL_new( ctx.impl()->ctx() );
// Connect the BIO
BIO_set_nbio(_in, 1);
BIO_set_nbio(_out, 1);
SSL_set_bio(_ssl, _in, _out);
if(omode == Accept)
SSL_set_accept_state(_ssl);
else
SSL_set_connect_state(_ssl);
assert(_ssl);
}
示例14: ssl_connect
int
ssl_connect(thread_t * thread)
{
SOCK *sock_obj = THREAD_ARG(thread);
int ret;
sock_obj->ssl = SSL_new(req->ctx);
sock_obj->bio = BIO_new_socket(sock_obj->fd, BIO_NOCLOSE);
BIO_set_nbio(sock_obj->bio, 1); /* Set the Non-Blocking flag */
SSL_set_bio(sock_obj->ssl, sock_obj->bio, sock_obj->bio);
ret = SSL_connect(sock_obj->ssl);
DBG(" SSL_connect return code = %d on fd:%d\n", ret, thread->u.fd);
ssl_printerr(SSL_get_error(sock_obj->ssl, ret));
return (ret > 0) ? 1 : 0;
}
示例15: set_blocking
void set_blocking(BIO *bio)
{
if(BIO_method_type(bio) == BIO_TYPE_CONNECT)
{
BIO_set_nbio(bio, 0);
}
if(BIO_method_type(bio) == BIO_TYPE_ACCEPT)
{
BIO_set_nbio_accept(bio, 0);
}
#ifdef DTLS_IMPLEMENTED
if(BIO_method_type(bio) == BIO_TYPE_DGRAM)
{
int fd, flags;
if((fd = BIO_get_fd(bio, NULL)))
{
flags = fcntl(fd, F_GETFL);
flags &= ~O_NONBLOCK;
fcntl(fd, F_SETFL, flags);
}
}
#endif
}