当前位置: 首页>>代码示例>>C++>>正文


C++ SSL_get_fd函数代码示例

本文整理汇总了C++中SSL_get_fd函数的典型用法代码示例。如果您正苦于以下问题:C++ SSL_get_fd函数的具体用法?C++ SSL_get_fd怎么用?C++ SSL_get_fd使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SSL_get_fd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ssl_handshake

/**
 *	@brief SSL servlet (contexts can be shared) 
 *  @decription THIS IS NOT MY CODE (from page 2)
 *	@param *ssl[in] 				Pointer to ssl
 */
void ssl_handshake(SSL* ssl){	
	char buf[1024];
	char reply[1024];
	int client, bytes;
	
	if(SSL_accept(ssl) < 0){
		printf("\n\nERROR: SSL_accept() failed (server.c - ssl_handshake)\n");
	} 
	else{
		bytes = SSL_read(ssl, buf, sizeof(buf));	
		if (bytes > 0){
			buf[bytes] = 0;
			printf("Client: %s\n", buf);
			long check = atol(buf) + 1;
			sprintf(reply, "%ld", check);	
			SSL_write(ssl, reply, strlen(reply));	 
		}
		else{
			printf("\n\nERROR: SSL_read() failed (server.c - ssl_handshake)\n");
			printf("A client has closed.\n\n");
		}
	}
	client = SSL_get_fd(ssl);	
	SSL_free(ssl);	
	close(client);	
}
开发者ID:penguintoku,项目名称:College,代码行数:31,代码来源:server.c

示例2: est_ssl_read

static int est_ssl_read (SSL *ssl, unsigned char *buf, int buf_max,
                       int sock_read_timeout) 
{
    int timeout;
    int read_fd;
    int rv;
    struct pollfd pfd;
    
    /*
     * load up the timeval struct to be passed to the select
     */
    timeout = sock_read_timeout * 1000;

    read_fd = SSL_get_fd(ssl);
    pfd.fd = read_fd;
    pfd.events = POLLIN;
    pfd.revents = 0;

    errno = 0;
    rv = POLL(&pfd, 1, timeout);
    if (rv == 0) {
        EST_LOG_ERR("Socket poll timeout.  No data received from server.");
        return -1;
    } else if ( rv == -1) {
        EST_LOG_ERR("Socket read failure. errno = %d", errno);
        return -1;
    } else {
        return (SSL_read(ssl, buf, buf_max));
    }
}
开发者ID:StephenWall,项目名称:libest,代码行数:30,代码来源:est_client_http.c

示例3: lws_ssl_close

LWS_VISIBLE int
lws_ssl_close(struct lws *wsi)
{
	lws_sockfd_type n;

	if (!wsi->ssl)
		return 0; /* not handled */

#if defined (LWS_HAVE_SSL_SET_INFO_CALLBACK)
	/* kill ssl callbacks, becausse we will remove the fd from the
	 * table linking it to the wsi
	 */
	if (wsi->vhost->ssl_info_event_mask)
		SSL_set_info_callback(wsi->ssl, NULL);
#endif

	n = SSL_get_fd(wsi->ssl);
	if (!wsi->socket_is_permanently_unusable)
		SSL_shutdown(wsi->ssl);
	compatible_close(n);
	SSL_free(wsi->ssl);
	wsi->ssl = NULL;

	if (wsi->context->simultaneous_ssl_restriction &&
	    wsi->context->simultaneous_ssl-- ==
			    wsi->context->simultaneous_ssl_restriction)
		/* we made space and can do an accept */
		lws_gate_accepts(wsi->context, 1);
#if defined(LWS_WITH_STATS)
	wsi->context->updated = 1;
#endif

	return 1; /* handled */
}
开发者ID:kubecz3k,项目名称:godot,代码行数:34,代码来源:ssl.c

示例4: Servlet

