當前位置: 首頁>>代碼示例>>C++>>正文


C++ BIO_should_retry函數代碼示例

本文整理匯總了C++中BIO_should_retry函數的典型用法代碼示例。如果您正苦於以下問題:C++ BIO_should_retry函數的具體用法?C++ BIO_should_retry怎麽用?C++ BIO_should_retry使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了BIO_should_retry函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: BIO_clear_retry_flags

int	MaOpenSslSocket::write(char *buf, int len)
{
	int		rc, written, totalWritten;

	if (bio == 0 || ssl == 0 || len <= 0) {
		return -1;
	}

	BIO_clear_retry_flags(bio);

	totalWritten = 0;

	do {
		written = BIO_write(bio, buf, len);

		mprLog(7, "written %d, len %d\n", written, len);

		if (written >= 0) {
			do {
				rc = BIO_flush(bio);
				mprLog(7, "BIO_flush rc %d\n", rc);
				if (rc > 0) {
					//	Success
					break;
				}
				//
				//	Nap to prevent busy waiting.
				//
				mprSleep(10);
			} while (rc <= 0 && BIO_should_retry(bio));

			totalWritten += written;
			buf += written;
			len -= written;
		}

		mprLog(7, "write: len %d, written %d, total %d, should_retry %d\n",
			len, written, totalWritten, BIO_should_retry(bio));

		/*
 		 *	If written is < 0 and an error occurred, then BIO_should_retry
 		 *	will return false.
		 */
	} while (len > 0 && (written > 0 || BIO_should_retry(bio)));

	if (totalWritten <= 0 && BIO_should_retry(bio) == 0) {
		mprLog(7, "connection closed\n");
		/* 
		 *	If totalWritten is not Zero, then we don't return an Error.
		 * 	Next time this function is called, it will return an Error.
		 */
		return -1; // return Error ( connection closed )
	}
	return totalWritten;
}
開發者ID:embedthis,項目名稱:appweb-2,代碼行數:55,代碼來源:openSslModule.cpp

示例2: BIO_read

int	MaOpenSslSocket::read(char *buf, int len)
{
	int		rc;

	if (bio == 0 || ssl == 0) {
		return -1;
	}

	rc = BIO_read(bio, buf, len);

#if DEBUG
	if (rc > 0 && !connTraced) {
		X509_NAME	*xSubject;
		X509		*cert;
		char		subject[260], issuer[260], peer[260];

		mprLog(4, "%d: SSL Connected using: \"%s\"\n", 
			sock, SSL_get_cipher(ssl));

		cert = SSL_get_peer_certificate(ssl);
		if (cert == 0) {
			mprLog(4, "%d: SSL Details: client supplied no certificate\n", 
				sock);
		} else {
			xSubject = X509_get_subject_name(cert);
			X509_NAME_oneline(xSubject, subject, sizeof(subject) -1);
			X509_NAME_oneline(X509_get_issuer_name(cert), issuer, 
				sizeof(issuer) -1);
			X509_NAME_get_text_by_NID(xSubject, NID_commonName, peer, 
				sizeof(peer) - 1);
			mprLog(4, "%d: SSL Subject %s\n", sock, subject);
			mprLog(4, "%d: SSL Issuer: %s\n", sock, issuer);
			mprLog(4, "%d: SSL Peer: %s\n", sock, peer);
			X509_free(cert);
		}
		connTraced = 1;
	}
#endif

	if (rc > 0) {
		return rc;

	} else if (rc == 0) {
		if (BIO_should_retry(bio)) {
			return 0;
		}
		flags |= MPR_SOCKET_EOF;
		return 0;
	}
	if (BIO_should_retry(bio)) {
		return 0;
	}
	return rc;
}
開發者ID:embedthis,項目名稱:appweb-2,代碼行數:54,代碼來源:openSslModule.cpp

示例3: ok_write

