static char cbuf[200],sbuf[200];
int doit(io_channel chan, SSL_CTX *s_ctx ){    int status, length, link_state;     struct rpc_msg msg;	static char cbuf[200],sbuf[200];	SSL *s_ssl=NULL;	BIO *c_to_s=NULL;	BIO *s_to_c=NULL;	BIO *c_bio=NULL;	BIO *s_bio=NULL;	int i;	int done=0;	s_ssl=SSL_new(s_ctx);	if (s_ssl == NULL) goto err;	c_to_s=BIO_new(BIO_s_rtcp());	s_to_c=BIO_new(BIO_s_rtcp());	if ((s_to_c == NULL) || (c_to_s == NULL)) goto err;/* original, DRM 24-SEP-1997	BIO_set_fd ( c_to_s, "", chan );	BIO_set_fd ( s_to_c, "", chan );*/	BIO_set_fd ( c_to_s, 0, chan );	BIO_set_fd ( s_to_c, 0, chan );	c_bio=BIO_new(BIO_f_ssl());	s_bio=BIO_new(BIO_f_ssl());	if ((c_bio == NULL) || (s_bio == NULL)) goto err;	SSL_set_accept_state(s_ssl);	SSL_set_bio(s_ssl,c_to_s,s_to_c);	BIO_set_ssl(s_bio,s_ssl,BIO_CLOSE);	/* We can always do writes */	printf("Begin doit main loop\n");	/*	 * Link states: 0-idle, 1-read pending, 2-write pending, 3-closed.	 */	for (link_state = 0; link_state < 3; ) {	    /*	     * Wait for remote end to request data action on A channel.	     */	    while ( link_state == 0 ) {		status = get ( chan, (char *) &msg, sizeof(msg), &length );		if ( (status&1) == 0 ) {		    printf("Error in main loop get: %d\n", status );		    link_state = 3;		    break;		}	   	if ( length < RPC_HDR_SIZE ) {		    printf("Error in main loop get size: %d\n", length );		    break;		    link_state = 3;		}	   	if ( msg.channel != 'A' ) {		    printf("Error in main loop, unexpected channel: %c\n", 			msg.channel );		    break;		    link_state = 3;		}		if ( msg.function == 'G' ) {		    link_state = 1;		} else if ( msg.function == 'P' ) {		    link_state = 2;	/* write pending */		} else if ( msg.function == 'X' ) {		    link_state = 3;		} else {		    link_state = 3;		}	    }	    if ( link_state == 1 ) {		i = BIO_read ( s_bio, msg.data, msg.length );		if ( i < 0 ) link_state = 3;		else {		    msg.channel = 'A';		    msg.function = 'C';		/* confirm */		    msg.length = i;		    status = put ( chan, (char *) &msg, i+RPC_HDR_SIZE );		    if ( (status&1) == 0 ) break;		    link_state = 0;		}	    } else if ( link_state == 2 ) {		i = BIO_write ( s_bio, msg.data, msg.length );		if ( i < 0 ) link_state = 3;		else {		    msg.channel = 'A';		    msg.function = 'C';		/* confirm */		    msg.length = 0;		    status = put ( chan, (char *) &msg, RPC_HDR_SIZE );		    if ( (status&1) == 0 ) break;		    link_state = 0;		}	    }	}	fprintf(stdout,"DONE\n");err:	/* We have to set the BIO's to NULL otherwise they will be	 * free()ed twice.  Once when th s_ssl is SSL_free()ed and	 * again when c_ssl is SSL_free()ed.	 * This is a hack required because s_ssl and c_ssl are sharing the same	 * BIO structure and SSL_set_bio() and SSL_free() automatically	 * BIO_free non NULL entries.	 * You should not normally do this or be required to do this */	s_ssl->rbio=NULL;	s_ssl->wbio=NULL;	if (c_to_s != NULL) BIO_free(c_to_s);	if (s_to_c != NULL) BIO_free(s_to_c);	if (c_bio != NULL) BIO_free(c_bio);	if (s_bio != NULL) BIO_free(s_bio);	return(0);}