void Servlet(SSL* ssl) /* Serve the connection -- threadable */
{   char buf[1024];
    char reply[1024];
    int sd, bytes;
    const char* HTMLecho="<html><body><pre>%s</pre></body></html>\n\n";
 
    if ( SSL_accept(ssl) == FAIL )     /* do SSL-protocol accept */
        ERR_print_errors_fp(stderr);
    else
    {
        ShowCerts(ssl);        /* get any certificates */
        bytes = SSL_read(ssl, buf, sizeof(buf)); /* get request */
        if ( bytes > 0 )
        {
            buf[bytes] = 0;
            printf("Client msg: \"%s\"\n", buf);
            sprintf(reply, HTMLecho, buf);   /* construct reply */
            SSL_write(ssl, reply, strlen(reply)); /* send reply */
        }
        else
            ERR_print_errors_fp(stderr);
    }
    sd = SSL_get_fd(ssl);       /* get socket connection */
    SSL_free(ssl);         /* release SSL state */
    close(sd);          /* close connection */
}
开发者ID:TheDarkmaster1,项目名称:Kope,代码行数:26,代码来源:SSL-Server.cpp

示例5: lws_ssl_close

LWS_VISIBLE int
lws_ssl_close(struct lws *wsi)
{
	int n;

	if (!wsi->ssl)
		return 0; /* not handled */

#if defined(LWS_USE_POLARSSL)
	ssl_close_notify(wsi->ssl);
	(void)n; /* we need to close the fd? */
	ssl_free(wsi->ssl);
#else
#if defined(LWS_USE_MBEDTLS)
#else
	n = SSL_get_fd(wsi->ssl);
	SSL_shutdown(wsi->ssl);
	compatible_close(n);
	SSL_free(wsi->ssl);
#endif
#endif
	wsi->ssl = NULL;

	return 1; /* handled */
}
开发者ID:hhool,项目名称:libwebsockets,代码行数:25,代码来源:ssl.c

示例6: sslWait

// Retrying versions of the SSL I/O operations, using
// non-blocking sockets and select().
int sslWait(SSL *ssl, int ret, const char *op)
{
  int err = SSL_get_error(ssl, ret);
  bool doread;
  switch (err) {
  case SSL_ERROR_WANT_READ:
    if (debuglevel > 4) fprintf(stderr, "%s wants read\n", op);
    doread = true;
    break;
  case SSL_ERROR_WANT_WRITE:
  case SSL_ERROR_WANT_CONNECT:
    if (debuglevel > 4) fprintf(stderr, "%s wants write\n", op);
    doread = false;
    break;
  default:
    return ret;
  }
  int fd = SSL_get_fd(ssl);
  fd_set fds;
  FD_ZERO(&fds); FD_SET(fd, &fds);
  if (doread) {
    ret = select(fd+1,&fds,NULL,NULL,NULL);
  } else {
    ret = select(fd+1,NULL,&fds,NULL,NULL);
  }
  assert(ret == 1);
  assert(FD_ISSET(fd, &fds));
  return SSL_OK;
}
开发者ID:matthewarcus,项目名称:ssl-demo,代码行数:31,代码来源:ssl_lib.cpp

示例7: Servlet

void Servlet(int client, SSL* ssl)/* Serve the connection -- threadable */
{
  char buf[16384];
  int sd, bytes;

  if ( SSL_accept(ssl) == -1 ) {
    ERR_print_errors_fp(stderr);
  } else {
    // Send a little data to test reads
    bytes = SSL_write(ssl, buf, 1);
    bytes = SSL_write(ssl, buf, 1);
    bytes = SSL_write(ssl, buf, 1);
    bytes = SSL_write(ssl, buf, 1);

    do {

      bytes = SSL_read(ssl, buf, sizeof(buf));/* get request */
      if ( bytes > 0 )
        {

        } else if (bytes == 0) {
        printf("Bytes recv: %i\n", bytes_recv);
      }
      else {
        printf("ERROR\n");
        ERR_print_errors_fp(stderr);
        break;
      }
      bytes_recv += bytes;
    } while (bytes > 0 );
  }
  sd = SSL_get_fd(ssl);/* get socket connection */
  SSL_free(ssl);/* release SSL state */
  close(sd);/* close connection */
}
开发者ID:fridex,项目名称:ktls-af_alg,代码行数:35,代码来源:tls.c

示例8: ssl_close

static int ssl_close(void *cookie)
{
	int cookie_fd = SSL_get_fd(cookie);
	int ret;

	if (cookie_fd > -1) {
		/*
		 * According to the TLS standard, it is acceptable for an application to only send its shutdown
		 * alert and then close the underlying connection without waiting for the peer's response (this
		 * way resources can be saved, as the process can already terminate or serve another connection).
		 */
		if ((ret = SSL_shutdown(cookie)) < 0) {
			ast_log(LOG_ERROR, "SSL_shutdown() failed: %d\n", SSL_get_error(cookie, ret));
		}

		if (!((SSL*)cookie)->server) {
			/* For client threads, ensure that the error stack is cleared */
			ERR_remove_state(0);
		}

		SSL_free(cookie);
		/* adding shutdown(2) here has no added benefit */
		if (close(cookie_fd)) {
			ast_log(LOG_ERROR, "close() failed: %s\n", strerror(errno));
		}
	}
	return 0;
}
开发者ID:akodakim,项目名称:Asterisk-Call-Center,代码行数:28,代码来源:tcptls.c