static int ok_write(BIO *b, const char *in, int inl)
{
    int ret = 0, n, i;
    BIO_OK_CTX *ctx;

    if (inl <= 0)
        return inl;

    ctx = (BIO_OK_CTX *)b->ptr;
    ret = inl;

    if ((ctx == NULL) || (b->next_bio == NULL) || (b->init == 0))
        return (0);

    if (ctx->sigio)
        sig_out(b);

    do {
        BIO_clear_retry_flags(b);
        n = ctx->buf_len - ctx->buf_off;
        while (ctx->blockout && n > 0) {
            i = BIO_write(b->next_bio, &(ctx->buf[ctx->buf_off]), n);
            if (i <= 0) {
                BIO_copy_next_retry(b);
                if (!BIO_should_retry(b))
                    ctx->cont = 0;
                return (i);
            }
            ctx->buf_off += i;
            n -= i;
        }

        /* at this point all pending data has been written */
        ctx->blockout = 0;
        if (ctx->buf_len == ctx->buf_off) {
            ctx->buf_len = OK_BLOCK_BLOCK;
            ctx->buf_off = 0;
        }

        if ((in == NULL) || (inl <= 0))
            return (0);

        n = (inl + ctx->buf_len > OK_BLOCK_SIZE + OK_BLOCK_BLOCK) ?
            (int)(OK_BLOCK_SIZE + OK_BLOCK_BLOCK - ctx->buf_len) : inl;

        memcpy((unsigned char *)(&(ctx->buf[ctx->buf_len])),
               (unsigned char *)in, n);
        ctx->buf_len += n;
        inl -= n;
        in += n;

        if (ctx->buf_len >= OK_BLOCK_SIZE + OK_BLOCK_BLOCK) {
            block_out(b);
        }
    } while (inl > 0);

    BIO_clear_retry_flags(b);
    BIO_copy_next_retry(b);
    return (ret);
}
開發者ID:GrayKing,項目名稱:Leakfix-on-OpenSSL,代碼行數:60,代碼來源:bio_ok.c

示例4: BIO_new

unsigned char *Client::encode64(std::string data, int *lenoutput){
	const char *c_data = data.c_str();
	unsigned char *u_data = (unsigned char *) c_data;

	int len = data.size();
	
	BIO *b64, *bmem;
	b64 = BIO_new(BIO_f_base64());
	BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
	bmem = BIO_new(BIO_s_mem());
	BIO_push(b64, bmem);

	bool done = false;
	int res = 0;

	while(!done){
		res = BIO_write(b64, u_data, len);
		if(res <= 0){
			if(BIO_should_retry(b64))
				continue;
			else
				return NULL;
		}
		else
			done = true;
	}
	
	BIO_flush(b64);
	
	unsigned char *output;
	*lenoutput = BIO_get_mem_data(bmem, &output);
	
	return output;	
		
}
開發者ID:martinkntk,項目名稱:smtp_client,代碼行數:35,代碼來源:client.cpp

示例5: OCSP_sendreq_new

OCSP_RESPONSE *OCSP_sendreq_bio (BIO * b, char *path, OCSP_REQUEST * req)
{
    OCSP_RESPONSE *resp = NULL;

    OCSP_REQ_CTX *ctx;

    int rv;

    ctx = OCSP_sendreq_new (b, path, req, -1);

    if (!ctx)
        return NULL;

    do
    {
        rv = OCSP_sendreq_nbio (&resp, ctx);
    }
    while ((rv == -1) && BIO_should_retry (b));

    OCSP_REQ_CTX_free (ctx);

    if (rv)
        return resp;

    return NULL;
}
開發者ID:274914765,項目名稱:C,代碼行數:26,代碼來源:ocsp_ht.c

示例6: tls_write_all

int tls_write_all(rdpTls* tls, const BYTE* data, int length)
{
	int status;
	int offset = 0;
	BIO* bio = tls->bio;

	while (offset < length)
	{
		status = BIO_write(bio, &data[offset], length - offset);

		if (status > 0)
		{
			offset += status;
		}
		else
		{
			if (!BIO_should_retry(bio))
				return -1;

			if (BIO_write_blocked(bio))
				status = BIO_wait_write(bio, 100);
			else if (BIO_read_blocked(bio))
				status = BIO_wait_read(bio, 100);
			else
				USleep(100);

			if (status < 0)
				return -1;
		}
	}

	return length;
}
開發者ID:dcatonR1,項目名稱:FreeRDP,代碼行數:33,代碼來源:tls.c