示例9: io_before_poll

/* Set up an io for polling. */
int
io_before_poll(struct io *io, struct pollfd *pfd)
{
    /* If io is NULL, don't let poll do anything with this one. */
    if (io == NULL) {
        memset(pfd, 0, sizeof *pfd);
        pfd->fd = -1;
        return (1);
    }

    /* Check for errors or closure. */
    if (io->error != NULL)
        return (-1);
    if (IO_CLOSED(io))
        return (0);

    /* Fill in pollfd. */
    memset(pfd, 0, sizeof *pfd);
    if (io->ssl != NULL)
        pfd->fd = SSL_get_fd(io->ssl);
    else
        pfd->fd = io->fd;
    if (io->rd != NULL)
        pfd->events |= POLLIN;
    if (io->wr != NULL && (BUFFER_USED(io->wr) != 0 ||
                           (io->flags & (IOF_NEEDFILL|IOF_NEEDPUSH|IOF_MUSTWR)) != 0))
        pfd->events |= POLLOUT;

    IO_DEBUG(io, "poll in: 0x%03x", pfd->events);

    return (1);
}
开发者ID:mbeck-,项目名称:fdm,代码行数:33,代码来源:io.c

示例10: BST_IP_SslClose

BST_IP_ERR_T BST_IP_SslClose( BST_FD_T fd, BST_ARG_T Arg )
{
    SSL                                *pstSsl;
    SSL_CTX                            *pstCtx;
    BST_FD_T                            lSocketFd;

    if ( BST_NULL_PTR == fd.pFd )
    {
        BST_RLS_LOG("BST_IP_SslClose fd.pFd is NULL");
        return BST_IP_ERR_ARG;
    }
    if ( BST_NULL_PTR == Arg )
    {
        BST_RLS_LOG("BST_IP_SslClose Arg is NULL");
        return BST_IP_ERR_ARG;
    }
    pstSsl                              = (SSL *)fd.pFd;
    pstCtx                              = (SSL_CTX *)Arg;
    /*获取协议栈中socket的fd*/
    lSocketFd.lFd                       = SSL_get_fd( pstSsl );
    SSL_shutdown( pstSsl );
    if ( BST_IP_ERR_OK !=BST_IP_BsdClose( lSocketFd, BST_NULL_PTR ) )
    {
        BST_RLS_LOG( "BST_IP_SslClose BST_IP_BsdClose is not OK" );
        return BST_IP_ERR_MEM;
    }
    SSL_set_session( pstSsl, BST_NULL_PTR );
    SSL_free(pstSsl);
    SSL_CTX_free(pstCtx);

    return BST_IP_ERR_OK;
}
开发者ID:magnusjjj,项目名称:android_kernel_huawei_rle,代码行数:32,代码来源:BST_IP_LwipApi.cpp

示例11: BST_IP_SslConnect

BST_IP_ERR_T BST_IP_SslConnect( BST_FD_T fd, BST_ARG_T Arg, BST_IP_SOCKET_ADD_T *pAdd )
{
    SSL                    *pstSsl;
    BST_INT32               ret;
    BST_FD_T                lSocketFd;

    pstSsl                  = (SSL *)fd.pFd;
    lSocketFd.lFd           = SSL_get_fd(pstSsl);

    if (BST_IP_ERR_OK != BST_IP_BsdConnect(lSocketFd, Arg, pAdd) )
    {
        BST_RLS_LOG( "BST_IP_SslConnect BST_IP_BsdConnect error" );
        return BST_IP_ERR_MEM;
    }

    ret                     = SSL_connect( pstSsl );

    /* 返回值等于1表示connect成功 */
    if ( 1 == ret )
    {
        return BST_IP_ERR_OK;
    }
    ret                     = SSL_get_error( pstSsl, ret );

    BST_RLS_LOG1( "BST_IP_SslConnect Err No. is %d", ret );
    return  BST_IP_ERR_VAL;
}
开发者ID:magnusjjj,项目名称:android_kernel_huawei_rle,代码行数:27,代码来源:BST_IP_LwipApi.cpp