示例7: 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;
}
開發者ID:pubnub,項目名稱:c-core,代碼行數:33,代碼來源:pbpal_resolv_and_connect_openssl.c

示例8: LUA_FUNCTION

static LUA_FUNCTION(openssl_bio_puts)
{
  BIO* bio = CHECK_OBJECT(1, BIO, "openssl.bio");
  const char* s = luaL_checkstring(L, 2);
  int ret = 1;
  int len = BIO_puts(bio, s);

  if (len > 0)
  {
    lua_pushinteger(L, len);
    ret = 1;
  }
  else if (BIO_should_retry(bio))
  {
    lua_pushinteger(L, 0);
    ret = 1;
  }
  else
  {
    lua_pushnil(L);
    lua_pushinteger(L, len);
    ret = 2;
  };
  return ret;
}
開發者ID:Shaddy1884,項目名稱:lua-openssl,代碼行數:25,代碼來源:bio.c

示例9: transport_bio_buffered_read

static int transport_bio_buffered_read(BIO* bio, char* buf, int size)
{
	int status;
	rdpTcp* tcp = (rdpTcp*) bio->ptr;

	tcp->readBlocked = FALSE;
	BIO_clear_flags(bio, BIO_FLAGS_READ);

	status = BIO_read(bio->next_bio, buf, size);

	if (status <= 0)
	{
		if (!BIO_should_retry(bio->next_bio))
		{
			BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
			status = -1;
			goto out;
		}

		BIO_set_flags(bio, BIO_FLAGS_SHOULD_RETRY);

		if (BIO_should_read(bio->next_bio))
		{
			BIO_set_flags(bio, BIO_FLAGS_READ);
			tcp->readBlocked = TRUE;
			goto out;
		}
	}

out:
	return status;
}
開發者ID:Auto-Droid,項目名稱:FreeRDP,代碼行數:32,代碼來源:tcp.c

示例10: write_to_BIO

int write_to_BIO( BIO *bio, char *out, int len ) 
{
    int total, written;
    int errcode;

    /* This loop writes the data to the file. It checks for errors as if the
     underlying file were non-blocking */
    for (total = 0; total < len; total += written) {
        if ((written = BIO_write (bio, out + total, len - total)) <= 0) {
            if (BIO_should_retry (bio)) {
                written = 0;
            }
            else {
                /* return the error */
                errcode = ERR_get_error();
                /* FIXME - do something with errcode? */
                return written;
            }
        }
    }

    /* Ensure all of our data is pushed all the way out to the destination */
    BIO_flush( bio );

    return total;
}
開發者ID:linuxlizard,項目名稱:snmptree,代碼行數:26,代碼來源:AgentList.cpp

示例11: __bro_openssl_read

int       
__bro_openssl_read(BroConn *bc, uchar *buf, uint buf_size)
{
  int n;

  D_ENTER;
  
  /* It's important here to use <= for comparison, since, as the
   * invaluable O'Reilly OpenSSL book reports, "for each of the four
   * reading and writing functions, a 0 or -1 return value may or may
   * not necessarily indicate that an error has occurred." This may or
   * may not necessarily be indicative of the incredible PITA that
   * OpenSSL is. --cpk
   */
  if ( (n = BIO_read(bc->bio, buf, buf_size)) <= 0)
    {
      if (BIO_should_retry(bc->bio))
	D_RETURN_(0);
      
      __bro_openssl_shutdown(bc);
      D(("Connection closed, BIO_read() returned %i.\n", n));      
      print_errors();
      D_RETURN_(-1);
    }
    
  D_RETURN_(n);
}
開發者ID:aming2007,項目名稱:dpi-test-suite,代碼行數:27,代碼來源:bro_openssl.c

示例12: bio_bucket_write

/* Returns the amount written. */
static int bio_bucket_write(BIO *bio, const char *in, int inl)
{
    serf_ssl_context_t *ctx = bio->ptr;
    serf_bucket_t *tmp;

#ifdef SSL_VERBOSE
    printf("bio_bucket_write called for %d bytes\n", inl);
#endif
    if (ctx->encrypt.status == SERF_ERROR_WAIT_CONN
        && !BIO_should_read(ctx->bio)) {
#ifdef SSL_VERBOSE
        printf("bio_bucket_write waiting: (%d %d %d)\n",
           BIO_should_retry(ctx->bio), BIO_should_read(ctx->bio),
           BIO_get_retry_flags(ctx->bio));
#endif
        /* Falling back... */
        ctx->encrypt.exhausted_reset = 1;
        BIO_clear_retry_flags(bio);
    }

    tmp = serf_bucket_simple_copy_create(in, inl,
                                         ctx->encrypt.pending->allocator);

    serf_bucket_aggregate_append(ctx->encrypt.pending, tmp);

    return inl;
}
開發者ID:coapp-deprecated,項目名稱:serf_old,代碼行數:28,代碼來源:ssl_buckets.c

示例13: recv_ssl_socket

/**
 * Receive data package though the ssl connection
 * @param ssl ssl connection
 * @param buffer array to hold the data
 * @param len size of the data container
 * @param timeout Seconds to wait for data to be available
 * @return number of bytes transmitted, -1 in case of an error
 */
int recv_ssl_socket(ssl_connection *ssl, void *buffer, int len, int timeout) {

#ifdef HAVE_OPENSSL
    int n= 0;

    ASSERT(ssl);

    do {
        n= SSL_read(ssl->handler, buffer, len);
    } while(n <= 0 &&
            BIO_should_retry(ssl->socket_bio) &&
            can_read(ssl->socket, timeout));

    if(n <= 0) {
        return -1;
    }

    return n;

#else

    return -1;

#endif

}
開發者ID:jiejiuzhang1579,項目名稱:nicad,代碼行數:34,代碼來源:ssl.c

示例14: read_from_stream

/**
 * Read a from a stream and handle restarts if nessecary
 */
ssize_t read_from_stream(BIO* bio, char* buffer, ssize_t length) {

    ssize_t r = -1;

    while (r < 0) {

        r = BIO_read(bio, buffer, length);
        if (r == 0) {

            print_ssl_error("Reached the end of the data stream.\n", stdout);
            continue;

        } else if (r < 0) {

            if (!BIO_should_retry(bio)) {

                print_ssl_error("BIO_read should retry test failed.\n", stdout);
                continue;
            }

            /* It would be prudent to check the reason for the retry and handle
             * it appropriately here */
        }

    };

    return r;
}
開發者ID:eltommo,項目名稱:licenceliber,代碼行數:31,代碼來源:example_client.c

示例15: transport_bio_buffered_read

static int transport_bio_buffered_read(BIO* bio, char* buf, int size)
{
	int status;
	WINPR_BIO_BUFFERED_SOCKET* ptr = (WINPR_BIO_BUFFERED_SOCKET*) BIO_get_data(bio);
	BIO* next_bio = BIO_next(bio);

	ptr->readBlocked = FALSE;
	BIO_clear_flags(bio, BIO_FLAGS_READ);

	status = BIO_read(next_bio, buf, size);

	if (status <= 0)
	{
		if (!BIO_should_retry(next_bio))
		{
			BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
			goto out;
		}

		BIO_set_flags(bio, BIO_FLAGS_SHOULD_RETRY);

		if (BIO_should_read(next_bio))
		{
			BIO_set_flags(bio, BIO_FLAGS_READ);
			ptr->readBlocked = TRUE;
			goto out;
		}
	}

out:
	return status;
}
開發者ID:kdienes,項目名稱:FreeRDP,代碼行數:32,代碼來源:tcp.c


注:本文中的BIO_should_retry函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。