示例12: input_listen_tls_cleanup

/**
 * \brief Free TLS related things when TLS connection fails from some reason
 *
 * \param[in] config  plugin configuration structure
 * \param[in] maid  structure containing all pointers to free
 * \return  nothing
 */
void input_listen_tls_cleanup(void *config, struct cleanup *maid)
{
	struct plugin_conf *conf;
	int fd;
	int ret;
	
	conf = (struct plugin_conf *) config;

	/* TLS enabled? */
	if (conf->tls) {
		if (maid->address != NULL) {
			free(maid->address);
		}

		if (maid->ssl != NULL) {
			fd = SSL_get_fd(maid->ssl);
			if (fd >=0) {
				/* TLS shutdown */
				ret = SSL_shutdown(maid->ssl);
				if (ret == -1) {
					MSG_WARNING(msg_module, "Error during TLS connection teardown");
				}
			}
			SSL_free(maid->ssl);
		}

		if (maid->peer_cert != NULL) {
			X509_free(maid->peer_cert);
		}
	}
}
开发者ID:VisBlank,项目名称:ipfixcol,代码行数:38,代码来源:tcp_input.c

示例13: process

static void process(SSL* ssl)
{
	char buf[1024];
	int sd, bytes;

	strcpy(buf, "Hello World\n");

	if (SSL_connect(ssl) != 1) {
		ERR_print_errors_fp(stderr);
		goto out;
	}

	show_certificates(ssl);
	while (1) {
		bytes = SSL_write(ssl, buf, sizeof(buf));
		if (bytes > 0) {
			printf("received from client: \"%s\"\n", buf);
			SSL_write(ssl, buf, bytes);
		} else {
			ERR_print_errors_fp(stderr);
			break;
		}
		if (SSL_get_shutdown(ssl) == SSL_RECEIVED_SHUTDOWN) {
			SSL_shutdown(ssl);
			break;
		}
	}

out:
	sd = SSL_get_fd(ssl);
	SSL_free(ssl);
	close(sd);
}
开发者ID:kazu-yamamoto,项目名称:hs-tls,代码行数:33,代码来源:openssl-client.c

示例14: lws_ssl_info_callback

void
lws_ssl_info_callback(const SSL *ssl, int where, int ret)
{
	struct lws *wsi;
	struct lws_context *context;
	struct lws_ssl_info si;

	context = (struct lws_context *)SSL_CTX_get_ex_data(
					SSL_get_SSL_CTX(ssl),
					openssl_SSL_CTX_private_data_index);
	if (!context)
		return;
	wsi = wsi_from_fd(context, SSL_get_fd(ssl));
	if (!wsi)
		return;

	if (!(where & wsi->vhost->ssl_info_event_mask))
		return;

	si.where = where;
	si.ret = ret;

	if (user_callback_handle_rxflow(wsi->protocol->callback,
						   wsi, LWS_CALLBACK_SSL_INFO,
						   wsi->user_space, &si, 0))
		lws_set_timeout(wsi, PENDING_TIMEOUT_KILLED_BY_SSL_INFO, -1);
}
开发者ID:kubecz3k,项目名称:godot,代码行数:27,代码来源:ssl.c

示例15: est_ssl_read

/*
 * Take care of the blocking IO aspect of ssl_read.  Make sure there's
 * something waiting to be read from the socket before calling ssl_read.
 */
static int est_ssl_read (SSL *ssl, unsigned char *buf, int buf_max,
                         int sock_read_timeout) 
{
    struct timeval timeout;
    fd_set set;
    int read_fd;
    int rv;
    
    /*
     * load up the timeval struct to be passed to the select
     */
    timeout.tv_sec = sock_read_timeout;
    timeout.tv_usec = 0;

    read_fd = SSL_get_fd(ssl);
    
    FD_ZERO(&set);
    FD_SET(read_fd, &set);
    rv = select(read_fd + 1, &set, NULL, NULL, &timeout);
    if (rv == 0) {
        EST_LOG_ERR("Socket read timeout.  No data received from server.");
        return -1;
    }

    return (SSL_read(ssl, buf, buf_max));    
}
开发者ID:DDvO,项目名称:libest,代码行数:30,代码来源:est_client_http.c


注:本文中的SSL_get_fd函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。